Author: rhs
Date: Mon Apr 14 09:33:40 2008
New Revision: 647887

URL: http://svn.apache.org/viewvc?rev=647887&view=rev
Log:
fixed encode/decode of structs in command/control arguments to include the type 
code when specified

Modified:
    incubator/qpid/trunk/qpid/python/qpid/codec010.py
    incubator/qpid/trunk/qpid/python/qpid/spec010.py
    incubator/qpid/trunk/qpid/python/tests/spec010.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=647887&r1=647886&r2=647887&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec010.py Mon Apr 14 09:33:40 2008
@@ -195,21 +195,21 @@
 
   def read_control(self):
     cntrl = self.spec.controls[self.read_uint16()]
-    return cntrl.decode(self)
+    return Struct(cntrl, **cntrl.decode_fields(self))
   def write_control(self, ctrl):
     type = ctrl._type
     self.write_uint16(type.code)
-    type.encode(self, ctrl)
+    type.encode_fields(self, ctrl)
 
   def read_command(self):
     type = self.spec.commands[self.read_uint16()]
     hdr = self.spec["session.header"].decode(self)
-    cmd = type.decode(self)
+    cmd = Struct(type, **type.decode_fields(self))
     return hdr, cmd
   def write_command(self, hdr, cmd):
     self.write_uint16(cmd._type.code)
     hdr._type.encode(self, hdr)
-    cmd._type.encode(self, cmd)
+    cmd._type.encode_fields(self, cmd)
 
   def read_size(self, width):
     if width > 0:

Modified: incubator/qpid/trunk/qpid/python/qpid/spec010.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/spec010.py?rev=647887&r1=647886&r2=647887&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/spec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/spec010.py Mon Apr 14 09:33:40 2008
@@ -192,6 +192,9 @@
 
   def decode(self, codec):
     codec.read_size(self.size)
+    if self.code is not None:
+      code = codec.read_uint16()
+      assert self.code == code
     return datatypes.Struct(self, **self.decode_fields(codec))
 
   def decode_fields(self, codec):
@@ -211,6 +214,8 @@
 
   def encode(self, codec, value):
     sc = StringCodec(self.spec)
+    if self.code is not None:
+      sc.write_uint16(self.code)
     self.encode_fields(sc, value)
     codec.write_size(self.size, len(sc.encoded))
     codec.write(sc.encoded)

Modified: incubator/qpid/trunk/qpid/python/tests/spec010.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/tests/spec010.py?rev=647887&r1=647886&r2=647887&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/tests/spec010.py (original)
+++ incubator/qpid/trunk/qpid/python/tests/spec010.py Mon Apr 14 09:33:40 2008
@@ -26,7 +26,7 @@
 class SpecTest(TestCase):
 
   def setUp(self):
-    self.spec = load(testrunner.get_spec_file("amqp.0-10.xml"))
+    self.spec = load(testrunner.get_spec_file("amqp.0-10-qpid-errata.xml"))
 
   def testSessionHeader(self):
     hdr = self.spec["session.header"]
@@ -62,3 +62,11 @@
     dec = self.encdec(self.spec["message.subscribe"], cmd)
     assert cmd.exclusive == dec.exclusive
     assert cmd.destination == dec.destination
+
+  def testXid(self):
+    xid = self.spec["dtx.xid"]
+    sc = StringCodec(self.spec)
+    st = Struct(xid, format=0, global_id="gid", branch_id="bid")
+    xid.encode(sc, st)
+    assert sc.encoded == 
'\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid'
+    assert xid.decode(sc).__dict__ == st.__dict__


Reply via email to