I need to use .desc
files to enable the reading of serialized protocol-buffer messages and their conversion to JSON (using jansson).
This is because the protocol-buffer message formats will change much more frequently than the C code. The .desc
files will be a runtime input to the executable.
I've found https://github.com/Sannis/protobuf2json-c but my reading of this is that it needs C code to be generated. In particular the ProtobufCMessage
needs to exist for the message being decoded, and I cannot see a way of making a ProtobufCMessage (from /usr/include/google/protobuf-c/protobuf-c.h
) without generating C code.
Have I missed something here, or will I need to write new code?
I'm not familiar with the .desc
extension but I'm guessing from the context that it is a file containing a protobuf FileDescriptorProto
, defined in google/protobuf/descriptor.proto
.
To do what you want, you will most likely need to use the Protobuf C++ or Java library, each of which defines a class DynamicMessage
which has the ability to emulate arbitrary message types based on descriptors. You can then combine this with any Protobuf-JSON library that is based on the standard Protobuf reflection interfaces. (You can also write your own JSON converter pretty easily; use the TextFormat
class (found in both the C++ and Java Protobuf libs) as a template.)
My understanding is that protobuf-c does not currently contain an equivalent to DynamicMessage
.