Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jopel committed Nov 12, 2024
1 parent 05caebb commit a36f504
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
File renamed without changes.
24 changes: 24 additions & 0 deletions scripts/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@

# Inline the size function for a given proto message field
def inline_size_function(proto_type: str, field_name: str, field_tag: str) -> str:
"""
For example:
class MessageMarshaler:
def size_uint32(self, TAG: bytes, FIELD_ATTR: int) -> int:
return len(TAG) + Varint.size_varint_u32(FIELD_ATTR)
Becomes:
size += len(b"\x10") + Varint.size_varint_u32(self.int_value)
"""
function_definition = inspect.getsource(globals()["MessageMarshaler"].__dict__[f"size_{proto_type}"])
# Remove the function header and unindent the function body
function_definition = function_definition.splitlines()[1:]
Expand All @@ -47,6 +58,19 @@ def inline_size_function(proto_type: str, field_name: str, field_tag: str) -> st

# Inline the serialization function for a given proto message field
def inline_serialize_function(proto_type: str, field_name: str, field_tag: str) -> str:
"""
For example:
class MessageMarshaler:
def serialize_uint32(self, out: BytesIO, TAG: bytes, FIELD_ATTR: int) -> None:
out.write(TAG)
Varint.serialize_varint_u32(out, FIELD_ATTR)
Becomes:
out.write(b"\x10")
Varint.serialize_varint_u32(out, self.int_value)
"""
function_definition = inspect.getsource(globals()["MessageMarshaler"].__dict__[f"serialize_{proto_type}"])
# Remove the function header and unindent the function body
function_definition = function_definition.splitlines()[1:]
Expand Down
2 changes: 1 addition & 1 deletion scripts/proto_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ echo "Creating temporary virtualenv at $venv_dir using $(python3 --version)"
python3 -m venv $venv_dir
source $venv_dir/bin/activate
python -m pip install \
-c $repo_root/gen-requirements.txt \
-c $repo_root/scripts/gen-requirements.txt \
protobuf Jinja2 grpcio-tools black isort .

echo 'python -m grpc_tools.protoc --version'
Expand Down

0 comments on commit a36f504

Please sign in to comment.