This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new ac47fe90d feat(compiler): add helpers to generate unified gRPC
service/method names (#3672)
ac47fe90d is described below
commit ac47fe90dbe50a6df72943b73cbca5c14e57a745
Author: Peiyang He <[email protected]>
AuthorDate: Tue May 12 11:26:31 2026 -0400
feat(compiler): add helpers to generate unified gRPC service/method names
(#3672)
## Why?
gRPC dispatches calls by the fully-qualified service name and method
path, for example `demo.greeter.Greeter` and
`/demo.greeter.Greeter/SayHello`.
For generated gRPC code to interoperate across different languages,
every language generator must generate these names from the same rule.
Centralizing the helpers in `compiler/fory_compiler/generators/base.py`
avoids redundancy logic in each language generator and make sure the
generated names are the same.
## What does this PR do?
Add helpers to generate unified gRPC service/method names in
`compiler/fory_compiler/generators/base.py`.
## Related issues
https://github.com/apache/fory/issues/3266
## AI Contribution Checklist
- [X] Substantial AI assistance was used in this PR: `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
---
compiler/fory_compiler/generators/base.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/compiler/fory_compiler/generators/base.py
b/compiler/fory_compiler/generators/base.py
index 6c4a9e8e1..77d401e4c 100644
--- a/compiler/fory_compiler/generators/base.py
+++ b/compiler/fory_compiler/generators/base.py
@@ -30,6 +30,8 @@ from fory_compiler.ir.ast import (
ListType,
ArrayType,
MapType,
+ RpcMethod,
+ Service,
)
from fory_compiler.ir.types import ARRAY_ELEMENT_KINDS
@@ -85,6 +87,18 @@ class BaseGenerator(ABC):
"""
return []
+ def get_grpc_service_name(self, service: Service) -> str:
+ """Get the gRPC service name."""
+ # e.g. for service `Greeter` defined in package `demo.greeter`, return
`demo.greeter.Greeter`.
+ if self.package:
+ return f"{self.package}.{service.name}"
+ return service.name
+
+ def get_grpc_method_path(self, service: Service, method: RpcMethod) -> str:
+ """Get the gRPC method path."""
+ # e.g. for method `sayHello` defined in service `demo.greeter.Greeter,
return `/demo.greeter.Greeter/SayHello`.
+ return f"/{self.get_grpc_service_name(service)}/{method.name}"
+
@abstractmethod
def generate_type(self, field_type: FieldType, nullable: bool = False) ->
str:
"""Generate the type string for a field type."""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]