Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf-net documentation or alternatives

Protobuf-net seems to be the fastest and for high-performence needs most recommended serialization library for .NET. I really want to use it, as I need to send hundreds of thousands of objects over the wire.

However, I'm having trouble getting started. The documentation (wiki at github) is quite sparse, especially for v2.

Somehow, you guys out there seem to be able to get going with the lib. How? By reading the sources? Trial and error? Or are there some API-docs / tutorials I'm not aware of? (I'm only aware of the GitHib page.)

Thanks and cheers,

Jan

P.S.: I need to get going using the RuntimeTypeModel (POCO's without attributes).

like image 841
Knack Avatar asked Sep 15 '13 19:09

Knack


People also ask

What is Protobuf net?

protobuf-net is a contract based serializer for . NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google. The API, however, is very different to Google's, and follows typical .

What is Protobuf c#?

Protobuf is used to serialize data structure efficiently. It is faster, smaller & simpler than XML. Protobuf is useful in developing programs to communicate with each other over a wire and it is created by Google. It helps us in creating gRPC services.


1 Answers

Since you've also asked about alternatives...

No need for attribute decoration was one of the reasons behind creating Migrant, fast serialization library with simple API. The library has some ideas that are also present in protobuf (so we are more or less on par in terms of speed and size), but at the same time tries to solve different problems. Among features distinctive from protobuf, there is a difference between empty and null collection and whole serialization is reference based for references and value based for values (well, you can also treat reference as a special kind of value). README at github should be able to answer most of your questions; whether some more detailed info is needed, just ask.

Simple scenario of custom object serialization:

var stream = new MyCustomStream();
var myComplexObject = new MyComplexType(complexParameters);
var serializer = new Serializer();

serializer.Serialize(myComplexObject, stream);

stream.Seek(0, SeekOrigin.Begin);

var myDeserializedObject = serializer.Deserialize<MyComplexType>(stream);

Note that expected type in Deserialize is only used to have nice compile-time type of the deserialized object, you can use general object as well.

Disclaimer: I'm one of the developers.

like image 125
konrad.kruczynski Avatar answered Sep 28 '22 18:09

konrad.kruczynski