diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c index 4d08740065df45973546adff62da7749837010e1..cb694e9902a90cb03afa092006340f317ce4cee2 100644 --- a/lib/c/labcomm_decoder.c +++ b/lib/c/labcomm_decoder.c @@ -86,7 +86,7 @@ void labcomm_decoder_free(struct labcomm_decoder* d) labcomm_memory_free(memory, 0, d); } -static int decode_sample(struct labcomm_decoder *d, int kind) +static int decode_sample_def(struct labcomm_decoder *d, int kind) { int result; struct labcomm_signature signature, *local_signature; @@ -189,7 +189,24 @@ static void reader_alloc(struct labcomm_decoder *d) labcomm_reader_alloc(d->reader, d->reader->action_context); } } - +static int decode_version(struct labcomm_decoder *d, int remote_index) +{ + int result; + char *version = labcomm_read_string(d->reader); + if (d->reader->error < 0) { + result = d->reader->error; + goto out; + } + if (strcmp(version, CURRENT_VERSION) == 0) { + result = LABCOMM_VERSION; + d->version_ok = 1; + } else { + result = -ECONNRESET; + } + labcomm_memory_free(d->memory, 1, version); +out: + return result; +} int labcomm_decoder_decode_one(struct labcomm_decoder *d) { int result, remote_index, length; @@ -206,23 +223,12 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) goto out; } if (remote_index == LABCOMM_VERSION) { - char *version = labcomm_read_string(d->reader); - if (d->reader->error < 0) { - result = d->reader->error; - goto out; - } - if (strcmp(version, CURRENT_VERSION) == 0) { - result = LABCOMM_VERSION; - d->version_ok = 1; - } else { - result = -ECONNRESET; - } - labcomm_memory_free(d->memory, 1, version); + result = decode_version(d, remote_index); } else if (! d->version_ok) { fprintf(stderr, "No VERSION %d %d\n", remote_index, length); result = -ECONNRESET; - } else if (remote_index == LABCOMM_SAMPLE) { - result = decode_sample(d, remote_index); + } else if (remote_index == LABCOMM_SAMPLE_DEF) { + result = decode_sample_def(d, remote_index); } else if (remote_index == LABCOMM_PRAGMA && 0 /* d->pragma_handler*/) { /* d->prama_handler(...); */ } else if (remote_index < LABCOMM_USER) { diff --git a/lib/c/labcomm_encoder.c b/lib/c/labcomm_encoder.c index d7617a447a864fd39b36fe39988f260b22e59db5..17d7eb6231a0b6d01df5ed6b34434c5e057871b2 100644 --- a/lib/c/labcomm_encoder.c +++ b/lib/c/labcomm_encoder.c @@ -222,7 +222,7 @@ int labcomm_internal_encoder_register( index, signature, NULL); if (err == -EALREADY) { result = 0; goto out; } if (err != 0) { result = err; goto out; } - labcomm_write_packed32(e->writer, LABCOMM_SAMPLE); + labcomm_write_packed32(e->writer, LABCOMM_SAMPLE_DEF); length = (labcomm_size_packed32(index) + labcomm_size_string(signature->name) + labcomm_size_packed32(signature->size) + diff --git a/lib/c/labcomm_private.h b/lib/c/labcomm_private.h index 1ba35c7ab6eb6893d729e8dde043e28ff60e5748..f20ba0ee0f9e70a3bc037683870eb5aeac55b562 100644 --- a/lib/c/labcomm_private.h +++ b/lib/c/labcomm_private.h @@ -39,10 +39,12 @@ /* * Allowed packet tags */ -#define LABCOMM_VERSION 0x01 -#define LABCOMM_SAMPLE 0x02 -#define LABCOMM_PRAGMA 0x3f -#define LABCOMM_USER 0x40 /* ..0xffffffff */ +#define LABCOMM_VERSION 0x01 +#define LABCOMM_SAMPLE_DEF 0x02 +#define LABCOMM_TYPE_DEF 0x03 +#define LABCOMM_TYPE_BINDING 0x04 +#define LABCOMM_PRAGMA 0x3f +#define LABCOMM_USER 0x40 /* ..0xffffffff */ /*