fix encoding of length > 128
This commit is contained in:
parent
6ce08c5871
commit
f8b45ab854
|
@ -8,12 +8,10 @@ def codelength(s):
|
||||||
l = len(s)
|
l = len(s)
|
||||||
if l == 0:
|
if l == 0:
|
||||||
return b'\x00'
|
return b'\x00'
|
||||||
encodedlen = b''
|
encodedlen = (l & 0x7F).to_bytes(1, 'little')
|
||||||
while l > 0:
|
while l > 0x7F:
|
||||||
c = l & 0x7F
|
|
||||||
l = l >> 7
|
l = l >> 7
|
||||||
if l > 0:
|
c = (l & 0x7F) | 0x80
|
||||||
c = c + 128
|
|
||||||
encodedlen = c.to_bytes(1, 'little') + encodedlen
|
encodedlen = c.to_bytes(1, 'little') + encodedlen
|
||||||
return encodedlen + s
|
return encodedlen + s
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue