From c8e4fd7fbafec2af1a84680a78e58adf3186d9f4 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Fri, 16 Aug 2024 11:36:53 +0200 Subject: [PATCH] feat(trezorlib): allow encoding of protobuf messages without wire type [no changelog] --- python/src/trezorlib/mapping.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/src/trezorlib/mapping.py b/python/src/trezorlib/mapping.py index d50324d58..e4a2d1e2a 100644 --- a/python/src/trezorlib/mapping.py +++ b/python/src/trezorlib/mapping.py @@ -68,6 +68,16 @@ class ProtobufMapping: protobuf.dump_message(buf, msg) return wire_type, buf.getvalue() + def encode_without_wire_type(self, msg: protobuf.MessageType) -> bytes: + """Serialize a Python protobuf class. + + Returns the byte representation of the protobuf message. + """ + + buf = io.BytesIO() + protobuf.dump_message(buf, msg) + return buf.getvalue() + def decode(self, msg_wire_type: int, msg_bytes: bytes) -> protobuf.MessageType: """Deserialize a protobuf message into a Python class.""" cls = self.type_to_class[msg_wire_type]