mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 19:38:09 +00:00
add loads, dumps to MessageType and Message
This commit is contained in:
parent
506f2e0c36
commit
f5b802d421
@ -185,6 +185,15 @@ class MessageType:
|
||||
raise ValueError('The field %s (\'%s\') is required but missing.' % (tag, name))
|
||||
return message
|
||||
|
||||
def dumps(self, value):
|
||||
fp = BytesIO()
|
||||
self.dump(fp, value)
|
||||
return fp.getvalue()
|
||||
|
||||
def loads(self, buf):
|
||||
fp = BytesIO(buf)
|
||||
return self.load(fp)
|
||||
|
||||
class Message:
|
||||
# Represents a message instance.
|
||||
|
||||
@ -196,6 +205,10 @@ class Message:
|
||||
# Dumps the message into a write-like object.
|
||||
return self.message_type.dump(fp, self)
|
||||
|
||||
def dumps(self):
|
||||
# Dumps the message into bytes
|
||||
return self.message_type.dumps(self)
|
||||
|
||||
# Embedded message. ------------------------------------------------------------
|
||||
|
||||
class EmbeddedMessage:
|
||||
|
Loading…
Reference in New Issue
Block a user