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

started adding (hierarchical) type def functionality. for now: skip them

parent 408d150a
......@@ -267,7 +267,7 @@ out:
static int decoder_skip(struct labcomm_decoder *d, int len, int tag)
{
int i;
printf("skipping %d bytes\n", len);
printf("got tag 0x%x, skipping %d bytes\n", tag, len);
for(i = 0; i <len; i++){
labcomm_read_byte(d->reader);
if (d->reader->error < 0) {
......
......@@ -12,6 +12,8 @@ public class Constant {
*/
public static final int VERSION = 0x01;
public static final int SAMPLE_DEF = 0x02;
public static final int TYPE_DEF = 0x03;
public static final int TYPE_BINDING = 0x04;
public static final int PRAGMA = 0x3f;
public static final int FIRST_USER_INDEX = 0x40; /* ..0xffffffff */
......
......@@ -30,6 +30,21 @@ public class DecoderChannel implements Decoder {
registry.add(index, name, signature);
}
private void processTypeDef(int len) throws IOException {
System.out.println("Got TypeDef: skipping "+len+" bytes");
for(int i=0; i<len; i++) {
decodeByte();
}
}
private void processTypeBinding(int len) throws IOException {
System.out.println("Got TypeBinding: skipping "+len+" bytes");
for(int i=0; i<len; i++) {
decodeByte();
}
}
private void processPragma(int len) throws IOException {
// String pt = decodeString();
// System.out.println("Pragma["+pt+"]: skipping "+plen+" bytes");
......@@ -77,14 +92,14 @@ public class DecoderChannel implements Decoder {
case Constant.SAMPLE_DEF: {
processSampleDef();
} break;
case Constant.TYPE_DEF: {
processTypeDef(length);
} break;
case Constant.TYPE_BINDING: {
processTypeBinding(length);
} break;
case Constant.PRAGMA: {
processPragma(length);
// String pt = decodeString();
// int plen = length - pt.length()-1;
// System.out.println("Pragma["+pt+"]: skipping "+plen+" bytes");
// for(int i=0; i<plen; i++) {
// decodeByte();
// }
} break;
default: {
DecoderRegistry.Entry e = registry.get(tag);
......
......@@ -29,6 +29,37 @@
# | ...
# +----+--
#
# LabComm220141009 TYPE_DEF: (as SAMPLE_DEF, but signatures are hierarchical,
# i.e., may contain references to other types
#
# +----+----+----+----+
# | id = 0x03 (packed32)
# +----+----+----+----+
# | length (packed32)
# +----+----+----+----+
# | type number (packed32)
# +----+----+----+----+
# | type name (UTF8)
# | ...
# +----+----+----+----+
# | signature length (packed32)
# +----+----+----+----+
# | type signature
# | ...
# +----+--
#
# LabComm220141009 TYPE_BINDING
#
# +----+----+----+----+
# | id = 0x04 (packed32)
# +----+----+----+----+
# | length (packed32)
# +----+----+----+----+
# | sample number (packed32)
# +----+----+----+----+
# | type number (packed32)
# +----+----+----+----+
#
# LabComm20141009 User data:
#
# +----+----+----+----+
......@@ -125,6 +156,8 @@ DEFAULT_VERSION = "LabComm20141009"
# Allowed packet tags
i_VERSION = 0x01
i_SAMPLE_DEF = 0x02
i_TYPE_DEF = 0x03
i_TYPE_BINDING= 0x04
i_PRAGMA = 0x3f
i_USER = 0x40 # ..0xffffffff
......@@ -693,6 +726,10 @@ class Decoder(Codec):
raise Exception('Should not be used')
return result
def skip(self, length):
for _ in xrange(length):
self.decode_byte()
def decode(self):
while True:
index = self.decode_type_number()
......@@ -708,6 +745,12 @@ class Decoder(Codec):
if index == i_SAMPLE_DEF:
decl = self.index_to_decl[index].decode_decl(self)
value = None
elif index == i_TYPE_DEF:
print "Got type_def, skipping %d bytes" % length
self.skip(length)
elif index == i_TYPE_BINDING:
print "Got type_binding, skipping %d bytes" % length
self.skip(length)
else:
decl = self.index_to_decl[index]
value = decl.decode(self)
......
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