Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of life enhancements for RPC modules #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/plugin/emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ let emit_service_type scope ServiceDescriptorProto.{ name; method' = methods; _
let input = Scope.get_scoped_name scope input_type in
let input_t = Scope.get_scoped_name scope ~postfix:"t" input_type in
let output = Scope.get_scoped_name scope output_type in
let output_t = Scope.get_scoped_name scope ~postfix:"t" output_type in
let output_t = Scope.get_scoped_name scope ~postfix:"t" output_type in
Code.emit t `Begin "module %s = struct" capitalized_name;
Code.emit t `None "let name = \"/%s/%s\"" service_name name;
Code.emit t `None "let service = \"%s\"" service_name;
Code.emit t `None "let rpc = \"%s\"" name;

Code.emit t `None "module Request = %s" input;
Code.emit t `None "module Response = %s" output;
Code.emit t `End "end";
Expand Down Expand Up @@ -201,6 +204,8 @@ let rec emit_message ~params ~syntax scope
Code.emit signature `None "val make : %s" default_constructor_sig;
Code.emit signature `None "val to_proto: t -> Runtime'.Writer.t";
Code.emit signature `None "val from_proto: Runtime'.Reader.t -> (t, [> Runtime'.Result.error]) result";
Code.emit signature `None "val encode: t -> string";
Code.emit signature `None "val decode: string -> (t, [> Runtime'.Result.error]) result";

Code.emit implementation `None "let name' () = \"%s\"" (Scope.get_current_scope scope);
Code.emit implementation `None "type t = %s%s" type' params.annot;
Expand All @@ -221,6 +226,9 @@ let rec emit_message ~params ~syntax scope
Code.emit implementation `None "let deserialize = Runtime'.Deserialize.deserialize %s spec constructor in" extension_ranges;
Code.emit implementation `None "fun writer -> deserialize writer |> Runtime'.Result.open_error";
Code.emit implementation `End "";

Code.emit implementation `None "let encode t = to_proto t |> Runtime'.Writer.contents";
Code.emit implementation `None "let decode s = Runtime'.Reader.create s |> from_proto";
| None -> ()
in
{module_name; signature; implementation}
Expand Down