C # Protobuf-Net serialization
Source code location: protobuf-net
1. Install Nuget:
Tools-expansion manager
After the installation is complete, restart Microsoft Visual Studio 2010. You can see:
Note:
The following two items are displayed only when the project has been opened for the solution:
2. Install protobuf_net (locate protobuf-net in Nuget, install it, and select the project)
3. encapsulate the simple operation class (introduce using ProtoBuf in the project; you can use it directly)
////// Protobuf_net ///Public class ProtobufSerializer {////// Serialization //////
//////
Public static string Serialize
(T) {using (MemoryStream MS = new MemoryStream () {Serializer. Serialize
(Ms, t); return Encoding. UTF8.GetString (ms. ToArray ());}}///
/// Deserialization //////
///
///
Public static T DeSerialize
(String content) {using (MemoryStream MS = new MemoryStream (Encoding. UTF8.GetBytes (content) {T t = Serializer. Deserialize
(MS); return t ;}}}
Note:
Reference:
Serialize Protobuf-Net, get started
Eight Methods to Improve the Performance of ASP. NET Web APIs
Compared with XML and binary serialization methods, Protobuf is more efficient and supports a large amount of data.
The serialized size of protobuf is 1/10 of the json, 1/20 of the xml format, and 1/10 of the binary serialization.