From 1279cb03707e82944e1593c22e918bc11d776fe4 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Sat, 25 Oct 2014 21:33:33 +0200
Subject: [PATCH] c decoder still skips pragma, decoding is wip, see comment

---
 lib/c/Makefile                   | 1 +
 lib/c/labcomm_bytearray_reader.c | 6 ++++++
 lib/c/labcomm_decoder.c          | 6 ++++++
 3 files changed, 13 insertions(+)

diff --git a/lib/c/Makefile b/lib/c/Makefile
index e1ba1d7..a3a495b 100644
--- a/lib/c/Makefile
+++ b/lib/c/Makefile
@@ -27,6 +27,7 @@ OBJS=labcomm_memory.o \
      labcomm.o \
      labcomm_dynamic_buffer_writer.o \
      labcomm_fd_reader.o labcomm_fd_writer.o \
+     labcomm_bytearray_reader.o \
      labcomm_pthread_scheduler.o 
 
 #FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
diff --git a/lib/c/labcomm_bytearray_reader.c b/lib/c/labcomm_bytearray_reader.c
index 9752808..505391f 100644
--- a/lib/c/labcomm_bytearray_reader.c
+++ b/lib/c/labcomm_bytearray_reader.c
@@ -34,9 +34,15 @@ struct labcomm_bytearray_reader {
   int bytearray_size;
 };
 
+#if 0
+// XXX HERE BE DRAGONS: version removed?
 static int bytearray_alloc(struct labcomm_reader *r,
 		    struct labcomm_reader_action_context *action_context, 
 		    char *version)
+#else
+static int bytearray_alloc(struct labcomm_reader *r,
+		    struct labcomm_reader_action_context *action_context) 
+#endif
 {
   int result = 0;
   
diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c
index 90ce3c9..d5613be 100644
--- a/lib/c/labcomm_decoder.c
+++ b/lib/c/labcomm_decoder.c
@@ -233,6 +233,7 @@ out:
 static int decoder_skip(struct labcomm_decoder *d, int len)
 {
   int i;
+  printf("skipping %d bytes\n", len);
   for(i = 0; i <len; i++){
     labcomm_read_byte(d->reader);
     if (d->reader->error < 0) {
@@ -252,6 +253,7 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
   }
   int bytes = labcomm_size_string(pragma_type);
   int psize = len-bytes;
+  printf("got pragma: %s\n", pragma_type);
   if(0 /*d->pragma_handler*/) {
   //read the entire packet to a buffer and then run
   // decode on that through a bytearray_reader.
@@ -265,11 +267,15 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
          goto out;
        }
      }
+    printf("read %d bytes\n", psize);
+    //TODO: add wrapped decoders, and create pragma decoder that does not
+    //      expect a version packet
      struct labcomm_reader *pr = labcomm_bytearray_reader_new(
                                      d->reader->memory, pragma_data, psize);
      struct labcomm_decoder *pd = labcomm_decoder_new(
                                      pr, d->error, d->memory, d->scheduler);
     /* d->prama_handler(pd, ptype, plen); */
+     labcomm_decoder_run(pd);
 
      internal_labcomm_decoder_free(pd);
      result = 0;
-- 
GitLab