diff options
author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-10-28 21:33:52 +0000 |
---|---|---|
committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-10-28 21:33:52 +0000 |
commit | e5f27778179696429e4212611c6e5454e2a63e99 (patch) | |
tree | 58597637361766aeba3bf863ef4534cc74756643 /python | |
parent | 3caac30ac5a8c2be453c1224e010fafa60e17ebf (diff) | |
download | qpid-python-e5f27778179696429e4212611c6e5454e2a63e99.tar.gz |
QPID-2916: throw an exception when a data value cannot be encoded correctly as its type.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1028501 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python')
-rw-r--r-- | python/qpid/codec010.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/python/qpid/codec010.py b/python/qpid/codec010.py index 5ad1ef14c1..0846db6bf7 100644 --- a/python/qpid/codec010.py +++ b/python/qpid/codec010.py @@ -85,11 +85,15 @@ class Codec(Packer): def read_uint8(self): return self.unpack("!B") def write_uint8(self, n): + if n < 0 or n > 255: + raise CodecException("Cannot encode %d as uint8" % n) return self.pack("!B", n) def read_int8(self): return self.unpack("!b") def write_int8(self, n): + if n < -128 or n > 127: + raise CodecException("Cannot encode %d as int8" % n) self.pack("!b", n) def read_char(self): @@ -108,22 +112,30 @@ class Codec(Packer): def read_uint16(self): return self.unpack("!H") def write_uint16(self, n): + if n < 0 or n > 65535: + raise CodecException("Cannot encode %d as uint16" % n) self.pack("!H", n) def read_int16(self): return self.unpack("!h") def write_int16(self, n): + if n < -32768 or n > 32767: + raise CodecException("Cannot encode %d as int16" % n) self.pack("!h", n) def read_uint32(self): return self.unpack("!L") def write_uint32(self, n): + if n < 0 or n > 4294967295: + raise CodecException("Cannot encode %d as uint32" % n) self.pack("!L", n) def read_int32(self): return self.unpack("!l") def write_int32(self, n): + if n < -2147483648 or n > 2147483647: + raise CodecException("Cannot encode %d as int32" % n) self.pack("!l", n) def read_float(self): |