Google protobuf is great protocol to serialize objects efficient, but it only supports serialization of trees, not graphs (lack of full Object Reference Tracking).
There are few implementation of Google idea in .NET. (i.e. protobuf-csharp-port, or protosharp), but most interesting is protobuf-net.
Protobuf-net is better because its architecture fits, to .NET world, and has several add-ins (not always compatible with original protobuf, but very useful).
One of that add-in is possibility to turn on reference tracking (AsReference option), which allows to serialize complex graphs even with cycles.
Unnecessary Protobuf-net v2 is in beta version, and AsReference option not works at real world scenarios. (without this option everything works well, but without Reference Tracikng protobuf-net is not able to serialize graphs and is not longer attractive serializer).
It still have some bugs:
So, I can't use this great tool, and I'm looking for alternative serializer which:
Bartosz, while this question is quite old, I might recommend you and whoever stumbles upon it to use Migrant, available both from source and NuGet package. I'm one of the co-authors.
It can be easily adopted to even complicated scenarios, we tried to make it as easy to use as possible.
The output size is reasonably small. It depends on your object tree, of course, but it can be comparable with protobuf-net. Like protobuf, it uses Varint and ZigZag encoding.
Of course Migrant resolves the problems you've mentioned - It keeps the whole graphs of objects, handles inheritance, complex collections, version tolerance (up to some point) etc.
In terms of speed we try to be comparable with protobuf-net. It supports de/serialization using dynamically generated methods, which is much faster then classical reflection-based solutions.
Simple usage scenarios are available on the site I've linked to, but simple object cloning is straight-forward.
var myComplexObject = new MyComplexType(complexParameters);
var myObjectCopy = serializer.DeepClone(myComplexObject);
Writing to stream is as easy.
Of course, for very complicated types, there is a set of class decorators (attributes, hooks) to make things even smarter ;-)
We are considering MessagePack. They claim to be 4x faster than ProtoBuf. However I don't know if it supports full object graphs. (we don't have that requirement, we actually flatten the objects we use for communication) In my scenario I would use it for communication between a .Net and a delphi layer (and that's also what's holding me back, no delphi support :) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With