Skip to content

Tweaks to generated code for ocaml-grpc #224

Closed
@mbarbin

Description

@mbarbin

Thank you for ocaml-protoc.3.0!

I'm currently working on modifications to ocaml-grpc to enhance the typing of
gRPC services and facilitate the selection of serialization backends.

I've added a proof of concept for ocaml-protoc.3.0 support in this PR. While it's functional, I believe the interface exposed by the generated code could
benefit from minor adjustments.

For instance, consider the services interface generated for the greeter-protoc example taken from the PR:

module Greeter : sig
  open Pbrt_services
  open Pbrt_services.Value_mode
  
  module Client : sig
    val sayHello : (hello_request, unary, hello_reply, unary) Client.rpc
  end
  
  module Server : sig
    val make : 
      sayHello:((hello_request, unary, hello_reply, unary) Server.rpc -> 'handler) ->
      unit -> 'handler Pbrt_services.Server.t
  end
end

To construct a Grpc.Rpc.t specification, we need:

  1. Pbrt_service.Client.rpc (for request encoding and response decoding)
  2. Pbrt_service.Server.rpc (for request decoding and response encoding)
  3. Pbrt_service.Server.t (for accessing the packages, service, and rpc names)

As shown in the generated interface above, the first value (Client.sayHello)
is readily available. However, accessing the second and third values requires
applying a dummy closure to Server.make, which somewhat misuses the current
interface exposed by the generated code.

A possibly more suitable interface for the specification-oriented design I'm
developing would repackage the value as follows:

module SayHello : sig
  val client : (hello_request, unary, hello_reply, unary) Client.rpc
  val server : (hello_request, unary, hello_reply, unary) Server.rpc
end

This repackaged SayHello could then be used as a single first-class module
argument to a function Grpc_protoc.make_rpc that would build the specification
accordingly.

I'd appreciate your thoughts on this. To note that the work I'm doing on
ocaml-grpc is very exploratory, so this is really just an early discussion at
this stage.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions