1
0
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:
Jan Pochyla 2016-05-19 16:47:35 +02:00 committed by Pavol Rusnak
parent 506f2e0c36
commit f5b802d421
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

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