oneof support

This commit is contained in:
Erik Friese
2023-08-27 14:03:22 +02:00
parent d79a9eee14
commit a12c9d24de
4 changed files with 53 additions and 17 deletions

View File

@@ -5,17 +5,20 @@ import betterproto
from dataclasses import dataclass
from typing import List
@dataclass
@dataclass(repr=False)
class Baz(betterproto.Message):
a: str = betterproto.string_field(1)
a: float = betterproto.float_field(1, group = "x")
b: int = betterproto.int64_field(2, group = "x")
c: float = betterproto.float_field(3, group = "y")
d: int = betterproto.int64_field(4, group = "y")
@dataclass
@dataclass(repr=False)
class Foo(betterproto.Message):
x: int = betterproto.int32_field(1)
y: float = betterproto.double_field(2)
z: List[Baz] = betterproto.message_field(3)
@dataclass
@dataclass(repr=False)
class Bar(betterproto.Message):
foo1: Foo = betterproto.message_field(1)
foo2: Foo = betterproto.message_field(2)
@@ -25,7 +28,7 @@ class Bar(betterproto.Message):
buffer = bytes(
Bar(
foo1=Foo(1, 2.34),
foo2=Foo(3, 4.56, [Baz("Hi"), Baz("There")]),
foo2=Foo(3, 4.56, [Baz(a = 1.234), Baz(b = 5), Baz(b = 2, d = 3)]),
packed=[5, 3, 1]
)
)