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?
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.
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.
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.
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.