I'd like to use protocol buffer in my program to read data from a file. I also would like to be able to edit the data file with any text editor, for a start (I'll write a data editor later on, and switch to full binary).
Is there a way to parse a human-readable format ? (debug string provided by protobuf itself, or some other format).
The question doesn't specify the programming language, and my answer is only about Java.
In Java, a Message
instance's toString
method returns a human-readable textual format. The same format can then be parsed into a Message
instance by TextFormat.merge
:
String messageString = ...
MyMessage.Builder builder = MyMessage.newBuilder();
TextFormat.merge(messageString, builder);
MyMessage newMessage = builder.build();
(Variations of the merge
method can also read from a stream, to avoid reading the whole message string into memory.)
There is a text based format too, but support for this is implementation specific. For example, I don't support it at all in protobuf-net. But yes: such is defined, and discussed (for example) here: http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.text_format.html
Personally, I'd rather use binary and write a UI around the model.
If you don't mind using command-line tools, the Piqi project includes piqi convert command for converting between 4 formats: binary Protocol Buffers, JSON, XML and Piq. The Piq format is specially designed for viewing and editing data in a text editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With