遍历一个protobuf消息的所有字段

zhangafei 2017-04-25 01:56:33
哪位大神知道如何遍历一个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)便可以取到所有的字段。
谢谢。
...全文
1803 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

6,721

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 Google技术社区
社区管理员
  • Google技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧