2021-03-23 12:30:03 +00:00
|
|
|
from typing import *
|
|
|
|
from trezor.protobuf import MessageType
|
|
|
|
T = TypeVar("T", bound=MessageType)
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/rustmods/modtrezorproto.c
|
2021-12-08 09:10:58 +00:00
|
|
|
def type_for_name(name: str) -> type[T]:
|
2021-03-23 12:30:03 +00:00
|
|
|
"""Find the message definition for the given protobuf name."""
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/rustmods/modtrezorproto.c
|
2021-12-08 09:10:58 +00:00
|
|
|
def type_for_wire(wire_type: int) -> type[T]:
|
2021-03-23 12:30:03 +00:00
|
|
|
"""Find the message definition for the given wire type (numeric
|
|
|
|
identifier)."""
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/rustmods/modtrezorproto.c
|
|
|
|
def decode(
|
|
|
|
buffer: bytes,
|
|
|
|
msg_type: Type[T],
|
|
|
|
enable_experimental: bool,
|
|
|
|
) -> T:
|
|
|
|
"""Decode data in the buffer into the specified message type."""
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/rustmods/modtrezorproto.c
|
|
|
|
def encoded_length(msg: MessageType) -> int:
|
|
|
|
"""Calculate length of encoding of the specified message."""
|
|
|
|
|
|
|
|
|
|
|
|
# extmod/rustmods/modtrezorproto.c
|
|
|
|
def encode(buffer: bytearray, msg: MessageType) -> int:
|
|
|
|
"""Encode the message into the specified buffer. Return length of
|
|
|
|
encoding."""
|