如何获取protobuf消息中的所有字段?

3

我最近在使用protobuf,遇到了一个问题。我想获取protobuf消息中的所有字段,我知道一个方法,使用field_count()来获取消息的字段数,然后使用函数FindFieldByNumber()来获取所有字段。但是,如果消息的字段编号是不连续的,例如:

message MyPb
{
uint32    id   =1;
int32 score    =2;
string name    =5;
uint32  high   =6;
}

那么,MyPb的字段数量为4,我使用

for(int i=1; i<=count; ++i)
{
    descriptor->FindFieldByNumber(i);
}

当count等于4时。

使用该方法,我可以获得字段namehigh吗? 如果不能,是否有更好的方法? 非常感谢。

1个回答

3

非常感谢您,您的答案解决了我的问题。 - ChengZhang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接