Change to have parse
*always* set serialized_on_wire
This commit is contained in:
parent
5c700618fd
commit
28a288924f
@ -741,15 +741,15 @@ class Message(ABC):
|
|||||||
Parse the binary encoded Protobuf into this message instance. This
|
Parse the binary encoded Protobuf into this message instance. This
|
||||||
returns the instance itself and is therefore assignable and chainable.
|
returns the instance itself and is therefore assignable and chainable.
|
||||||
"""
|
"""
|
||||||
|
# Got some data over the wire
|
||||||
|
self._serialized_on_wire = True
|
||||||
|
|
||||||
for parsed in parse_fields(data):
|
for parsed in parse_fields(data):
|
||||||
field_name = self._betterproto.field_name_by_number.get(parsed.number)
|
field_name = self._betterproto.field_name_by_number.get(parsed.number)
|
||||||
if not field_name:
|
if not field_name:
|
||||||
self._unknown_fields += parsed.raw
|
self._unknown_fields += parsed.raw
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Got some data over the wire
|
|
||||||
self._serialized_on_wire = True
|
|
||||||
|
|
||||||
meta = self._betterproto.meta_by_field_name[field_name]
|
meta = self._betterproto.meta_by_field_name[field_name]
|
||||||
|
|
||||||
value: Any
|
value: Any
|
||||||
|
@ -39,11 +39,9 @@ def test_has_field():
|
|||||||
2, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
2, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
||||||
)
|
)
|
||||||
|
|
||||||
# Unset with empty collections
|
# Is always set from parse, even if all collections are empty
|
||||||
with_collections_empty = WithCollections().parse(bytes(WithCollections()))
|
with_collections_empty = WithCollections().parse(bytes(WithCollections()))
|
||||||
assert betterproto.serialized_on_wire(with_collections_empty) == False
|
assert betterproto.serialized_on_wire(with_collections_empty) == True
|
||||||
|
|
||||||
# Set with non-empty collections
|
|
||||||
with_collections_list = WithCollections().parse(
|
with_collections_list = WithCollections().parse(
|
||||||
bytes(WithCollections(test_list=["a", "b", "c"]))
|
bytes(WithCollections(test_list=["a", "b", "c"]))
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user