Getting all field names from protocol buffer in C ++?

Is there a way to get all fields of a protobuff message using its handle in C ++?

There is a way to do this in Python as follows: Getting all field names from the protocol buffer?

Just wondering if there is the same thing in C ++. I tried to find something on descriptor.h , but to no avail.

+4
source share
1 answer

Yes. If you have a Descriptor , you will get the number of fields using Descriptor::field_count(). Then you iterate over the fields with the help of Descriptor::field(int index)which FieldDescriptor returns , where you can find the name of each field using FieldDescriptor::name().

+5
source

Source: https://habr.com/ru/post/1626249/


All Articles