Native deserialization based on Rust and PyO3
Proof of concept Only capable of deserializing (nested) Messages with primitive fields No handling of lists, maps, enums, .. implemented yet See `example.py` for a working example
This commit is contained in:
22
example.py
Normal file
22
example.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# dev tests
|
||||
# to be deleted later
|
||||
|
||||
import betterproto
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Foo(betterproto.Message):
|
||||
x: int = betterproto.int32_field(1)
|
||||
y: float = betterproto.double_field(2)
|
||||
|
||||
@dataclass
|
||||
class Bar(betterproto.Message):
|
||||
foo1: Foo = betterproto.message_field(1)
|
||||
foo2: Foo = betterproto.message_field(2)
|
||||
|
||||
# Serialization has not been changed yet. So nothing unusual here
|
||||
buffer = bytes(Bar(foo1 = Foo(1, 2.34), foo2 = Foo(3, 4.56)))
|
||||
|
||||
# Native deserialization happening here
|
||||
bar = Bar().parse(buffer)
|
||||
print(bar)
|
||||
Reference in New Issue
Block a user