diff options
author | Dana Powers <dana.powers@rd.io> | 2015-11-28 19:34:37 +0800 |
---|---|---|
committer | Zack Dever <zack.dever@rd.io> | 2015-12-04 11:25:39 -0800 |
commit | f08775a6198cd16a7bc9ec93ffd057f65064ec54 (patch) | |
tree | e46e8df3d16e7baaf82a5d3dc260499955a7d39b /kafka/util.py | |
parent | dc94b5fe9f3f93bf6f2235d7f65c62fcf0a2a996 (diff) | |
download | kafka-python-f08775a6198cd16a7bc9ec93ffd057f65064ec54.tar.gz |
Switch crc32 back to signed integer -- this is consistent with protocol encoding spec
Diffstat (limited to 'kafka/util.py')
-rw-r--r-- | kafka/util.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/kafka/util.py b/kafka/util.py index 6d9d307..e95d51d 100644 --- a/kafka/util.py +++ b/kafka/util.py @@ -10,7 +10,13 @@ from kafka.common import BufferUnderflowError def crc32(data): - return binascii.crc32(data) & 0xffffffff + crc = binascii.crc32(data) + # py2 and py3 behave a little differently + # CRC is encoded as a signed int in kafka protocol + # so we'll convert the py3 unsigned result to signed + if six.PY3 and crc >= 2**31: + crc -= 2**32 + return crc def write_int_string(s): |