diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-03-07 20:22:18 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-03-07 20:22:18 +0000 |
commit | 9348ffddf9dbeb1029a91f0804a5f3b1e22f8821 (patch) | |
tree | 0526d5636f51483eccb437f1035a9d9a9e1f2670 /python/qpid/codec010.py | |
parent | 039d4461a0c1bb44731bbee6df58c0ee0c1673cf (diff) | |
download | qpid-python-9348ffddf9dbeb1029a91f0804a5f3b1e22f8821.tar.gz |
added support for maps
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@634803 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/codec010.py')
-rw-r--r-- | python/qpid/codec010.py | 29 |
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 |