Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 698
CarlosR Avatar asked Jan 27 '16 20:01

CarlosR


1 Answers

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().

like image 54
Adi Levin Avatar answered Sep 19 '22 15:09

Adi Levin