1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00
trezor-firmware/python/src/trezorlib/_proto_messages.mako
2022-11-01 10:57:27 +01:00

59 lines
1.6 KiB
Mako

# Automatically generated by pb2py
# fmt: off
# isort:skip_file
from enum import IntEnum
from typing import Sequence, Optional
from . import protobuf
% for enum in enums:
class ${enum.name}(IntEnum):
% for value in enum.value:
${value.name} = ${value.number}
% endfor
% endfor
% for message in messages:
<%
required_fields = [f for f in message.fields if f.required]
repeated_fields = [f for f in message.fields if f.repeated]
optional_fields = [f for f in message.fields if f.optional]
%>\
class ${message.name}(protobuf.MessageType):
MESSAGE_WIRE_TYPE = ${message.wire_type}
% if message.fields:
FIELDS = {
% for field in message.fields:
% if not field.required:
${field.number}: protobuf.Field("${field.name}", "${field.type_name}", repeated=${field.repeated}, required=${field.required}, default=${field.default_value_repr}),
% else:
${field.number}: protobuf.Field("${field.name}", "${field.type_name}", repeated=${field.repeated}, required=${field.required}),
% endif
% endfor
}
def __init__(
self,
*,
% for field in required_fields:
${field.name}: "${field.python_type}",
% endfor
% for field in repeated_fields:
${field.name}: Optional[Sequence["${field.python_type}"]] = None,
% endfor
% for field in optional_fields:
${field.name}: Optional["${field.python_type}"] = ${field.default_value_repr},
% endfor
) -> None:
% for field in repeated_fields:
self.${field.name}: Sequence["${field.python_type}"] = ${field.name} if ${field.name} is not None else []
% endfor
% for field in required_fields + optional_fields:
self.${field.name} = ${field.name}
% endfor
% endif
% endfor