News article: Google launches Protocol Buffers: competing for the Internet Data Format

Source: Internet
Author: User
Tags ruby on rails
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 download

    Original article address: Google launches Protocol Buffers: competing for the data format in the Network Age

  • Related Article

    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.