Add support for protobuf Sint32 type

This commit is contained in:
slush 2017-12-12 19:19:55 +01:00
parent 5e7d2833af
commit 4916393139
2 changed files with 9 additions and 3 deletions

View File

@ -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))

View File

@ -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