Protobuf3 为什么不允许重复映射?
Protobuf3 why repeated map is not allowed?
我正在使用 Protobuf3,我需要创建一个地图列表。
我以为我可以使用 repeated map<string, string>
但似乎我不能。
我应该改用什么?
谢谢
本质上,map<...>
等同于:
repeated TypedPair ...
和
message TypedPair {
KeyType key = 1;
ValueType value = 2;
}
所以 repeated map<...>
将是 repeated repeated TypedPair
,这没有意义。
相反,定义一个 具有 映射的类型,并使用它:
message HazMap {
map<...> map = 1;
}
...
repeated HazMap maps = 1;
这可以隐含吗?也许 - 但现在不是。
我正在使用 Protobuf3,我需要创建一个地图列表。
我以为我可以使用 repeated map<string, string>
但似乎我不能。
我应该改用什么?
谢谢
本质上,map<...>
等同于:
repeated TypedPair ...
和
message TypedPair {
KeyType key = 1;
ValueType value = 2;
}
所以 repeated map<...>
将是 repeated repeated TypedPair
,这没有意义。
相反,定义一个 具有 映射的类型,并使用它:
message HazMap {
map<...> map = 1;
}
...
repeated HazMap maps = 1;
这可以隐含吗?也许 - 但现在不是。