ee2 ee2 - 1 month ago 33
C++ Question

protocol buffers get EnumDescriptor *

I have an UpdateType enum in my protocol buffers message

I want to modify it using reflections, for that I need EnumDescriptor.

Google protocol buffers Documentation says

#include <google/protobuf/descriptor.h>
namespace google::protobuf

Describes an enum type defined in a .proto file.

To get the EnumDescriptor for a generated enum type, call TypeName_descriptor(). Use DescriptorPool to construct your own descriptors.


How can I get EnumDescriptor? where is TypeName_descriptor() func?

Answer

You can get enum_descriptor from FieldDescriptor.

Just use FiledDescriptor::enum_type() to get EnumDescriptor*

Hope it helps !!