为什么google protobuf不支持map的序列化和反序列化

为什么google protobuf不支持map的序列化和反序列化
最新回答
寒岛春信

2022-08-07 13:41:33

现在它是支持的。
proto2的文档就已经提到了Maps(Language Guide),但我用protoc2.6编译的时候,map关键字无法通过编译,protoc3.0编译正常,proto举例:

message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;
map<string, string> values= 4;
}

另外,
官方文档(
https://developers.google.com/protocol-buffers/docs/proto#Maps
)说了:

The map syntax is equivalent to the following on the wire, so protocol buffers implementations that do not support maps can still handle your data:
message MapFieldEntry {
key_type key = 1;
value_type value = 2;
}

repeated MapFieldEntry map_field = N;