我最近在使用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时。
使用该方法,我可以获得字段name
和high
吗?
如果不能,是否有更好的方法?
非常感谢。