Is it possible to use protobuf-net Serializer and at the same time the corresponding * .proto file?

I have a .NET type that does not bind to either ProtoContract or DataContract. In addition, not all of his condition must be proto-serialized. Can I define a .proto file for it, but at the same time use some Serializer to serialize it, as if it were attributed to ProtoContract?

Thanks.

+4
source share
1 answer

As the third option, you can use [XmlType] and [XmlElement(Order=n)] ... but I don’t think this is what you mean: p

In "v2" this is really possible. You do not need to define .proto - you can simply tell what to do at runtime, for example:

 var model = TypeModel.Create(); model.Add(typeof(SomeType)).Add("Foo", "Bar", "Blip"); 

now save the model somewhere (and reuse it) and use model.Serialize(...) and model.Deserialize(...) . The above SomeType configuration for serializing .Foo (as field 1), .Bar (as field 2) and .Blip (as field 3). Of course, there are many ways to do this for finer control.

It will generate (primarily) a serializer (using IL emit, so very fast) that will work with your types as expected.

There is a downloadable "v2" DLL, but it needs to be updated - in the last few weeks I have made many corrections. I will try to update this dll later today, or you can build from code.

+6
source

All Articles