Document directory
- Google launches Protocol Buffers: competing for the Internet Data Format
Http://www.cnbeta.com/articles/59752.htmgooglepush protocol Buffers: compete for the Internet Data Format
Ugmbbc was released on 17:34:09 |
2159 read fonts: large and small print preview
Thank you for your delivery.
News source: Google Code
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;
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;
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 downloadOriginal article address: Google launches Protocol Buffers: competing for the data format in the Network Age