Skip to content

Commit d40c193

Browse files
committed
Add helpers for advanced users
1 parent 027e57e commit d40c193

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

lib/grpc-protoc-plugin/grpc_protoc_plugin.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ module Server_rpc : sig
9090
end
9191

9292
val handlers : 'a list -> ('a, _) Grpc.Rpc.Handlers.t
93+
94+
(** {1 Advanced users API}
95+
96+
The following functions are meant for advanced users only. *)
97+
98+
val service_spec :
99+
(module S with type Request.t = 'request and type Response.t = 'response) ->
100+
Grpc.Rpc.Service_spec.t
101+
(** This is the function used by this module to extract and build a gRPC service
102+
spec from the information generated by [ocaml_protoc_plugin]. *)

lib/grpc-protoc/grpc_protoc.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ let decode (type a) (decode : Pbrt.Decoder.t -> a) buffer =
77
let decoder = Pbrt.Decoder.of_string buffer in
88
decode decoder
99

10+
let client_service_spec (rpc : _ Pbrt_services.Client.rpc) =
11+
{
12+
Grpc.Rpc.Service_spec.package = rpc.package;
13+
service_name = rpc.service_name;
14+
}
15+
1016
module Client_rpc = struct
1117
let make (type request response)
1218
(rpc : (request, _, response, _) Pbrt_services.Client.rpc) ~request_mode
1319
~response_mode =
1420
{
15-
Grpc.Rpc.Client_rpc.service_spec =
16-
{ package = rpc.package; service_name = rpc.service_name };
21+
Grpc.Rpc.Client_rpc.service_spec = client_service_spec rpc;
1722
rpc_name = rpc.rpc_name;
1823
encode_request = encode rpc.encode_pb_req;
1924
decode_response = decode rpc.decode_pb_res;
@@ -50,6 +55,12 @@ module Server_rpc = struct
5055
make rpc ~request_mode:Stream ~response_mode:Stream
5156
end
5257

53-
let handlers { Pbrt_services.Server.package; service_name; handlers } =
58+
let server_service_spec
59+
{ Pbrt_services.Server.package; service_name; handlers = _ } =
60+
{ Grpc.Rpc.Service_spec.package; service_name }
61+
62+
let handlers
63+
({ Pbrt_services.Server.package = _; service_name = _; handlers } as server)
64+
=
5465
Grpc.Rpc.Handlers.With_service_spec
55-
{ service_spec = { package; service_name }; handlers }
66+
{ service_spec = server_service_spec server; handlers }

lib/grpc-protoc/grpc_protoc.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@ module Server_rpc : sig
114114
end
115115

116116
val handlers : 'a Pbrt_services.Server.t -> (_, 'a) Grpc.Rpc.Handlers.t
117+
118+
(** {1 Advanced users API}
119+
120+
The following functions are meant for advanced users only. *)
121+
122+
val client_service_spec : _ Pbrt_services.Client.rpc -> Grpc.Rpc.Service_spec.t
123+
(** This is the function used by this module to extract and build a gRPC service
124+
spec from the information generated by [ocaml_protoc] on the client side. *)
125+
126+
val server_service_spec : _ Pbrt_services.Server.t -> Grpc.Rpc.Service_spec.t
127+
(** This is the function used by this module to extract and build a gRPC service
128+
spec from the information generated by [ocaml_protoc] on the server side. *)

0 commit comments

Comments
 (0)