diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2007-08-10 15:55:16 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2007-08-10 15:55:16 +0000 |
| commit | 01652ef4ec4d7a92bfdcf677c27fb28968398bc6 (patch) | |
| tree | 495a8d994def30a30512beaf4077643c41cff332 /python/qpid/codec.py | |
| parent | 6577b14632d81c15482cb0793e01166cdb28eaff (diff) | |
| download | qpid-python-01652ef4ec4d7a92bfdcf677c27fb28968398bc6.tar.gz | |
added support for unpacked structs and execution.result
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@564637 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/codec.py')
| -rw-r--r-- | python/qpid/codec.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/python/qpid/codec.py b/python/qpid/codec.py index a11486376d..3920f2c8d9 100644 --- a/python/qpid/codec.py +++ b/python/qpid/codec.py @@ -26,7 +26,7 @@ fields. The unit test for this module is located in tests/codec.py """ -import re +import re, qpid from cStringIO import StringIO from struct import * from reference import ReferenceId @@ -40,11 +40,12 @@ class Codec: class that handles encoding/decoding of AMQP primitives """ - def __init__(self, stream): + def __init__(self, stream, spec): """ initializing the stream/fields used """ self.stream = stream + self.spec = spec self.nwrote = 0 self.nread = 0 self.incoming_bits = [] @@ -163,7 +164,7 @@ class Codec: # short int's valid range is [0,65535] if (o < 0 or o > 65535): - raise ValueError('Valid range of short int is [0,65535]') + raise ValueError('Valid range of short int is [0,65535]: %s' % o) self.pack("!H", o) @@ -255,7 +256,7 @@ class Codec: encodes a table data structure in network byte order """ enc = StringIO() - codec = Codec(enc) + codec = Codec(enc, self.spec) if tbl: for key, value in tbl.items(): if len(key) > 128: @@ -356,3 +357,21 @@ class Codec: def decode_uuid(self): return self.decode_longstr() + + def encode_long_struct(self, s): + enc = StringIO() + codec = Codec(enc, self.spec) + type = s.type + codec.encode_short(type.type) + for f in type.fields: + codec.encode(f.type, getattr(s, f.name)) + codec.flush() + self.encode_longstr(enc.getvalue()) + + def decode_long_struct(self): + codec = Codec(StringIO(self.decode_longstr()), self.spec) + type = self.spec.structs[codec.decode_short()] + s = qpid.Struct(type) + for f in type.fields: + setattr(s, f.name, codec.decode(f.type)) + return s |
