qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r659671 - in /incubator/qpid/trunk/qpid/python: qpid/codec010.py qpid/spec010.py tests/codec010.py
Date Fri, 23 May 2008 21:40:04 GMT
Author: rhs
Date: Fri May 23 14:40:03 2008
New Revision: 659671

URL: http://svn.apache.org/viewvc?rev=659671&view=rev
Log:
QPID-947: added codec and tests for array and list types

Modified:
    incubator/qpid/trunk/qpid/python/qpid/codec010.py
    incubator/qpid/trunk/qpid/python/qpid/spec010.py
    incubator/qpid/trunk/qpid/python/tests/codec010.py

Modified: incubator/qpid/trunk/qpid/python/qpid/codec010.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/codec010.py?rev=659671&r1=659670&r2=659671&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec010.py Fri May 23 14:40:03 2008
@@ -160,17 +160,20 @@
 
   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 @@
     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):

Modified: incubator/qpid/trunk/qpid/python/qpid/spec010.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/spec010.py?rev=659671&r1=659670&r2=659671&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/spec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/spec010.py Fri May 23 14:40:03 2008
@@ -473,6 +473,7 @@
     basestring: "vbin16",
     int: "int64",
     long: "int64",
+    float: "float",
     None.__class__: "void",
     list: "list",
     tuple: "list",

Modified: incubator/qpid/trunk/qpid/python/tests/codec010.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/tests/codec010.py?rev=659671&r1=659670&r2=659671&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/tests/codec010.py (original)
+++ incubator/qpid/trunk/qpid/python/tests/codec010.py Fri May 23 14:40:03 2008
@@ -55,3 +55,30 @@
                        "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)



Mime
View raw message