Reputation: 4704
OK, I have a protobuf formatted data file. I also have a .proto file that describes the schema of the file.
I have found copious libraries that let me extract known messages out of the file. How nice.
However, I don't really know the structure of the file. There may be different top-level "messages" in the file, and what I really want to do is just inspect the file and get a dump of what's in it.
Would love to have a command that lets me do something like:
proto2json <format.proto> <datafile> -o <output.json>
Is this too much to ask for? The Google isn't yielding an obvious answer, so maybe there's something subtle about protobufs I don't get yet.
Ideas?
Upvotes: 0
Views: 5150
Reputation: 31
Here's a pass at solving the problem that you posed. Here's an example command line to run this tool.
$ ./proto2json.sh --schema=test/test.proto \
--root=Recording --in=test/test.pb --out=out.json
https://github.com/rohitsaboo/proto2json
Currently, the tool only supports protocol buffer schemas that do not depend on protos from other files. However, it should be possible to extend it to support "dependency_schemas".
Upvotes: 0
Reputation: 4704
Thanks to some helpful people on the protocol-buffers google group, I have an answer.
The answer is, "sorry, no".
Well, close. The problem is it's up to you to know what the "root" message is in the data file. In my case it wasn't obvious, so I was hoping a dump of the file would divulge the root. No luck, as the file itself doesn't know what the fields or messages are, they just have data that you can extract if you have the right .proto file.
In my case, I had a few suspicions as to what the root might be, so I did trial and error until I found the message that seemed to know what all of the fields are in the file.
It would have been nice if the .proto file indicated what the root message is, in which case I'm sure a tool to do this conversion would exist already.
I hope this helps.
Upvotes: 1