1、开源地址:
https://github.com/google/protobuf/
2、发布版本下载:
https://github.com/google/protobuf/releases
3、什么是Protobuf
3、数据类型
.proto
Type |
Notes | C++ Type | Java Type |
double | double | double | |
float | float | float | |
int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int |
int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long |
uint32 | Uses variable-length encoding. | uint32 | int |
uint64 | Uses variable-length encoding. | uint64 | long |
sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int |
sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long |
fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 228. | uint32 | int |
fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 256. | uint64 | long |
sfixed32 | Always four bytes. | int32 | int |
sfixed64 | Always eight bytes. | int64 | long |
bool | bool | boolean | |
string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String |
bytes | May contain any arbitrary sequence of bytes. | string | ByteString |
5、Protobuf的优点
1、性能好,效率高
6、Protobuf的缺点
1、应用不够广
2、二进制格式导致可读性差(二进制格式)
3、缺乏自描述
7、Protobuf环境的搭建
根据不同操作系统下载不同的发布版本
https://github.com/google/protobuf/releases,
8、新建第一个proto文件
文件名为:ResponseMsg.proto
option java_package = "io.hpgary.netty.pb"; //生成java的包名 option java_outer_classname = "ResponseMsgProbuf"; // 生成java的类名 message ResponseMsg { required bytes response = 1; }
9、转换成为java类:
使用命令:
# ../java 是源代码所在目录 protoc.exe --java_out ../java ResponseMsg.proto
10、使用:
ByteString byteString = ByteString.copyFrom("aaa".getBytes()); RequestMsg.Builder requstMsg = RequestMsg.newBuilder(); requstMsg.setCmd("hp_call"); requstMsg.setRequestParam( byteString );
相关推荐
google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf ...
定义protobuf文件(包含enum,message,required,optional,repeated, 结构体定义中引用另一个结构体), 生成java文件,能够构建java对象,并转化为字节byte或者流,能够将流或字节转化为对象
适用于protobuf3协议规则转换为java文件的一个工具类,操作简便,谷歌下载不易。
服务器端与客户端通信,使用google protobuf作为交互数据的序列化工具,其中客户端使用select机制实现I/O复用,服务端使用epoll机制,提高并发连接时的处理效率。软件环境:linux。文件dealpack.cc是服务端和客户端...
Google ProtoBuf 安装使用说明
windows下vs环境对protobuf的简单应用,所用vs版本2010,protobuf版本protobuf-2.5.0
使用protobuf的Description技术,实现protobuf结构体与json语言之间的黑盒转换.
google protobuf的简单实用方法,主要用于向他人介绍。 可以用于数据传输和单元测试中 google protobuf的简单实用方法,主要用于向他人介绍。 可以用于数据传输和单元测试中
ros2使用自建类型编译,订阅以及发布的demo,并且包括和protobuf互转的使用方式. 自建类型为序列化数据{uint32 size, uint8 data[] }
google protobuf库文件,编译方法,及使用 google protobuf学习笔记一:windows下环境配置
google protobuf对协议内容进行了编码和压缩,对协议安全很有意义
protobuf转换为json,原版中存在bug,使用时候修复了原版的bug
google protobuf-2.4.1
google protobuf C教程,主要实现将google protobuf移植到32位单片机的教程。
使用google protobuf通过TCP传输文件
ros2和protobuf, dds一同编译,并完成互转
google protobuf-3.2.0 protoc3.2.0.exe
google protobuf 2.6.0源文件可直接编译使用!!!!!!!!!!!!!!!!!!!!!
Protobuf工具 Google官方协议转换工具