mransan/ocaml-protoc

text_format, MessageToString and Merge functions

Closed this issue · 3 comments

Hi @mransan

There is a text_format module in protobuf which allows the message conversion between its binary representation and ascii representation (by calling MessageToString and Merge functions). May I ask whether the similar functions have been implemented in ocaml-protoc?

Many thanks!

ref: https://developers.google.com/protocol-buffers/docs/reference/python/google.protobuf.text_format-module

Yes! If no mode is specified when invoking ocaml-protoc it will by default generate files called <proto_file_name>_pp.{ml|mli}. Those file contains formatter function which can be used with the ocaml Format module:

For instance:

Format.fprintf Format.std_formatter "%a" Example02_pb.pp_person person 

Note however that there is decoding functionality for that format and there are no formal specification for the output. It should therefore be used only for debugging/logging purposes. If you want formally defined human readable encoding you can use proto3 JSON encoding.

Note as well that you can tweak which files get generated with command line arguments! (ie -binary -pp etc...)

OK, I see. This is really helpful, many thanks for the detailed answer. 👍