Introduction to the

protobufWhat is?

Protocol buffers are Google’s language-neutral, platform-neutral, Extensible Mechanism for serializing structured data — think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.

  • GoogleA data description language developed by The Company
  • A language – independent, platform – independent, extensible mechanism for serializing structured data
  • throughprotoFiles define structured data, and other functions are similarXML,JSONAnd so on;
  • Built-in code generator

There are many frameworks out there that use Protocol Buffers. GRPC is also based on Protocol Buffers. Protocol Buffers are currently available in versions 2 and 3.

Proto3 is recommended for gRPC.

Why is it called”Protocol Buffers

The name originates from the early days of the format, before we had the protocol buffer compiler to generate classes for us. At the time, there was a class called ProtocolBuffer which actually acted as a buffer for an individual method. Users would add tag/value pairs to this buffer individually by calling methods like AddValue(tag, value). The raw bytes were stored in a buffer which could then be written out once the message had been constructed.

Since that time, the “buffers” part of the name has lost its meaning, but it is still the name we use. Today, people usually use the term “protocol message” to refer to a message in an abstract sense, “protocol buffer” to refer to a serialized copy of a message, and “protocol message object” to refer to an in-memory object representing the parsed message.

advantages

  • Support for multiple programming languages
  • Serialized data is small in size
  • Fast deserialization
  • Serialization and deserialization code are generated automatically

disadvantages

  • Poor readability and lack of self-description

“Abnormal” performance

A netizen has done a variety of common serialization protocol technology comparison, I directly here to give you a feel:

Specific parameters:

protobuf jackson xstream Serializable hessian2 Hessian2 compression hessian1
Serialization (unit)ns) 1154 5421 92406 10189 26794 100766 29027
Deserialization (in unitsns) 1334 8743 117329 64027 37871 188432 37596
bytes 97 311 664 824 374 283 495

ProtobufThe installation

  • protocSource code and pre-compiled packages for each system

  • Select the corresponding installation file to download, unpack (win10) (Tips: The best path to decompress the file is In English, without any special characters, including Spaces)

  • Setting environment VariablesPathaddbinDirectory (win10)

  • Check whether the installation is successful (win10)