首页 新闻 会员 周边

遍历所有protobuf消息字段

0
[待解决问题]

哪位大神知道如何遍历一个protobuf消息的所有字段吗?

我知道一种方法就是首先取到field_count,然后通过FindFieldByNumber(),来循环读取所有的字段,但是现在有一种情况,就是protobuf定义时,字段号是不连续的,比如下面这种,

message MyPb

{

     uint32    id      =1;

  uint32 score   =2;

  string name   =5;

  uint32  high   =6;

}

像上面这种定义,取到的field_count应该是4,那么我遍历时调用FindFieldByNumber(1)~FindFieldByNumber(4),能取到字段号为5的name以及为6的high吗?或者我的理解有问题,取得时候通过FindFieldByNumber(1)~FindFieldByNumber(4)便可以取到所有的字段。

谢谢。

CLFAL的主页 CLFAL | 初学一级 | 园豆:178
提问于:2017-04-25 13:53
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册