File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -724,6 +724,9 @@ def parse(self: T, data: bytes) -> T:
724
724
Parse the binary encoded Protobuf into this message instance. This
725
725
returns the instance itself and is therefore assignable and chainable.
726
726
"""
727
+ # Got some data over the wire
728
+ self ._serialized_on_wire = True
729
+
727
730
for parsed in parse_fields (data ):
728
731
field_name = self ._betterproto .field_name_by_number .get (parsed .number )
729
732
if not field_name :
Original file line number Diff line number Diff line change 1
1
import betterproto
2
2
from dataclasses import dataclass
3
- from typing import Optional
3
+ from typing import Optional , List , Dict
4
4
5
5
6
6
def test_has_field ():
@@ -32,6 +32,25 @@ class Foo(betterproto.Message):
32
32
foo .bar = Bar ()
33
33
assert betterproto .serialized_on_wire (foo .bar ) is False
34
34
35
+ @dataclass
36
+ class WithCollections (betterproto .Message ):
37
+ test_list : List [str ] = betterproto .string_field (1 )
38
+ test_map : Dict [str , str ] = betterproto .map_field (
39
+ 2 , betterproto .TYPE_STRING , betterproto .TYPE_STRING
40
+ )
41
+
42
+ # Is always set from parse, even if all collections are empty
43
+ with_collections_empty = WithCollections ().parse (bytes (WithCollections ()))
44
+ assert betterproto .serialized_on_wire (with_collections_empty ) == True
45
+ with_collections_list = WithCollections ().parse (
46
+ bytes (WithCollections (test_list = ["a" , "b" , "c" ]))
47
+ )
48
+ assert betterproto .serialized_on_wire (with_collections_list ) == True
49
+ with_collections_map = WithCollections ().parse (
50
+ bytes (WithCollections (test_map = {"a" : "b" , "c" : "d" }))
51
+ )
52
+ assert betterproto .serialized_on_wire (with_collections_map ) == True
53
+
35
54
36
55
def test_class_init ():
37
56
@dataclass
You can’t perform that action at this time.
0 commit comments