diff --git a/src/protobuf.py b/src/protobuf.py index 84ddf35c86..35e0aa955a 100644 --- a/src/protobuf.py +++ b/src/protobuf.py @@ -53,6 +53,14 @@ class UVarintType: WIRE_TYPE = 0 +class Sint32Type: + WIRE_TYPE = 0 + + +class Sint64Type: + WIRE_TYPE = 0 + + class BoolType: WIRE_TYPE = 0 @@ -143,6 +151,10 @@ async def load_message(reader, msg_type): if ftype is UVarintType: fvalue = ivalue + elif ftype is Sint32Type: + fvalue = (ivalue >> 1) ^ ((ivalue << 31) & 0xffffffff) + elif ftype is Sint64Type: + fvalue = (ivalue >> 1) ^ ((ivalue << 63) & 0xffffffffffffffff) elif ftype is BoolType: fvalue = bool(ivalue) elif ftype is BytesType: @@ -199,6 +211,12 @@ async def dump_message(writer, msg): if ftype is UVarintType: await dump_uvarint(writer, svalue) + elif ftype is Sint32Type: + await dump_uvarint(writer, ((svalue << 1) & 0xffffffff) ^ (svalue >> 31)) + + elif ftype is Sint64Type: + await dump_uvarint(writer, ((svalue << 1) & 0xffffffffffffffff) ^ (svalue >> 63)) + elif ftype is BoolType: await dump_uvarint(writer, int(svalue)) diff --git a/tools/pb2py b/tools/pb2py index ef61d7e945..50d7cebc7c 100755 --- a/tools/pb2py +++ b/tools/pb2py @@ -39,6 +39,10 @@ def process_type(t, cls, msg_id, indexfile, is_upy): # TYPE_SINT32 = 17 type = 'p.Sint32Type' + elif v.type in (18,): + # TYPE_SINT64 = 18 + type = 'p.Sint64Type' + elif v.type == 9: # TYPE_STRING = 9 type = 'p.UnicodeType'