From dcaa8582a323d445fee5fdb46a25f2bcf3f89d58 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 14 Apr 2008 16:33:40 +0000 Subject: fixed encode/decode of structs in command/control arguments to include the type code when specified git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@647887 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/codec010.py | 8 ++++---- python/qpid/spec010.py | 5 +++++ python/tests/spec010.py | 10 +++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'python') diff --git a/python/qpid/codec010.py b/python/qpid/codec010.py index 0e4244fb75..f82a7a49dc 100644 --- a/python/qpid/codec010.py +++ b/python/qpid/codec010.py @@ -195,21 +195,21 @@ class Codec(Packer): 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: diff --git a/python/qpid/spec010.py b/python/qpid/spec010.py index 4eb03008d0..03f60edc4e 100644 --- a/python/qpid/spec010.py +++ b/python/qpid/spec010.py @@ -192,6 +192,9 @@ class Composite(Type, Coded): 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 @@ class Composite(Type, Coded): 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) diff --git a/python/tests/spec010.py b/python/tests/spec010.py index 4161dc060f..ff29bd8cea 100644 --- a/python/tests/spec010.py +++ b/python/tests/spec010.py @@ -26,7 +26,7 @@ from qpid.datatypes import Struct 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 @@ class SpecTest(TestCase): 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__ -- cgit v1.2.1