[ANN] Ocaml-protoc-plugin 0.9: A protobuf compiler

Dear all,

I am happy to announce the first release of ocaml-protoc-plugin.

The library implements the full proto3 specification, and aims to generate ocaml idiomatic bindings to protobuf types/mesages defined in .proto files:

  • Messages are mapped to modules, with a type t
  • Enums are mapped to ADT’s
  • Oneof types are mapped to polymorphic variants

All types are serialized using the proto3 specification (i.e. all repeated scalar types are packed).

All parts (package, service definitions, includes etc.) are supported.

The library is available through opam:
opam install ocaml-protoc-plugin.

For more information, please visit the homepage of ocaml-protoc-plugin at: https://github.com/issuu/ocaml-protoc-plugin/

Comments and suggestions are more than welcome.

Regards
Anders Fugmann

8 Likes

Wow, great job. Congrats! I have a compile-to-JS project (unfortunately it uses BuckleScript because genType is incredibly useful) and when I reviewed the protobuf story I decided to go with protobufjs. Now ocaml-protoc-plugin looks incredible. One question I have is if you are open to stripping the runtime dependencies. It currently uses Base and ocplib-endian and a few ppxs. All of these are rather cumbersome to bring to the bucklescript-world. Or maybe a better way is to use a separate runtime for BuckleScript altogether?

How is this compared to ocaml-protoc?

I’m still using ocaml-protoc in one project, I should check this out before that project goes to production use I guess. Proto3 support sounds promising.

1 Like

OCaml-Protoc uses its own parser which chokes on “service” lines and some set of other smaller syntactic details (also does not support imports very well). It depends on ppx_deriving_protobuf which at last time I checked didn’t support OCaml 4.07+. In addition the code it generates puts records with same keys into the same module thus confusing OCaml’s inference to the point where you have to force the “proper” type on every let statement which makes the code read somewhat like C.

In addition the runtime is very imperative in nature, where you have to serialize and deserialize types through an somewhat ugly “Builder”-kind of API.

Hi,

Looks interesting. I have two questions though:

Is it faster than the Marshal module for serialization?

Is it safer than the Marshal module for deserialization?

Regards,
F.

I updated ppx_deriving_protobuf to support 4.08+, tested also the ocaml-protoc itself. But I agree about generated code, it’s a mess.

P.S. Checked the library, so good. Going to migrate to ocaml-protoc-plugin in my projects. Amazing!

It is on the todo-list to slim the amount of runtime dependencies, but its currently not the highest priority. PR’s to use the labled variant of the standard library are welcomed.

Protobuf is more than just a message format for serialization and deserialization. It allows you to define backward and forward compatible messages, as all fields in a message is explicitly tagged. Also the definition of messages for protobuf resides in a .proto file, which allows you to generate serialization and deserialization function for other languages that ocaml.

The library is not yet optimized for speed - but I gather it will never compete with native ocaml mashalling - Its definitely safer, as it will never segfault.

/Anders

1 Like

Since I wrote that comment I decided to give it a go, and I simply stubbed the required functions in Base and Endian modules which lives next to protobuf runtime files. Therefore, in order to fulfil my goal (JavaScript support via BuckleScript) it’s not necessary to remove them.

1 Like