From 011d940d7a8151880aee7c22027a488ce0061b4a Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Thu, 21 May 2015 14:58:20 +0200 Subject: [PATCH] WiP: temporary fix in C lib, incompatible with other libs --- lib/c/2014/labcomm2014_decoder.c | 11 ++++++++ lib/c/2014/labcomm2014_encoder.c | 27 ++++++++++++++++--- .../test/test_labcomm_generated_encoding.c | 12 ++++----- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c index f822288..181c53b 100644 --- a/lib/c/2014/labcomm2014_decoder.c +++ b/lib/c/2014/labcomm2014_decoder.c @@ -157,6 +157,17 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind) result = d->reader->error; goto out; } + + int numInts = labcomm2014_read_byte(d->reader); + + if(numInts != 1) { + printf("WARNING! #intentions != 1, this will probably crash\n"); + } + //XXX temporary kludge for intentions + //assume only one intention: the name + + labcomm2014_read_packed32(d->reader); // assume the empty key (i.e., name) + signature.name = labcomm2014_read_string(d->reader); if (d->reader->error < 0) { result = d->reader->error; diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c index c49798d..3897915 100644 --- a/lib/c/2014/labcomm2014_encoder.c +++ b/lib/c/2014/labcomm2014_encoder.c @@ -36,6 +36,25 @@ struct encoder { LABCOMM_SIGNATURE_ARRAY_DEF(typedefs, int); }; +/* XXX: TEMPORARY PLACEHOLDERS FOR INTENTIONS */ + +static int TODO_sizeof_intentions(const struct labcomm2014_signature *signature) { + return labcomm2014_size_string(signature->name) + 2; +} + +static int TODO_encode_intentions( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) +{ + int result = -EINVAL; + + labcomm2014_write_packed32(e->writer, 1); // one intention: the name + labcomm2014_write_packed32(e->writer, 0); // key: the empty string + labcomm2014_write_string(e->writer, signature->name); + + result = e->writer->error; + return result; +} static int do_sample_register( struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature, @@ -58,12 +77,12 @@ static int do_sample_register( if (err != 0) { result = err; goto out; } labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_DEF); length = (labcomm2014_size_packed32(index) + - labcomm2014_size_string(signature->name) + + TODO_sizeof_intentions(signature) + labcomm2014_size_packed32(signature->size) + signature->size); labcomm2014_write_packed32(e->writer, length); labcomm2014_write_packed32(e->writer, index); - labcomm2014_write_string(e->writer, signature->name); + TODO_encode_intentions(e, signature); labcomm2014_write_packed32(e->writer, signature->size); for (i = 0 ; i < signature->size ; i++) { if (e->writer->pos >= e->writer->count) { @@ -138,12 +157,12 @@ static int do_ref_register( if (err != 0) { result = err; goto out; } labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_REF); length = (labcomm2014_size_packed32(index) + - labcomm2014_size_string(signature->name) + + TODO_sizeof_intentions(signature) + labcomm2014_size_packed32(signature->size) + signature->size); labcomm2014_write_packed32(e->writer, length); labcomm2014_write_packed32(e->writer, index); - labcomm2014_write_string(e->writer, signature->name); + TODO_encode_intentions(e, signature); labcomm2014_write_packed32(e->writer, signature->size); for (i = 0 ; i < signature->size ; i++) { if (e->writer->pos >= e->writer->count) { diff --git a/lib/c/2014/test/test_labcomm_generated_encoding.c b/lib/c/2014/test/test_labcomm_generated_encoding.c index 5936b0a..023bdf6 100644 --- a/lib/c/2014/test/test_labcomm_generated_encoding.c +++ b/lib/c/2014/test/test_labcomm_generated_encoding.c @@ -213,7 +213,7 @@ int main(void) /* Register twice to make sure that only one registration gets encoded */ labcomm2014_encoder_register_generated_encoding_V(encoder); labcomm2014_encoder_register_generated_encoding_V(encoder); - EXPECT({ 0x02, 0x07, VARIABLE(0), 0x01, 'V', 0x03, 0x00, 0x11, 0x00, + EXPECT({ 0x02, 0x08, VARIABLE(0), 0x01, 0x00, 0x01, 'V', 0x02, 0x11, 0x00, 0x04, 0x08, VARIABLE(1), 0x03, 'v', '_', 't', 0x02, 0x11, 0x00, 0x04, 0x05, VARIABLE(2), 0x01, 'V', 0x01, VARIABLE(1), 0x05, 0x02, VARIABLE(0), VARIABLE(2) }); @@ -222,14 +222,14 @@ int main(void) /* Register twice to make sure that only one registration gets encoded */ labcomm2014_encoder_register_generated_encoding_B(encoder); labcomm2014_encoder_register_generated_encoding_B(encoder); - EXPECT({ 0x02, 0x06, VARIABLE(3), 0x01, 'B', 0x02, 0x00, 0x21, + EXPECT({ 0x02, 0x07, VARIABLE(3),0x01, 0x00, 0x01, 'B', 0x01, 0x21, 0x05, 0x02, VARIABLE(3), LABCOMM_BIND_SELF }); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ labcomm2014_encoder_register_generated_encoding_R(encoder); labcomm2014_encoder_register_generated_encoding_R(encoder); - EXPECT({ 0x02, 0x09, VARIABLE(4), 0x01, 'R', 0x05, 0x00, 0x10, 0x01, 0x04, 0x28, + EXPECT({ 0x02, 0x0a, VARIABLE(4), 0x01, 0x00, 0x01, 'R', 0x04, 0x10, 0x01, 0x04, 0x28, 0x05, 0x02, VARIABLE(4), LABCOMM_BIND_SELF }); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); @@ -238,7 +238,7 @@ int main(void) labcomm2014_signature_generated_encoding_V); labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_signature_generated_encoding_V); - EXPECT({0x03, 0x07, VARIABLE(5), 0x01, 'V', 0x03, 0x00, 0x11, 0x00}); + EXPECT({0x03, 0x08, VARIABLE(5), 0x01, 0x00, 0x01, 'V', 0x02, 0x11, 0x00}); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ @@ -246,7 +246,7 @@ int main(void) labcomm2014_signature_generated_encoding_B); labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_signature_generated_encoding_B); - EXPECT({0x03, 0x06, VARIABLE(6), 0x01, 'B', 0x02, 0x00, 0x21}); + EXPECT({0x03, 0x07, VARIABLE(6), 0x01, 0x00, 0x01, 'B', 0x01, 0x21}); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ @@ -254,7 +254,7 @@ int main(void) labcomm2014_signature_generated_encoding_R); labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_signature_generated_encoding_R); - EXPECT({0x03, 0x09, VARIABLE(7), 0x01, 'R', 0x05, 0x00, 0x10, 0x01, 0x04, 0x28}); + EXPECT({0x03, 0x0a, VARIABLE(7), 0x01, 0x00, 0x01, 'R', 0x04, 0x10, 0x01, 0x04, 0x28}); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); // was: labcomm2014_encode_generated_encoding_V(encoder, &V); -- GitLab