summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Simon <allan.simon@supinfo.com>2019-02-27 00:02:35 +0100
committerOmer Katz <omer.drow@gmail.com>2019-02-27 01:02:35 +0200
commited759687c069b12c914d8ebdab26ef34d068fca9 (patch)
tree23b021dfc668aa55df648521e900f15cf8e0820b
parentb2a0269e147f0052603b19647744e1829ff07f61 (diff)
downloadpy-amqp-ed759687c069b12c914d8ebdab26ef34d068fca9.tar.gz
for deserialisation, correct offset for bits (#187)
* for deserialisation, correct offset for bits it needs to be increased only at the beginning and once every 8 bits * Added a test. * Autopep8. * Verify result.
-rw-r--r--amqp/serialization.py3
-rw-r--r--t/unit/test_serialization.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/amqp/serialization.py b/amqp/serialization.py
index 95c18ea..183ae2e 100644
--- a/amqp/serialization.py
+++ b/amqp/serialization.py
@@ -171,11 +171,12 @@ def loads(format, buf, offset=0,
if p == 'b':
if not bitcount:
bits = ord(buf[offset:offset + 1])
+ offset += 1
bitcount = 8
val = (bits & 1) == 1
bits >>= 1
bitcount -= 1
- offset += 1
+
elif p == 'o':
bitcount = bits = 0
val, = unpack_from('>B', buf, offset)
diff --git a/t/unit/test_serialization.py b/t/unit/test_serialization.py
index 811b1a6..3891090 100644
--- a/t/unit/test_serialization.py
+++ b/t/unit/test_serialization.py
@@ -98,6 +98,13 @@ class test_serialization:
with pytest.raises(FrameSyntaxError):
dumps('A', [[object()]])
+ def test_bit_offset_adjusted_correctly(self):
+ expected = [50, "quick", "fox", True,
+ False, False, True, True, {"prop1": True}]
+ buf = dumps('BssbbbbbF', expected)
+ actual, _ = loads('BssbbbbbF', buf)
+ assert actual == expected
+
class test_GenericContent: