协议缓冲区获取 EnumDescriptor *

protocol buffers get EnumDescriptor *

我的协议缓冲区消息中有一个 UpdateType 枚举

我想使用反射修改它,为此我需要 EnumDescriptor。

Google protocol buffers Documentation

#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.

如何获取 EnumDescriptor? TypeName_descriptor() 函数在哪里?

您可以从 FieldDescriptor 中获取 enum_descriptor。

只需使用 FieldDescriptor::enum_type() 获取 EnumDescriptor*

希望对您有所帮助!!