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

Commit ab50cbf

Browse files
add serialized descriptorproto to python classes
1 parent f6aa679 commit ab50cbf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/betterproto2_compiler/plugin/models.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def comment(self) -> str:
153153
"""
154154
return get_comment(proto_file=self.source_file, path=self.path)
155155

156-
157156
@dataclass(kw_only=True)
158157
class PluginRequestCompiler:
159158
plugin_request_obj: CodeGeneratorRequest
@@ -261,6 +260,10 @@ def custom_methods(self) -> list[str]:
261260
methods_source.append(source.strip())
262261

263262
return methods_source
263+
264+
@property
265+
def descriptor(self):
266+
return self.proto_obj.SerializeToString()
264267

265268

266269
def is_map(proto_field_obj: FieldDescriptorProto, parent_message: DescriptorProto) -> bool:
@@ -523,7 +526,10 @@ def py_name(self) -> str:
523526
@property
524527
def deprecated(self) -> bool:
525528
return bool(self.proto_obj.options and self.proto_obj.options.deprecated)
526-
529+
530+
@property
531+
def descriptor(self):
532+
return self.proto_obj.SerializeToString()
527533

528534
@dataclass(kw_only=True)
529535
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 }}(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 }}(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)