From aa11b5720b6f54fbde4a2c66ac621485f7ceb404 Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Fri, 13 Jan 2017 14:23:55 -0500 Subject: [PATCH] fixed vints_unpack --- cassandra/marshal.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cassandra/marshal.py b/cassandra/marshal.py index cd81eb3d..2cb34cf4 100644 --- a/cassandra/marshal.py +++ b/cassandra/marshal.py @@ -91,11 +91,23 @@ def decode_zig_zag(n): def vints_unpack(term): # noqa - first_byte = ord(term[0]) - if (first_byte & 128) == 0: - val = first_byte - else: - extra_bytes = 8 - (~first_byte & 0xff).bit_length() - # takes (8-extra_bytes) bits + extra_bytes + values = [] + n = 0 + while n < len(term): + first_byte = ord(term[n]) - return decode_zig_zag(val) + if (first_byte & 128) == 0: + val = first_byte + else: + num_extra_bytes = 8 - (~first_byte & 0xff).bit_length() + val = first_byte & (0xff >> num_extra_bytes) + end = n + num_extra_bytes + while n < end: + n += 1 + val <<= 8 + val |= ord(term[n]) & 0xff + + n += 1 + values.append(decode_zig_zag(val)) + + return tuple(values)