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

Limit input type (multiple methods)

1. Only Chinese characters can be input and pasted...

Usage and best practice guide for watch in Vue3

Table of contents Preface🌟 1. API Introduction 2....

border-radius method to add rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

Summary of practical methods for JS beginners to process arrays

join() method: connects all elements in an array ...

Tutorial on setting up scheduled tasks to backup the Oracle database under Linux

1. Check the character set of the database The ch...

Tomcat configuration and how to start it in Eclipse

Table of contents How to install and configure To...

Resolving MySQL implicit conversion issues

1. Problem Description root@mysqldb 22:12: [xucl]...

jQuery implements the drop-down box for selecting the place of residence

The specific code for using jQuery to implement t...

Steps to enable MySQL database monitoring binlog

Preface We often need to do something based on so...

Detailed explanation of vue page state persistence

Table of contents Code: Replenish: Summarize Requ...