C# .net protocol buffers - protobuf-net support for serializing dictionary of object values?

纵然是瞬间 提交于 2019-12-05 04:29:40

A Dictionary<int,SomeClass> is perfectly serailizable with protobuf-net. Protobuf-net works simplest when working code-first, so: *just have a Dictionary<int,SomeClass> in your model. You are not required to use a .proto at all - that is provided mainly for cross-platform purposes. The .proto specification has no concept of a dictionary, but if you are required to use a .proto schema, then this is serialized as:

message KeyValuePairInt32SomeClass {
    required int32 Key = 1;
    required SomeClass Value = 2;
}

with the dictionary as

repeated KeyValuePairInt32SomeClass YourDictionary = [n]; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!