Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 09b978e

Browse files
add serialized descriptorproto to python classes
1 parent 517c698 commit 09b978e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/betterproto2_compiler/plugin/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def custom_methods(self) -> list[str]:
266266

267267
return methods_source
268268

269+
@property
270+
def descriptor(self):
271+
return self.proto_obj.SerializeToString()
272+
269273

270274
def is_map(proto_field_obj: FieldDescriptorProto, parent_message: DescriptorProto) -> bool:
271275
"""True if proto_field_obj is a map, otherwise False."""
@@ -594,6 +598,10 @@ def py_name(self) -> str:
594598
def deprecated(self) -> bool:
595599
return bool(self.proto_obj.options and self.proto_obj.options.deprecated)
596600

601+
@property
602+
def descriptor(self):
603+
return self.proto_obj.SerializeToString()
604+
597605

598606
@dataclass(kw_only=True)
599607
class ServiceCompiler(ProtoContentBase):

src/betterproto2_compiler/templates/template.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class {{ enum.py_name | add_to_all }}(betterproto2.Enum):
66
"""
77
{% endif %}
88

9+
@staticmethod
10+
def _serialized_pb():
11+
return {{ enum.descriptor }}
12+
913
{% for entry in enum.entries %}
1014
{{ entry.name }} = {{ entry.value }}
1115
{% if entry.comment %}
@@ -45,6 +49,10 @@ class {{ message.py_name | add_to_all }}(betterproto2.Message):
4549
"""
4650
{% endif %}
4751

52+
@staticmethod
53+
def _serialized_pb():
54+
return {{ message.descriptor }}
55+
4856
{% for field in message.fields %}
4957
{{ field.get_field_string() }}
5058
{% if field.comment %}

0 commit comments

Comments
 (0)