protocol buffers, protobuf
protocol buffers, protobuf install protoc # archlinux 可以从仓库直接安装 pacman -S protobuf # 其它发行版, 比如 ubuntu 可以下载二进制包 解压即可. https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip # set protoc to PATH protoc -help windows download protoc https://developers.google.com/protocol-buffers/docs/downloads define message format in a .proto file syntax = "proto3"; message SearchRequest { string query = 1; int32 page_number = 2; int32 results_per_page = 3; } syntax = "proto3"; package package0; option java_package = "com.wiloon.test.protobuf.package0"; message Msg0 { // comments0 string foo = 1; ObjType enum0 = 2; uint64 timestamp = 5; int32 type = 6; //类型 enum ObjType { type0 = 0; type1 = 1; } } generate java/golang code export SRC_DIR=/pathToSrcDir export DST_DIR=$SRC_DIR golang # 安装 protoc-gen-go # install protocol buffers plugin # go: module github.com/golang/protobuf is deprecated: Use the "google.golang.org/protobuf" module instead. # 废弃,deprecated go get -u github.com/golang/protobuf/protoc-gen-go # 建议用这个 go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26 # 或 go install google.golang.org/protobuf/cmd/protoc-gen-go@latest # generate golang code protoc -I=$SRC_DIR --go_out=$DST_DIR $SRC_DIR/proto0.proto protoc --proto_path=$SRC_DIR --go_out=$DST_DIR --go_opt=paths=source_relative $SRC_DIR/foo.proto # -I, --proto_path: .proto 文件目录 # --go_out: 输出目录 java Java 工程建议使用下面的 protobuf-maven-plugin 方式 ...