美文网首页
linux 安装protobuf

linux 安装protobuf

作者: 鱼小莘 | 来源:发表于2020-03-23 13:41 被阅读0次
1、根据protobuf GitHub的README.md安装protoBuf

(1)安装依赖工具

sudo apt-get install autoconf automake libtool curl make g++ unzip

(2)在protobuf github上获取版本信息及源码链接,用wget下载:

wget  https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protobuf-cpp-3.7.1.tar.gz

(3)解压

tar -xzvf protobuf-cpp-3.7.1.tar.gz
image.png

(4)根据官网安装教程依次执行

cd protobuf-3.7.1
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig

成功安装


image.png
2、定义proto文件,以student.proto为例
image.png
3、编译student.proto
protoc student.proto --cpp_out=./
image.png
4、protoc会根据定义的proto文件生成相应的API,对于student.id有

inline bool has_id() const;
inline void clear_id();
static const int kIdFieldNumber = 1;
inline google::protobuf::uint64 id() const;
inline void set_id(google::protobuf::uint64 value);

5、除了字段的API,protoc还会生成标准消息函数

bool IsInitialized() const; //检查是否全部的required字段都被置(set)了值
void CopyFrom(const Person& from); //用外部消息的值,覆写调用者消息内部的值
void Clear(); //将所有项复位到空状态
int ByteSize() const; //消息字节大小
string DebugString() const; //将消息内容以可读的方式输出
string ShortDebugString() const; //输出时会有较少的空白
bool SerializeToString(string* output) const; //将消息序列化并储存在指定的string中
bool ParseFromString(const string& data); //从给定的string解析消息
bool SerializeToArray(void * data, int size) const //将消息序列化至数组
bool ParseFromArray(const void * data, int size) //从数组解析消息
bool SerializeToOstream(ostream* output) const; //将消息写入到给定的C++ ostream中
bool ParseFromIstream(istream* input); //从给定的C++ istream解析消息

相关文章

  • Protobuf安装|编译|使用

    1.linux安装Protobuf Linux编译安装protocal-3.6.1https://github.c...

  • protobuf编译安装

    准备知识 protobuf简介 protobuf官方编译说明 编译安装 Linux下直接按照官方文档操作即可 Ma...

  • linux 安装protobuf

    1、根据protobuf GitHub的README.md安装protoBuf (1)安装依赖工具 (2)在pr...

  • linux下源码编译protobuf

    linux下使用ProtoBuf, 有如下几种安装方式。configure方式源码编译安装,发现使用的时候cmak...

  • mac上安装Protobuf

    为什么要安装protobuf 什么是protobuf 怎么判断有没有安装过protobuf? 安装protobuf...

  • iOS开发环境搭建

    一、安装cocoapods 安装cocoapods 二、安装protobuf 安装protobuf使用方式:pro...

  • gRPC之python

    安装 安装grpc 安装python grpc的protobuf的编译工具 安装protobuf的python依赖...

  • protobuf使用

    protobuf的使用 protobuf .proto文件 idea安装protobuf插件 syntax = ...

  • Ubuntu16.04安装protobuf 2.6.1

    Ubuntu上安装protobuf 和protobuf-c 1、下载安装包protobuf-2.6.1,解压 2、...

  • iOS Protobuf快速集成

    安装Protobuf 使用命令 brew install protobuf 安装前可能需要先安装autoconf和...

网友评论

      本文标题:linux 安装protobuf

      本文链接:https://www.haomeiwen.com/subject/bqhwyhtx.html