summaryrefslogtreecommitdiff
path: root/python/qpid/codec010.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/qpid/codec010.py')
-rw-r--r--python/qpid/codec010.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/python/qpid/codec010.py b/python/qpid/codec010.py
index f6539ffcee..27df9db974 100644
--- a/python/qpid/codec010.py
+++ b/python/qpid/codec010.py
@@ -20,11 +20,18 @@
from packer import Packer
from datatypes import RangedSet
+class CodecException(Exception): pass
+
class Codec(Packer):
def __init__(self, spec):
self.spec = spec
+ def write_void(self, v):
+ assert v == None
+ def read_void(self):
+ return None
+
def write_bit(self, b):
if not b: raise ValueError(b)
def read_bit(self):
@@ -148,10 +155,26 @@ class Codec(Packer):
self.write(b)
def write_map(self, m):
- self.write_uint32(0) #hack
+ sc = StringCodec(self.spec)
+ for k, v in m.items():
+ type = self.spec.encoding(v.__class__)
+ if type == None:
+ raise CodecException("no encoding for %s" % v.__class__)
+ sc.write_str8(k)
+ sc.write_uint8(type.code)
+ type.encode(sc, v)
+ # XXX: need to put in count when CPP supports it
+ self.write_vbin32(sc.encoded)
def read_map(self):
- size = self.read_uint32() #hack
- self.read(size) #hack
+ sc = StringCodec(self.spec, self.read_vbin32())
+ result = {}
+ while sc.encoded:
+ k = sc.read_str8()
+ code = sc.read_uint8()
+ type = self.spec.types[code]
+ v = type.decode(sc)
+ result[k] = v
+ return result
def write_array(self, a):
pass