diff --git a/cassandra/marshal.py b/cassandra/marshal.py index 51010891..cf9c7656 100644 --- a/cassandra/marshal.py +++ b/cassandra/marshal.py @@ -37,6 +37,8 @@ def bitlength(n): def varint_pack(big): pos = True + if big == 0: + return '\x00' if big < 0: bytelength = bitlength(abs(big) - 1) / 8 + 1 big = (1 << bytelength * 8) + big diff --git a/tests/unit/test_marshalling.py b/tests/unit/test_marshalling.py index 6b707339..9abb8547 100644 --- a/tests/unit/test_marshalling.py +++ b/tests/unit/test_marshalling.py @@ -61,6 +61,7 @@ marshalled_value_pairs = ( # vagaries of internal python ordering for unordered types ('\x00\x03\x00\x06\xe3\x81\xbfbob\x00\x04\x00\x00\x00\xc7\x00\x00\x00\x04\xff\xff\xff\xff\x00\x01\\\x00\x04\x00\x00\x00\x00', 'MapType(UTF8Type, Int32Type)', {u'\u307fbob': 199, u'': -1, u'\\': 0}), ('\x00\x02\x00\x08@\x14\x00\x00\x00\x00\x00\x00\x00\x08@\x01\x99\x99\x99\x99\x99\x9a', 'SetType(DoubleType)', set([2.2, 5.0])), + ('\x00', 'IntegerType', 0), ) class TestUnmarshal(unittest.TestCase):