mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-22 05:10:56 +00:00
protobuf: fix uvarint dumping
In python3, chr() is not a proper way to pack an int to bytes.
This commit is contained in:
parent
6be657114e
commit
ec412c6da3
@ -43,17 +43,21 @@ def print_protobuf_message(message_type):
|
|||||||
print('CLOSE', message_type)
|
print('CLOSE', message_type)
|
||||||
|
|
||||||
|
|
||||||
|
_UVARINT_DUMP_BUFFER = bytearray(1)
|
||||||
|
|
||||||
|
|
||||||
class UVarintType:
|
class UVarintType:
|
||||||
WIRE_TYPE = 0
|
WIRE_TYPE = 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dump(target, value):
|
async def dump(target, value):
|
||||||
shifted_value = True
|
shifted = True
|
||||||
while shifted_value:
|
while shifted:
|
||||||
shifted_value = value >> 7
|
shifted = value >> 7
|
||||||
yield from target.write(chr((value & 0x7F) | (
|
_UVARINT_DUMP_BUFFER[0] = (value & 0x7F) | (
|
||||||
0x80 if shifted_value != 0 else 0x00)))
|
0x80 if shifted else 0x00)
|
||||||
value = shifted_value
|
await target.write(_UVARINT_DUMP_BUFFER)
|
||||||
|
value = shifted
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(source):
|
def load(source):
|
||||||
|
Loading…
Reference in New Issue
Block a user