Commit 011d940d authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

WiP: temporary fix in C lib, incompatible with other libs

parent 52e78cef
...@@ -157,6 +157,17 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind) ...@@ -157,6 +157,17 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
result = d->reader->error; result = d->reader->error;
goto out; 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); signature.name = labcomm2014_read_string(d->reader);
if (d->reader->error < 0) { if (d->reader->error < 0) {
result = d->reader->error; result = d->reader->error;
......
...@@ -36,6 +36,25 @@ struct encoder { ...@@ -36,6 +36,25 @@ struct encoder {
LABCOMM_SIGNATURE_ARRAY_DEF(typedefs, int); 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( static int do_sample_register(
struct labcomm2014_encoder *e, struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature, const struct labcomm2014_signature *signature,
...@@ -58,12 +77,12 @@ static int do_sample_register( ...@@ -58,12 +77,12 @@ static int do_sample_register(
if (err != 0) { result = err; goto out; } if (err != 0) { result = err; goto out; }
labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_DEF); labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_DEF);
length = (labcomm2014_size_packed32(index) + length = (labcomm2014_size_packed32(index) +
labcomm2014_size_string(signature->name) + TODO_sizeof_intentions(signature) +
labcomm2014_size_packed32(signature->size) + labcomm2014_size_packed32(signature->size) +
signature->size); signature->size);
labcomm2014_write_packed32(e->writer, length); labcomm2014_write_packed32(e->writer, length);
labcomm2014_write_packed32(e->writer, index); 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); labcomm2014_write_packed32(e->writer, signature->size);
for (i = 0 ; i < signature->size ; i++) { for (i = 0 ; i < signature->size ; i++) {
if (e->writer->pos >= e->writer->count) { if (e->writer->pos >= e->writer->count) {
...@@ -138,12 +157,12 @@ static int do_ref_register( ...@@ -138,12 +157,12 @@ static int do_ref_register(
if (err != 0) { result = err; goto out; } if (err != 0) { result = err; goto out; }
labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_REF); labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_REF);
length = (labcomm2014_size_packed32(index) + length = (labcomm2014_size_packed32(index) +
labcomm2014_size_string(signature->name) + TODO_sizeof_intentions(signature) +
labcomm2014_size_packed32(signature->size) + labcomm2014_size_packed32(signature->size) +
signature->size); signature->size);
labcomm2014_write_packed32(e->writer, length); labcomm2014_write_packed32(e->writer, length);
labcomm2014_write_packed32(e->writer, index); 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); labcomm2014_write_packed32(e->writer, signature->size);
for (i = 0 ; i < signature->size ; i++) { for (i = 0 ; i < signature->size ; i++) {
if (e->writer->pos >= e->writer->count) { if (e->writer->pos >= e->writer->count) {
......
...@@ -213,7 +213,7 @@ int main(void) ...@@ -213,7 +213,7 @@ int main(void)
/* Register twice to make sure that only one registration gets encoded */ /* 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);
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, 0x08, VARIABLE(1), 0x03, 'v', '_', 't', 0x02, 0x11, 0x00,
0x04, 0x05, VARIABLE(2), 0x01, 'V', 0x01, VARIABLE(1), 0x04, 0x05, VARIABLE(2), 0x01, 'V', 0x01, VARIABLE(1),
0x05, 0x02, VARIABLE(0), VARIABLE(2) }); 0x05, 0x02, VARIABLE(0), VARIABLE(2) });
...@@ -222,14 +222,14 @@ int main(void) ...@@ -222,14 +222,14 @@ int main(void)
/* Register twice to make sure that only one registration gets encoded */ /* 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);
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 }); 0x05, 0x02, VARIABLE(3), LABCOMM_BIND_SELF });
labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
/* Register twice to make sure that only one registration gets encoded */ /* 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);
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 }); 0x05, 0x02, VARIABLE(4), LABCOMM_BIND_SELF });
labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
...@@ -238,7 +238,7 @@ int main(void) ...@@ -238,7 +238,7 @@ int main(void)
labcomm2014_signature_generated_encoding_V); labcomm2014_signature_generated_encoding_V);
labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_encoder_sample_ref_register(encoder,
labcomm2014_signature_generated_encoding_V); 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); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
/* Register twice to make sure that only one registration gets encoded */ /* Register twice to make sure that only one registration gets encoded */
...@@ -246,7 +246,7 @@ int main(void) ...@@ -246,7 +246,7 @@ int main(void)
labcomm2014_signature_generated_encoding_B); labcomm2014_signature_generated_encoding_B);
labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_encoder_sample_ref_register(encoder,
labcomm2014_signature_generated_encoding_B); 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); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
/* Register twice to make sure that only one registration gets encoded */ /* Register twice to make sure that only one registration gets encoded */
...@@ -254,7 +254,7 @@ int main(void) ...@@ -254,7 +254,7 @@ int main(void)
labcomm2014_signature_generated_encoding_R); labcomm2014_signature_generated_encoding_R);
labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_encoder_sample_ref_register(encoder,
labcomm2014_signature_generated_encoding_R); 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); labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
// was: labcomm2014_encode_generated_encoding_V(encoder, &V); // was: labcomm2014_encode_generated_encoding_V(encoder, &V);
......
Supports Markdown
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