1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

protobuf: message fields moved to get_fields method

This commit is contained in:
Dusan Klinec 2018-09-18 14:13:21 +02:00 committed by Jan Pochyla
parent 3ae4106465
commit 6d98a97f7c

View File

@ -108,7 +108,10 @@ class UnicodeType:
class MessageType: class MessageType:
WIRE_TYPE = 2 WIRE_TYPE = 2
FIELDS = {}
@classmethod
def get_fields(cls):
return {}
def __init__(self, **kwargs): def __init__(self, **kwargs):
for kw in kwargs: for kw in kwargs:
@ -149,7 +152,7 @@ FLAG_REPEATED = const(1)
async def load_message(reader, msg_type): async def load_message(reader, msg_type):
fields = msg_type.FIELDS fields = msg_type.get_fields()
msg = msg_type() msg = msg_type()
while True: while True:
@ -204,8 +207,8 @@ async def load_message(reader, msg_type):
setattr(msg, fname, fvalue) setattr(msg, fname, fvalue)
# fill missing fields # fill missing fields
for tag in msg.FIELDS: for tag in fields:
field = msg.FIELDS[tag] field = fields[tag]
if not hasattr(msg, field[0]): if not hasattr(msg, field[0]):
setattr(msg, field[0], None) setattr(msg, field[0], None)
@ -215,7 +218,7 @@ async def load_message(reader, msg_type):
async def dump_message(writer, msg): async def dump_message(writer, msg):
repvalue = [0] repvalue = [0]
mtype = msg.__class__ mtype = msg.__class__
fields = mtype.FIELDS fields = mtype.get_fields()
for ftag in fields: for ftag in fields:
fname, ftype, fflags = fields[ftag] fname, ftype, fflags = fields[ftag]