2017-04-25 74 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? 如果沒有,請給一些人一個更好的方法? 非常感謝。

回答

相關問題