Is there a way to get all the fields of a protobuff message using its descriptor, in C++?
There's a way to do that in Python like this: Getting all field names from a protocol buffer?
Just wondering if there's the same thing in C++. Tried to find anything on the descriptor.h, but without success.
Yes. If you have a Descriptor, you get the number of fields using Descriptor::field_count()
. Then, you iterate over the fields using Descriptor::field(int index)
, which returns a FieldDescriptor, where you can find the name of each field using FieldDescriptor::name()
.
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