mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 23:40:58 +00:00
protobuf: skip None values while dumping
This commit is contained in:
parent
fb7b85e479
commit
976b14a5b8
@ -204,7 +204,8 @@ class MessageType:
|
|||||||
raise TypeError('Incompatible type')
|
raise TypeError('Incompatible type')
|
||||||
for tag, field in self.__fields.items():
|
for tag, field in self.__fields.items():
|
||||||
field_type, field_flags, field_name = field
|
field_type, field_flags, field_name = field
|
||||||
if field_name not in value.__dict__:
|
field_value = getattr(value, field_name, None)
|
||||||
|
if field_value is None:
|
||||||
if field_flags & FLAG_REQUIRED:
|
if field_flags & FLAG_REQUIRED:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'The field with the tag %s is required but a value is missing.' % tag)
|
'The field with the tag %s is required but a value is missing.' % tag)
|
||||||
@ -214,13 +215,13 @@ class MessageType:
|
|||||||
# repeated value
|
# repeated value
|
||||||
key = _pack_key(tag, field_type.WIRE_TYPE)
|
key = _pack_key(tag, field_type.WIRE_TYPE)
|
||||||
# send the values sequentially
|
# send the values sequentially
|
||||||
for single_value in getattr(value, field_name):
|
for single_value in field_value:
|
||||||
yield from UVarintType.dump(target, key)
|
yield from UVarintType.dump(target, key)
|
||||||
yield from field_type.dump(target, single_value)
|
yield from field_type.dump(target, single_value)
|
||||||
else:
|
else:
|
||||||
# single value
|
# single value
|
||||||
yield from UVarintType.dump(target, _pack_key(tag, field_type.WIRE_TYPE))
|
yield from UVarintType.dump(target, _pack_key(tag, field_type.WIRE_TYPE))
|
||||||
yield from field_type.dump(target, getattr(value, field_name))
|
yield from field_type.dump(target, field_value)
|
||||||
|
|
||||||
def load(self, target, source=None):
|
def load(self, target, source=None):
|
||||||
if source is None:
|
if source is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user