deserializing lists
This commit is contained in:
17
example.py
17
example.py
@@ -3,20 +3,33 @@
|
||||
|
||||
import betterproto
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
@dataclass
|
||||
class Baz(betterproto.Message):
|
||||
a: str = betterproto.string_field(1)
|
||||
|
||||
@dataclass
|
||||
class Foo(betterproto.Message):
|
||||
x: int = betterproto.int32_field(1)
|
||||
y: float = betterproto.double_field(2)
|
||||
z: List[Baz] = betterproto.message_field(3)
|
||||
|
||||
@dataclass
|
||||
class Bar(betterproto.Message):
|
||||
foo1: Foo = betterproto.message_field(1)
|
||||
foo2: Foo = betterproto.message_field(2)
|
||||
packed: List[int] = betterproto.int64_field(3)
|
||||
|
||||
# Serialization has not been changed yet. So nothing unusual here
|
||||
buffer = bytes(Bar(foo1 = Foo(1, 2.34), foo2 = Foo(3, 4.56)))
|
||||
buffer = bytes(
|
||||
Bar(
|
||||
foo1=Foo(1, 2.34),
|
||||
foo2=Foo(3, 4.56, [Baz("Hi"), Baz("There")]),
|
||||
packed=[5, 3, 1]
|
||||
)
|
||||
)
|
||||
|
||||
# Native deserialization happening here
|
||||
bar = Bar().parse(buffer)
|
||||
print(bar)
|
||||
print(bar)
|
||||
|
||||
Reference in New Issue
Block a user