On July 22, July 8, Beijing time, according to foreign media reports, Google released the internal use of the company on Monday.Source codeThe data description language protocol buffers. Protocol buffers is similar to XML, but it is simpler, smaller, and faster.
Google open sourceCodeChris DiBona, Project Manager, wrote in a blog post: "Almost all structured information we transmit over the network or store on disks uses this language. We think protocol buffers may be useful to other people, so we decided to release it as open source software ."
Google software engineer Kenton Varda posted on the company's open source blogArticleGoogle uses thousands of different data formats, most of which are structured data formats. XML is not capable of coding these massive structured data. Google developed protocol buffers.
Valda compares protocol buffers to an interface description language without the complexity of the Interface Description Language. He said that one of the main design goals of protocol buffers is conciseness. Parse protocol buffers quickly, at least one order of magnitude faster than XML.
Google Documents said that the size of the Protocol buffers file is 3-10 times smaller than that of comparable XML files, and the resolution speed is 20-times faster.
Free files released by Google include Java, Python, and C ++Programming LanguageSource code of the Protocol buffers compiler.
Google said in a document that the company plans to release many other software projects as open-source software. Because these projects will use protocol buffers, Google decided to first release it as open source software.
In the Web 2.0 era, XML format has sprung up due to the popularity of Ajax and the popularity of RSS. However, with the popularity of Python and Ruby on Rails and the release of various APIs, yaml and JSON have become famous. Google released protocol buffers to allow programmers to easily use Google's data transmission format.
What is protocol buffers?
This is a piece of code on the Protocol buffers homepage:
Message person {
Required string name = 1;
Required int32 id = 2;
Optional string email = 3;
Enum phonetype {
Mobile = 0;
Home = 1;
Work = 2;
} Message phonenumber {
Required string number = 1;
Optional phonetype type = 2 [default = Home];
}
Repeated phonenumber phone = 4;
}
The role of protocol buffers is to automatically generate Java, Python, and C ++ code for the Data Types in the preceding format, then the following code can be called directly: (C ++)
Person;
Person. set_name ("John Doe ");
Person. set_id (1234 );
Person. set_email ("jdoe@example.com ");
Fstream output ("myfile", IOS: Out | IOs: Binary );
Person. serializreceivstream (& output); fstream input ("myfile", IOS: In | IOs: Binary );
Person;
Person. parsefromistream (& input );
Cout <"name:" <person. Name () <Endl;
Cout <"E-mail:" <person. Email () <Endl;
I believe that all c ++ programmers are tired of defining functions such as set and get. What Google does is to help you save the trouble and construct a data structure that is more conducive to network transmission.
Comparison with XML
Simpler
3 to 10 times smaller than XML
20 to 100 times faster than XML
Not easy to cause ambiguity
Automatically generate programmable class code
Comparison:
Cout <"name:" <person. Name () <Endl;Cout <"E-mail:" <person. Email () <Endl;
Cout <"name :"
<Person. getelementsbytagname ("name")-> item (0)-> innertext ()
<Endl;
Cout <"E-mail :"
<Person. getelementsbytagname ("email")-> item (0)-> innertext ()
<Endl; disadvantage
No layers, so you cannot deal with HTML Markup Language
Without the definition of message, you cannot understand the meaning of message, while XML is self-explanatory.
Protocol buffer homepage protocol buffer download