1
votes

What's a smart way to generate and validate a protocol buffer spec? Is there any library (binding?) for the protoc file format, maybe java or python?

Just to be clear, I know that after my code generates a protocol buffer specification it will be fed to protoc for generating language-specific binding code. It's straightforward for me to invoke protoc to validate a generated spec (just check exit code etc.), but I thought maybe there's a better way.

The only vaguely related thing I could find is Cannot parse a protocol buffers file in python when using the correct .proto file

Thanks in advance.

1

1 Answers

0
votes

I would probably just invoke the protoc binary and check the exit code, because that command line interface is likely to be more stable across versions than a library interface.

However, all the relevant functionality is available in libprotoc.so. As a starting point, you can see the protoc main program here, which is beautifully short: https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/main.cc

I expect you could pretty much copy that to your own project and link against libprotoc.so.