C# .net protocol buffers - protobuf-net support for serializing dictionary of object values? -
i'm new protocol buffers , using protobuf-net vs2010. i'm reading here dictionary in protocol buffers, doesn't seem protobuf can serialize dictionary object types values. here on site read this:
notes on types
supported:
custom classes that: marked data-contract have parameterless constructor silverlight: public many common primitives etc single dimension arrays: t[] list / ilist dictionary / idictionary type implements ienumerable , has add(t) method code assumes types mutable around elected members. accordingly, custom structs not supported, since should immutable.
which seems supported.
i can compile list of objects so:
message valuesobject { optional int32 someval = 1; repeated someclass listofsomeclasstypes = 2; } this works fine list<someclass>. why cannot serialize using protobuf-net dictionary<int, someclass>? message serialize dictionary<int, someclass>?
a dictionary<int,someclass> serailizable protobuf-net. protobuf-net works simplest when working code-first, so: *just have dictionary<int,someclass> in model. not required use .proto at all - provided cross-platform purposes. .proto specification has no concept of dictionary, if are required use .proto schema, serialized as:
message keyvaluepairint32someclass { required int32 key = 1; required someclass value = 2; } with dictionary as
repeated keyvaluepairint32someclass yourdictionary = [n];
Comments
Post a Comment