当前位置:主页 > 服务器 > Linux >

protobuf简单介绍和ubuntu 16.04环境下安装教程

时间:2021-01-27 10:41:44 | 栏目:Linux | 点击:

protobuf简单介绍

      protobuf是谷歌的开源序列化协议框架,结构类似于XML,JSON这种,显著的特点是二进制的,效率高,主要用于通信协议和数据存储等方面,算是一种结构化数据的表示方法。

protobuf的优点

protobuf的缺点

xml是自我描述的,但是protobuf格式不是的,给你一段二进制文件,你看不出来作用

protobuf使用步骤

比如定义一个结构化数据person,包含name和email属性

xml中这样定义

<person>
 <name>zhangsan</name>
 <email>zhangsan@qq.com</email>
<person>

protobuf这样定义

person{
 name:"zhangsan"
 email:"zhangsan@qq.com"
}

json中这样定义

{
 "person":{
  "name":"zhangsan",
  "email":"zhangsan@qq.com"
 }
}

protobuf的语法

Message定义 

  一个message类型定义一个请求或相应的消息格式,可以包含多种类型

Service服务 

  如果需要将消息类型用在rpc上面,那就需要在.proto文件定义一个rpc服务接口,protocol buffer编译器会根据所选择的不同语言生成服务接口代码。

protobuf在ubuntu 下安装 【版本16.04】

  官方地址:https://github.com/google/protobuf/blob/master/src/README.md

安装命令行如下:

$ 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.

make之后的截图

宛十八微服务

中途编译一路顺风,没有遇到什么问题,下面查看下版本吧

$ protoc --version12

宛十八微服务

总结

您可能感兴趣的文章:

相关文章