mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 14:31:06 +00:00
add __repr__ to Message and MessageType
This commit is contained in:
parent
1da27dd558
commit
173c49bef8
@ -99,12 +99,13 @@ _unpack_key = lambda key: (key >> 3, key & 7)
|
||||
class MessageType:
|
||||
# Represents a message type.
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, name=None):
|
||||
# Creates a new message type.
|
||||
self.__tags_to_types = dict() # Maps a tag to a type instance.
|
||||
self.__tags_to_names = dict() # Maps a tag to a given field name.
|
||||
self.__defaults = dict() # Maps a tag to its default value.
|
||||
self.__flags = dict() # Maps a tag to FLAG_
|
||||
self.__name = name
|
||||
|
||||
def add_field(self, tag, name, field_type, flags=FLAG_SIMPLE, default=None):
|
||||
# Adds a field to the message type.
|
||||
@ -194,6 +195,9 @@ class MessageType:
|
||||
fp = BytesIO(buf)
|
||||
return self.load(fp)
|
||||
|
||||
def __repr__(self):
|
||||
return '<MessageType: %s>' % self.__name
|
||||
|
||||
class Message:
|
||||
# Represents a message instance.
|
||||
|
||||
@ -213,6 +217,11 @@ class Message:
|
||||
# Dumps the message into bytes
|
||||
return self.message_type.dumps(self)
|
||||
|
||||
def __repr__(self):
|
||||
values = self.__dict__
|
||||
values = {k:values[k] for k in values if k != 'message_type'}
|
||||
return '<%s: %s>' % (self.message_type.__name, values)
|
||||
|
||||
# Embedded message. ------------------------------------------------------------
|
||||
|
||||
class EmbeddedMessage:
|
||||
|
@ -8,7 +8,7 @@ from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper
|
||||
def process_type(t, cls, msg_id):
|
||||
imports = ["from protobuf import protobuf as p",]
|
||||
|
||||
out = ["t = p.MessageType()", ]
|
||||
out = ["t = p.MessageType('%s')" % t, ]
|
||||
|
||||
if msg_id is not None:
|
||||
out.append("t.wire_type = %d" % msg_id)
|
||||
|
Loading…
Reference in New Issue
Block a user