I'm trying to append some documentation metainformation to a protobuf message by extending google.protobuf.MessageOptions. One of my metainfo option may appear more than once. Looks like I can declare repeated option but how can I use it on a message?
Here is an example of what I try to achieve:
extend google.protobuf.MessageOptions {
optional string description = 51234;
repeated string usages = 51235;
}
message MyMsg {
option (description) = "MyMsg description";
option (usages) = ???
optional bool myFlag = 1;
optional string myStr = 2;
}
What should I type instead of ??? if I want fo document two different ways of usage?
If I recall correctly, you can specify a repeated option multiple times:
message MyMsg {
option (description) = "MyMsg description";
option (usages) = "usage1";
option (usages) = "usage2";
optional bool myFlag = 1;
optional string myStr = 2;
}
Edit: the way to access repeated field is not documented and took some time to look throug headers so I decide to add it to this answer:
auto opts = MyMsg::descriptor()->options();
std::cout << opts.GetExtension(description) << std::endl;
for (int i = 0; i < opts.ExtensionSize(usages); ++i)
std::cout << opts.GetExtension(usages, i) << std::endl;
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