issuu / ocaml-protoc-plugin

ocaml-protoc-plugin
https://issuu.github.io/ocaml-protoc-plugin/
Other
48 stars 19 forks source link

Unique OCaml module for all messages #63

Open lambdaxdotx opened 3 weeks ago

lambdaxdotx commented 3 weeks ago

Hi, Thanks for your work on this project.

This is a feature request more than an actual issue.

tldr: Would it be possible to modify the OCaml generation to optionally emit a single OCaml module for all messages in a .proto file rather than a separate module for each of the messages?

A more reasoned request follows. Messages can be structured to follow a hierarchy, as in this example:

message A {
  bool is_something = 1;
  repeated B bs = 2;
}

message B {
  bool is_something_else = 1;
  oneof content {
    C c = 2;
    D d = 3;
  }
}

message C { ... }
message D { ... }

Especially in such cases, it would be useful to optionally have in output just an OCaml module with a type mirroring such a hierarchy, approximately of the form:

type a = {
  is_something: bool;
  bs: b list;
}

and b = {
  is_something_else: bool;
  content: [ `not_set | `C of c | `D of d ];
} 

and c = { ... }
and d = {....}

Such an OCaml type hierarchy allows for easier navigation of the type structure than the current one. In particular, it would be easier to write a ppx for doing something on such a solution than the current one.

Does this sound reasonable? How hard would it be to make such a change?

andersfugmann commented 2 weeks ago

Please note that active development of the ocaml-protoc-plugin has moved to https://github.com/andersfugmann/ocaml-protoc-plugin. I have replied to your question here: https://github.com/andersfugmann/ocaml-protoc-plugin/issues/42.