Reputation: 1553
I'd like to do some message debugging on traffic for a few protobuf based services we use.
The services all use compiled .proto files for messages, and I'd like to serialize the actual format of the message back to .proto file text and send that to a client so that the client does not need to know implementation details at compile time.
Is this possible in C++? I know that I can get the structure of a message without the definition, but having the names of the message fields would be critical for debugging. Is there another way of getting this information without having the .proto files?
Thanks!
Upvotes: 1
Views: 802
Reputation: 1063864
If the original sender has the .proto files, they can be compiled by "protoc" into a protobuf data file, matching "descriptor.proto" (which should be available in your distribution of protobuf). You can do this by using
protoc --descriptor_set_out={out_path} --proto_path={in_path}
(or to stdout if you prefer, IIRC - untested)
The resultant binary data can be included as a bytes
field, and deserialized serparately as long as the client also has an object-model generated from descriptor.proto.
In terms of what to do once you have deserialized it: FileDescriptorSet
is the top-level object; you should be able to traverse down to FieldDescriptorProto
, which has the member-name etc
Perhaps not very elegant, but it should work.
Alternatively, include the metadata any-which-way, and treat everything as extension fields.
Upvotes: 2