From 4916393139ba6557b68b5385d6c7b2ca1244c1c0 Mon Sep 17 00:00:00 2001 From: slush Date: Tue, 12 Dec 2017 19:19:55 +0100 Subject: [PATCH] Add support for protobuf Sint32 type --- src/protobuf.py | 7 +++++++ tools/pb2py | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/protobuf.py b/src/protobuf.py index 229f7d94..403de342 100644 --- a/src/protobuf.py +++ b/src/protobuf.py @@ -54,6 +54,8 @@ async def dump_uvarint(writer, n): class UVarintType: WIRE_TYPE = 0 +class Sint32Type: + WIRE_TYPE = 0 class BoolType: WIRE_TYPE = 0 @@ -145,6 +147,8 @@ 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 BoolType: fvalue = bool(ivalue) elif ftype is BytesType: @@ -201,6 +205,9 @@ 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 BoolType: await dump_uvarint(writer, int(svalue)) diff --git a/tools/pb2py b/tools/pb2py index 47170e62..ef61d7e9 100755 --- a/tools/pb2py +++ b/tools/pb2py @@ -35,10 +35,9 @@ def process_type(t, cls, msg_id, indexfile, is_upy): # TYPE_ENUM = 14 type = 'p.UVarintType' - elif v.type in (17, 18): - # TYPE_SINT64 = 18 + elif v.type in (17,): # TYPE_SINT32 = 17 - type = 'p.VarintType' + type = 'p.Sint32Type' elif v.type == 9: # TYPE_STRING = 9