1.protobuf的github地址
https://github.com/protocolbuffers/protobuf
去releases下载需要的版本
https://github.com/protocolbuffers/protobuf/releases
选择2.5.0的版本
https://github.com/protocolbuffers/protobuf/releases/tag/v2.5.0
下载
wget https://github.com/protocolbuffers/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.gz
编译安装
./autogen.sh ./configure make make check sudo make install
安装完毕,查看版本
protoc --version libprotoc 2.5.0
参考google的javatutorial
https://developers.google.com/protocol-buffers/docs/javatutorial
pb的数据类型如下
https://developers.google.com/protocol-buffers/docs/proto
下载文件addressbook.proto
https://github.com/protocolbuffers/protobuf/blob/v2.5.0/examples/addressbook.proto
编译成java代码
protoc -I=./ --java_out=./ ./addressbook.proto # protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto 或者 protoc --java_out=. addressbook.proto
生成文件
tree -L 4 . ├── addressbook.proto └── com └── example └── tutorial └── AddressBookProtos.java