C # Protobuf-Net serialization

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.