从 C++ 中的协议缓冲区获取所有字段名称?
Getting all field names from a protocol buffer in C++?
有没有办法在 C++ 中使用其描述符获取 protobuff 消息的所有字段?
在 Python 中有一种方法可以做到这一点,如下所示:
Getting all field names from a protocol buffer?
只是想知道 C++ 中是否有相同的东西。试图在 descriptor.h 上找到任何东西,但没有成功。
是的。如果您有一个 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,您可以在其中使用 FieldDescriptor::name()
.
找到每个字段的名称
有没有办法在 C++ 中使用其描述符获取 protobuff 消息的所有字段?
在 Python 中有一种方法可以做到这一点,如下所示: Getting all field names from a protocol buffer?
只是想知道 C++ 中是否有相同的东西。试图在 descriptor.h 上找到任何东西,但没有成功。
是的。如果您有一个 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,您可以在其中使用 FieldDescriptor::name()
.