Google Data Communication Protocol protocol buffers

Source: Internet
Author: User

Protocol buffers: An extensible way to serialize structured data, language neutrality, platform neutrality, and data protocols for communication protocols, data storage, and much more, think of Xml,json, but smaller, simpler and faster than XML.

Protocol buffers is a flexible and efficient automated mechanism for serializing structured data. All you need to do is define how you want the data to be organized, and then you can use the specially generated source code to easily read and write to a wide variety of data streams using a variety of languages. You can even update your data structure without destroying deployed programs that are compiled in an "old" format.

Common techniques for serializing objects across process/machine boundaries are: Local serialization, serialization of objects using a local implementation of a language such as java,c++, and so on. Serializing the data into XML with a custom serialization format

Each of these scenarios has its own problems, such as local serialization, which means that the end of the serialized pipeline must be the same platform to ensure that the serialized object is materialized, and that XML is considered a lengthy and inefficient serialization format. The custom serialization format increases the cost of developing a one-time parser.

The goal of Protocol buffers is a flexible, efficient and automated solution to this problem. Using protocol buffers, you write a. Proto description file for the data structure you need to store. The Protocol buffer compiler creates a class that implements automatic encoding and analyzes Protocol buffer data in an efficient binary format. The generated class provides getter and setter for fields that compose protocol buffer, and handles the details of reading and writing this protocol buffer as a unit. More importantly, protocol The buffer format supports the concept of extending the format over time, in such a way that code can still read data encoded in the old format.

Protocol buffers supports the following basic data types that can be expressed in the object graph Basic 128 Varint representation-int32,int64,uint32,uint64,sint32,sint64,bool,enum ( Varints is a way to serialize integers using one or more bytes. A small number takes up a smaller byte. Fixed size 64-bit represents-fixed64,sfixed64,double fixed-size representation-string,bytes, embedding messages, packed repeating fields with fixed size 32-bit representations-fixed32,sfixed32,float

A serialization unit is a message that contains a field consisting of a base data type or an embedded message. Protocol buffers supports optional, required, and duplicate fields. An address book message that uses protocol buffers to define it might look like this

Package Tutorial;message Person {Required String name = 1; required Int32 id = 2; Optional string email = 3; enum phonety PE {MOBILE = 0; home = 1; WORK = 2; } message PhoneNumber {Required String number = 1; optional Phonetype type = 2 [default = home]; repeated PhoneNumber p Hone = 4;} Message AddressBook {repeated person person = 1;}

The characteristics of the message definition language are described in the language guide. When compiling using the protocol buffer compiler, encoders and parsers are generated in a proprietary, efficient serialization format. The current release includes compilers and APIs for C++,java and Pyhon. There are also community projects trying to add new language implementations to protocol buffers, including perl,c#, and Ruby. Advantages

1. Small size of language, support for a variety of data types, such as list, support nesting
2. The concept of a type can be used in the definition process to check the type legality when used
3. A description file can be generated to generate multiple language code, so that the data read and write to achieve language-independent.
4. If the description of the file is modified, as long as the following rules, the original data structure corresponding to the information can also be successfully read. Disadvantage

1. The serialized file is unreadable.
2. Do not transform with XML or JSON

Scene...

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.