summaryrefslogtreecommitdiff
path: root/qpid/python
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2008-05-23 21:40:03 +0000
committerRafael H. Schloming <rhs@apache.org>2008-05-23 21:40:03 +0000
commit99daabac209e7e0d7e624f37e76a33b9e15f71f9 (patch)
tree66754dd617f1b585a65712b44de71054f6ce9a1a /qpid/python
parentcd916eb65ffcd78bf87869980872824cd39be515 (diff)
downloadqpid-python-99daabac209e7e0d7e624f37e76a33b9e15f71f9.tar.gz
QPID-947: added codec and tests for array and list types
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@659671 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/qpid/codec010.py58
-rw-r--r--qpid/python/qpid/spec010.py1
-rw-r--r--qpid/python/tests/codec010.py27
3 files changed, 75 insertions, 11 deletions
diff --git a/qpid/python/qpid/codec010.py b/qpid/python/qpid/codec010.py
index 3d67d42d43..dac023e2bd 100644
--- a/qpid/python/qpid/codec010.py
+++ b/qpid/python/qpid/codec010.py
@@ -160,17 +160,20 @@ class Codec(Packer):
def write_map(self, m):
sc = StringCodec(self.spec)
- sc.write_uint32(len(m))
- 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)
+ if m is not None:
+ sc.write_uint32(len(m))
+ 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)
self.write_vbin32(sc.encoded)
def read_map(self):
sc = StringCodec(self.spec, self.read_vbin32())
+ if not sc.encoded:
+ return None
count = sc.read_uint32()
result = {}
while sc.encoded:
@@ -182,15 +185,48 @@ class Codec(Packer):
return result
def write_array(self, a):
- pass
+ sc = StringCodec(self.spec)
+ if a is not None:
+ if len(a) > 0:
+ type = self.spec.encoding(a[0].__class__)
+ else:
+ type = self.spec.encoding(None.__class__)
+ sc.write_uint8(type.code)
+ sc.write_uint32(len(a))
+ for o in a:
+ type.encode(sc, o)
+ self.write_vbin32(sc.encoded)
def read_array(self):
sc = StringCodec(self.spec, self.read_vbin32())
+ if not sc.encoded:
+ return None
type = self.spec.types[sc.read_uint8()]
count = sc.read_uint32()
result = []
- while count:
+ while count > 0:
+ result.append(type.decode(sc))
+ count -= 1
+ return result
+
+ def write_list(self, l):
+ sc = StringCodec(self.spec)
+ if l is not None:
+ sc.write_uint32(len(l))
+ for o in l:
+ type = self.spec.encoding(o.__class__)
+ sc.write_uint8(type.code)
+ type.encode(sc, o)
+ self.write_vbin32(sc.encoded)
+ def read_list(self):
+ sc = StringCodec(self.spec, self.read_vbin32())
+ if not sc.encoded:
+ return None
+ count = sc.read_uint32()
+ result = []
+ while count > 0:
+ type = self.spec.types[sc.read_uint8()]
result.append(type.decode(sc))
- count = count - 1
+ count -= 1
return result
def read_struct32(self):
diff --git a/qpid/python/qpid/spec010.py b/qpid/python/qpid/spec010.py
index 8c9b9068ac..23966e6176 100644
--- a/qpid/python/qpid/spec010.py
+++ b/qpid/python/qpid/spec010.py
@@ -473,6 +473,7 @@ class Spec(Node):
basestring: "vbin16",
int: "int64",
long: "int64",
+ float: "float",
None.__class__: "void",
list: "list",
tuple: "list",
diff --git a/qpid/python/tests/codec010.py b/qpid/python/tests/codec010.py
index bd3f875ac4..c849c1b0c0 100644
--- a/qpid/python/tests/codec010.py
+++ b/qpid/python/tests/codec010.py
@@ -55,3 +55,30 @@ class CodecTest(TestCase):
"long": 2**32,
"none": None,
"map": {"string": "nested map"}})
+
+ def testMapEmpty(self):
+ self.check("map", {})
+
+ def testMapNone(self):
+ self.check("map", None)
+
+ def testList(self):
+ self.check("list", [1, "two", 3.0, -4])
+
+ def testListEmpty(self):
+ self.check("list", [])
+
+ def testListNone(self):
+ self.check("list", None)
+
+ def testArrayInt(self):
+ self.check("array", [1, 2, 3, 4])
+
+ def testArrayString(self):
+ self.check("array", ["one", "two", "three", "four"])
+
+ def testArrayEmpty(self):
+ self.check("array", [])
+
+ def testArrayNone(self):
+ self.check("array", None)