Commit 02d82d5d authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

skeleton decoder

parent 91219636
......@@ -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) {
......
......@@ -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) +
......
......@@ -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 */
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment