Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the way the Erik Bergstedt toollibrary simplifies the use of Protobuf in .NET?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Erik Bergstedt tool library to simplify the way to use Protobuf in .NET, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, hope you can gain something.

Protobuf is an encoding format created by Google, and its official name is Protocol Buffers. This is a compact binary format that sacrifices the readability and extensibility of the content in exchange for less space and better performance. In order to deserialize a Protobuf message, the client and server must agree on specific fields in the message in advance. (contrary to the XML or JSON format, the client can analyze the message structure of the latter at run time. )

The. Net version of the Protobuf implementation takes advantage of the custom attribute of the property, setting a "id" value for each property. These attribute will be used to build binary arrays containing Protobuf messages. Here is an example of an application of Protobuf:

[ProtoContract] class Address {[ProtoMember (1)] public string Line1 {get; set;} [ProtoMember (2)] public string Line2 {get; set;}}

The way to use Protobuf in C # is a bit cumbersome because developers need stream to operate. By using the Protobuffer library developed by Erik Bergstedt, serialization or deserialization can be done with just one line of code.

Var serialize = _ simpleSerializer.ToByteArray (GetPerson ()); Person deserialize = _ simpleDeserializer.FromByteArray (serialize)

Developers may wonder why not add these API directly to the Protobuf project. Erik wrote in response:

Because the API of this library is written dead, it hides some functionality, which may not be appropriate for some scenarios. It sacrifices some features in exchange for simplicity.

For example, the way streams are created in this library is written to death, and the support for GZIP is beyond the scope of the original protobuf.

We need to be careful to distinguish between features and feature expansion. If you add the functionality of this library to the original protobuf project, I would think that it is not a feature, but a feature inflation.

Protobuffer is an open source software based on the MIT protocol. The Protobuf tool itself is developed by Google and supports a variety of platforms and programming languages, including C++, Java, JavaScript, Python, Ruby and so on.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report