当前位置: 代码迷 >> 综合 >> C++ Protocol Buffer RepeatedPtrField 类型遍历及成员函数
  详细解决方案

C++ Protocol Buffer RepeatedPtrField 类型遍历及成员函数

热度:50   发布时间:2023-09-18 13:31:12.0

Protocol Buffer Repeated 对应类型为

::google::protobuf::RepeatedPtrField

如果想要遍历该类型,可以使用 iterator 

typedef ::google::protobuf::RepeatedPtrField<Person> ptrf;// classmates is repeated type
ptrf *clsmates = school.mutable_classmates(); for (ptrf::iterator it = clsmates->begin(); it != clsmates->end(); ++it)
{it->set_name("xxx"); // name is a field in Personit->set_age(18);
}/**// SchoolMember.pb
message SchoolMember
{repeated Person classmates = 1;...
}message Person
{required string name = 1;required uint32 age  = 2;
}*/

 

  相关解决方案