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

Commit 7f8070e

Browse files
committed
Generated methods for sync clients
1 parent f760f73 commit 7f8070e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/betterproto2_compiler/templates/service_stub_sync.py.j2

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,46 @@
3232
{% endblock %}
3333

3434
{% block method_body %}
35-
pass
35+
{% if method.server_streaming %}
36+
{% if method.client_streaming %}
37+
for response in self._channel.stream_stream(
38+
"{{ method.route }}",
39+
{{ method.py_input_message_type }}.SerializeToString,
40+
{{ method.py_output_message_type }}.FromString,
41+
)({{ method.py_input_message_param }}_iterator):
42+
yield response
43+
{% else %}
44+
{% if method.is_input_msg_empty %}
45+
if {{ method.py_input_message_param }} is None:
46+
{{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
47+
48+
{% endif %}
49+
for response in self._channel.unary_stream(
50+
"{{ method.route }}",
51+
{{ method.py_input_message_type }}.SerializeToString,
52+
{{ method.py_output_message_type }}.FromString,
53+
)({{ method.py_input_message_param }}):
54+
yield response
55+
56+
{% endif %}
57+
{% else %}
58+
{% if method.client_streaming %}
59+
return self._channel.stream_unary(
60+
"{{ method.route }}",
61+
{{ method.py_input_message_type }}.SerializeToString,
62+
{{ method.py_output_message_type }}.FromString,
63+
)({{ method.py_input_message_param }}_iterator)
64+
{% else %}
65+
{% if method.is_input_msg_empty %}
66+
if {{ method.py_input_message_param }} is None:
67+
{{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
68+
69+
{% endif %}
70+
return self._channel.unary_unary(
71+
"{{ method.route }}",
72+
{{ method.py_input_message_type }}.SerializeToString,
73+
{{ method.py_output_message_type }}.FromString,
74+
)({{ method.py_input_message_param }})
75+
{% endif %}
76+
{% endif %}
3677
{% endblock %}

0 commit comments

Comments
 (0)