【问题标题】:How does proto3 set the value of the map typeproto3如何设置map类型的值
【发布时间】:2021-03-23 02:28:39
【问题描述】:

如何在静态代码中设置地图类型的值? 我有这样的地图结构。

message HelloRequest {
  Maps   maps = 1;
}
message Maps {
  map<string, AudioChannelCountMapBitrateOptions> formatMapChannelCount = 1;
}

message AudioChannelCountMapBitrateOptions{
  map<string, StringVec> bitrateMap = 1;
}

message StringVec{
  repeated string strings = 1;
}

生成pb文件后,如何使用? StringVec 提供了 set 方法和 get 方法,因此可以像这样获取和设置 strings 字段。

const strVec = new messages.StringVec();
strVec.setStringsList(['1', '2']);
console.log(strVec.getStringsList());

但 Maps 和 AudioChannelCountMapBitrateOptions 只提供 get 方法,如 getFormatmapchannelcountMap、getBitratemapMap。 如何设置这个map结构的值,才能得到一个完整的map数据结构。 像这样的地图数据结构?对吧?

formatMapChannelCount : {
  bitrateMap : ['1','2','3']
}

如果您觉得我的描述不清楚,请向我提问。

【问题讨论】:

    标签: node.js protocol-buffers grpc grpc-node


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-07
      • 2018-10-08
      • 2021-12-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多