1.下载protoc压缩包并安装
https://github.com/protocolbuffers/protobuf/releases
2.命令
tar -zxvf protobuf
cd protobuf
./configure --prefix=/usr/local/protobuf
make
make check
make install
3.修改配置文件
vim ~/.bash_profile
#添加:
export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
#保存并执行
source ~/.bash_profile
4.检查安装状态
protoc --version
5.添加.proto格式文件
https://blog.youkuaiyun.com/wxj280306451/article/details/108102533
syntax = “proto3”;
//生成的文件路径
//option java_package = “com.bsit.qm702.mqtt”;
//生成的文件名称
option java_outer_classname = “Track”;
// 公交车轨迹数据
message msg {
string Termid = 1;
string Posid = 2;
string Samid = 3;
string INSTACP = 4;
string longitude = 5;
string latitude = 6;
string BusLine = 7;
string speed = 8;
string Plate = 9;
string check = 10;
string Time = 11;
string Direction = 12;
string BusDirection = 13;
string Elevation = 14;
}
6…proto格式编译成java
protoc PushPayload.proto --java_out=./
7…proto编译成.desc
-I是生成的desc路径
protoc -I=./ --descriptor_set_out=PushPayload.desc PushPayload.proto