A brief introduction to protobuf and installation tutorial in Ubuntu 16.04 environment

A brief introduction to protobuf and installation tutorial in Ubuntu 16.04 environment

A brief introduction to protobuf

Protobuf is Google's open source serialization protocol framework, which has a structure similar to XML and JSON. Its notable features are binary and high efficiency. It is mainly used in communication protocols and data storage, and is considered a method of representing structured data.

Advantages of protobuf

  • Everyone is using it, at least the "pretentious" ones are using it [We have to keep up with the times]
  • Others say that the performance is good, binary format [big projects don't use this, it feels shameful]
  • Cross-platform support for various languages, backward and forward compatibility is very powerful [after all, Google is using it]

Disadvantages of protobuf

  • Binary format, ordinary people can't read it
  • Lack of self-description

XML is self-describing, but protobuf format is not. If you are given a binary file, you cannot tell what it does.

Protobuf usage steps

  • Define your own data structure format (.pro) source file
  • Compile the source file using the compiler provided by protobuf
  • Use protobuf go's api to read and write information

For example, define a structured data person, including name and email attributes

Defined in xml

<person>
 <name>zhangsan</name>
 <email>[email protected]</email>
<person>

protobuf defines this

person{
 name:"zhangsan"
 email:"[email protected]"
}

This is defined in json

{
 "person":{
  "name":"zhangsan",
  "email":"[email protected]"
 }
}

Syntax of protobuf

Message definition

A message type defines a request or response message format and can contain multiple types.

Service

If you need to use the message type on RPC, you need to define an RPC service interface in the .proto file. The protocol buffer compiler will generate service interface code based on the selected language.

Protobuf is installed in Ubuntu [version 16.04]

Official address: https://github.com/google/protobuf/blob/master/src/README.md

The installation command line is as follows:

$ sudo apt-get install autoconf automake libtool curl make g++ unzip
$ git clone https://github.com/google/protobuf.git
$ cd protobuf
$ git submodule update --init --recursive
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.

Screenshot after make

宛十八微服務

The compilation went smoothly without any problems. Let's check the version below.

$ protoc --version12

宛十八微服務

Summarize

The above is a brief introduction to protobuf and the installation tutorial in Ubuntu 16.04 environment. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed tutorial on installing Protobuf 3 on Ubuntu

<<:  Detailed explanation of the configuration method of MySQL master-slave replication read-write separation

>>:  Detailed explanation of common usage methods of weixin-js-sdk in vue

Recommend

Details on using JS array methods some, every and find

Table of contents 1. some 2. every 3. find 1. som...

VMware workstation 12 install Ubuntu 14.04 (64 bit)

1. Installation Environment Computer model: Lenov...

How to realize vertical arrangement of text using CSS3

In a recent project, I wanted to align text verti...

JavaScript to achieve the idea of ​​​​snake game

The implementation idea of ​​the javascript game ...

How to use @media in mobile adaptive styles

General mobile phone style: @media all and (orien...

Pay attention to the use of HTML tags in web page creation

This article introduces some issues about HTML ta...

Summary of experience in using div box model

Calculation of the box model <br />Margin + ...

How to deploy SpringBoot project using Dockerfile

1. Create a SpringBooot project and package it in...

js implements a simple shopping cart module

This article example shares the specific code of ...

React useMemo and useCallback usage scenarios

Table of contents useMemo useCallback useMemo We ...

vitrualBox+ubuntu16.04 install python3.6 latest tutorial and detailed steps

Because I need to use Ubuntu+Python 3.6 version t...

Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Today I wanted to change the mysql port, but I fo...