Search code examples
c++c++11enumsprotocol-buffers

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?


Solution

  • You can get enum_descriptor from FieldDescriptor.

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

    Hope it helps !!