mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 11:58:13 +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))
|
raise ValueError('The field %s (\'%s\') is required but missing.' % (tag, name))
|
||||||
return message
|
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:
|
class Message:
|
||||||
# Represents a message instance.
|
# Represents a message instance.
|
||||||
|
|
||||||
@ -196,6 +205,10 @@ class Message:
|
|||||||
# Dumps the message into a write-like object.
|
# Dumps the message into a write-like object.
|
||||||
return self.message_type.dump(fp, self)
|
return self.message_type.dump(fp, self)
|
||||||
|
|
||||||
|
def dumps(self):
|
||||||
|
# Dumps the message into bytes
|
||||||
|
return self.message_type.dumps(self)
|
||||||
|
|
||||||
# Embedded message. ------------------------------------------------------------
|
# Embedded message. ------------------------------------------------------------
|
||||||
|
|
||||||
class EmbeddedMessage:
|
class EmbeddedMessage:
|
||||||
|
Loading…
Reference in New Issue
Block a user