Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Unique OCaml module for all messages #63

@lambdaxdotx

Description

@lambdaxdotx

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions