From 02d82d5d3d70ac0a3445936f19eb070c4d67b4b1 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Fri, 24 Oct 2014 19:17:15 +0200
Subject: [PATCH] skeleton decoder

---
 lib/c/labcomm_decoder.c | 38 ++++++++++++++++++++++----------------
 lib/c/labcomm_encoder.c |  2 +-
 lib/c/labcomm_private.h | 10 ++++++----
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c
index 4d08740..cb694e9 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 d7617a4..17d7eb6 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 1ba35c7..f20ba0e 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 */
 
 
 /*
-- 
GitLab