From ec412c6da3ef9cb14c75d2a1def70c22266ab632 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 5 Oct 2016 12:24:55 +0200 Subject: [PATCH] protobuf: fix uvarint dumping In python3, chr() is not a proper way to pack an int to bytes. --- src/lib/protobuf.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/protobuf.py b/src/lib/protobuf.py index 9dfb2c91e..3d24ce865 100644 --- a/src/lib/protobuf.py +++ b/src/lib/protobuf.py @@ -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):