protobuf
来源:互联网 发布:数据库的逻辑设计例题 编辑:程序博客网 时间:2024/05/18 01:30
本文使用版本: protobuf-2.4.1.tar.bz2
1. 解压 tar jxvf protobuf-2.4.1.tar.bz2
2. 进入解压后的目录, ./configure –prefix=/yourdirpath/output
make && make install
3. 使用
a. 定义proto文件
b. 生成proto对应的代码文件
./output/bin/protoc ./demo.proto --cpp_out=./
会在当前路径下生成, demo.pb.h demo.pb.cc
c. 写自己的hello.cpp
d. 编译
g++ hello.cpp demo.pb.cc -o ./test -I./include ./lib/libprotobuf.a -lpthread
4. 另外probuf数据提供多种序列化接口
a. C数组的序列化和反序列化API
bool ParseFromArray(const void* data, int size);
bool SerializeToArray(void* data, int size) const;
b.C++ String的序列化和反序列化API
bool SerializeToString(string* output) const;
bool ParseFromString(const string& data);
c. 文件描述符序列化和反序列化API
bool SerializeToFileDescriptor(int file_descriptor) const;
bool ParseFromFileDescriptor(int file_descriptor);
d. C++ stream 序列化和反序列化API
bool SerializeToOstream(ostream* output) const
bool ParseFromIstream(istream* input);
- protobuf
- ProtoBuf
- protobuf
- protobuf
- protobuf
- Protobuf
- protobuf
- Protobuf
- protobuf
- protobuf
- protobuf
- protobuf
- protobuf
- protobuf
- ProtoBuf
- 【Protobuf】
- 【Protobuf】
- protobuf
- android 内核
- C语言中static的作用
- WWDC 2014 Session笔记 - iOS 通知中心扩展制作入门
- catch中的直接映射
- Perl中的变量和数组
- protobuf
- Linux笔记
- 通过一张图初步了解DNS
- 使用perl的expect对linux下使用fdi…
- leetcode-ZigZag Conversion
- Hadoop入门
- Windows下opencl环境配置
- 小白学c++之模板的使用
- 网站开发之二级选项卡制作记录