Fix duration encoding for large values

This commit is contained in:
Alan Boudreault
2017-05-05 14:16:18 -04:00
parent 9adf704800
commit 373dc95556

View File

@@ -135,10 +135,13 @@ def vints_pack(values):
num_extra_bytes = 0
num_bits = v.bit_length()
# We need to reserve (num_extra_bytes+1) bits in the first byte
# ie. with 1 extra byte, the first byte needs to be something like '10XXXXXX'
while num_bits > (8-(num_extra_bytes+1)):
# ie. with 1 extra byte, the first byte needs to be something like '10XXXXXX' # 2 bits reserved
# ie. with 8 extra bytes, the first byte needs to be '11111111' # 8 bits reserved
reserved_bits = num_extra_bytes + 1
while num_bits > (8-(reserved_bits)):
num_extra_bytes += 1
num_bits -= 8
reserved_bits = min(num_extra_bytes + 1, 8)
revbytes.append(v & 0xff)
v >>= 8