Repository navigation
Add complete service path to service module - #49
Conversation
|
Thanks for the PR. I was considering if this logic is not better placed in let service_name (module Method : Rpc) =
match Method.package_name with
| None -> Method.service_name
| Some p -> Printf.sprintf "%s.%s" p Method.service_nameBut that can only be used with an actual service, i.e: let service_name = Ocaml_protoc_plugin.service_name (module Echo.Echo.Call)
...What is the usecase for this? Each Method already have a |
|
To register a service, currently we have to construct its full name by pulling information from one of its specific methods. This creates an unnecessary dependency—we want to register the service as a whole, so it feels strange to rely on a single method like For example, this is the current approach with https://github.com/dialohq/ocaml-grpc: let service = Grpc_eio.Server.Service.(v () |> call |> handle_request)
let name =
match Echo.Echo.Call.package_name with
| None -> Echo.Echo.Call.service_name
| Some path -> path ^ "." ^ Echo.Echo.Call.service_name
in
Grpc_eio.Server.add_service ~name ~serviceThis PR would allow us to do this instead, which is much more straightforward: Grpc_eio.Server.add_service
~name:Echo.Echo.package_service_name
~serviceThis new approach might be better because it decouples the service's identity from its methods and makes the service module the single source of truth for its own name. The code becomes more readable, and we get to remove that repetitive logic. |
|
Thanks for the explanation! Much appreciated and thanks for the PR. |
|
Thank you for approving it! I agree, that approach is much better 👍 |
CHANGES: - Add `package_service_name` to generated service modules, providing the complete protobuf service path directly (andersfugmann/ocaml-protoc-plugin#49, thanks @Nymphium) - Use binary mode for the plugin's standard input and output on Windows (andersfugmann/ocaml-protoc-plugin#51, thanks @linsyking) - Fix JSON decoder initialization when a message references an enum nested in another message (andersfugmann/ocaml-protoc-plugin#59, thanks @mbickers) - Read the complete protoc plugin request instead of treating a short input read as end-of-file (andersfugmann/ocaml-protoc-plugin#60, thanks @jeong-sik)
This PR adds a complete service name (
package.path.Service) to a service module.Previously, the full service name had to be constructed using an arbitrary method from that service. This was inconvenient, as the name is a property of the service itself, not a specific method.
With this PR, the name can be accessed directly from the service module, simplifying the logic.