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

added handler callbacks to python decoder

parent e2275d7a
......@@ -693,7 +693,7 @@ class struct(type_decl):
result = "labcomm.struct(["
for (intentions, decl) in self.field:
try:
name = intentions['']
name = dict(intentions)['']
except:
name = '(no name)'
result += "%s\n ('%s', %s)" % (delim, name, decl)
......@@ -916,6 +916,10 @@ class Decoder(Codec):
super(Decoder, self).__init__()
self.reader = reader
self.version = version
self.handlers = {}
def register_handler(self, sig, handler):
self.handlers[str(sig)] = handler
def unpack(self, format):
size = packer.calcsize(format)
......@@ -945,6 +949,17 @@ class Decoder(Codec):
else:
raise Exception("Invalid type index %d" % index)
def runOne(self):
data,decl = self.decode()
if decl:
if data:
if str(decl) in self.handlers:
handler = self.handlers[str(decl)]
handler(data)
else:
print ("No handler for %s" % decl.name )
def decode(self):
while True:
index = self.decode_type_number()
......
Markdown is supported
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