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:
Erik Friese
2023-08-25 19:41:22 +02:00
parent 4cdf1bb9e0
commit 421aa78014
12 changed files with 1203 additions and 486 deletions

View File

@@ -779,6 +779,7 @@ class Message(ABC):
"""
Get the binary encoded Protobuf representation of this message instance.
"""
output = bytearray()
for field_name, meta in self._betterproto.meta_by_field_name.items():
try:
@@ -1002,6 +1003,14 @@ class Message(ABC):
:class:`Message`
The initialized message.
"""
if True:
# TODO: Make native deserialization optional
import betterproto_extras
betterproto_extras.deserialize(self, data)
return self
# Got some data over the wire
self._serialized_on_wire = True
proto_meta = self._betterproto