2017-04-25 402 views
2

这些天我正在使用protobuf,而且遇到了问题。 我想获得protobuf消息中的所有字段,并且我知道一种方法,使用field_count()来获取消息的字段数,然后使用函数FindFieldByNumber()获取所有字段。但是,如果消息的场数是不连续的,例如:如何获取protobuf消息中的所有字段?

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? 如果没有,请给一些人一个更好的方法? 非常感谢。

回答