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)
|
||||
|
||||
|
||||
_UVARINT_DUMP_BUFFER = bytearray(1)
|
||||
|
||||
|
||||
class UVarintType:
|
||||
WIRE_TYPE = 0
|
||||
|
||||
@staticmethod
|
||||
def dump(target, value):
|
||||
shifted_value = True
|
||||
while shifted_value:
|
||||
shifted_value = value >> 7
|
||||
yield from target.write(chr((value & 0x7F) | (
|
||||
0x80 if shifted_value != 0 else 0x00)))
|
||||
value = shifted_value
|
||||
async def dump(target, value):
|
||||
shifted = True
|
||||
while shifted:
|
||||
shifted = value >> 7
|
||||
_UVARINT_DUMP_BUFFER[0] = (value & 0x7F) | (
|
||||
0x80 if shifted else 0x00)
|
||||
await target.write(_UVARINT_DUMP_BUFFER)
|
||||
value = shifted
|
||||
|
||||
@staticmethod
|
||||
def load(source):
|
||||
|
Loading…
Reference in New Issue
Block a user