首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Google Protocol Buffer中使用std::map<int、std::string>

在Google Protocol Buffer中使用std::map<int、std::string>
EN

Stack Overflow用户
提问于 2013-07-14 18:54:32
回答 1查看 2K关注 0票数 0

我想知道是否有可能使用带有google协议缓冲区的地图。目前在我的.proto文件中有类似这样的内容

代码语言:javascript
复制
message MsgA
{
required string symbol = 1 ;
optional int32  freq = 2   [default = 0]; 
}

message MsgB
{

   //What should I do to make a map<int,MsgA>
}

我的问题是,在MsgB中,我想创建一个类型,它将是一个映射::有什么建议可以实现这一点吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-14 18:58:51

执行以下操作:

代码语言:javascript
复制
message MapEntry
{
    required int32 mapKey  = 1;
    required MsgA mapValue = 2;
}

message MsgB
{
    repeated MapEntry = 1;
}

您必须编写自己的代码将地图与MsgB相互转换,但这基本上应该是微不足道的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17638764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档