1.C++ to pb
1.1 map嵌套对象结构
//pb数据结构 message Inner { repeated string codes = 1; map<string, string> ext = 2; }; message Outer { map<int32, Inner> uint2Inner = 1; map<string, string> ext = 2; };
赋值代码 :
Outer req; req.mutable_ext()->insert({"keyA", "valueA"}); // uint2Inner auto uint2inner = req.mutable_uint2Inner();// 复杂的map成员添加元素 uint32_t a=5; auto inner = (*uint2inner)[a];// map复杂对象添加成员 for (const auto& code : codes) { inner.add_codes(code); // repeated类型循环添加成员 } inner.mutable_ext()->insert({"lat", "123"}); //map简单类型的直接mutable&insert就行
1.2 嵌套map
// pb类型 message InnerStrMap { map<string, string> value = 1; }; message PullLiveRoomListReq{ map<string, string> ext = 1; map<string, InnerStrMap> ext2= 2; repeated uint32 keys = 3; };
赋值代码:
2.pb to C++
标签:map,C++,pb,ext,mutable,message,数据结构 From: https://www.cnblogs.com/BlueBlueSea/p/18134638