- 定义.proto文件
HeaderProto.proto
syntax = "proto3"; package xxx.yyy; message HeaderProto { }
VLMProto.proto
syntax = "proto3"; package xxx.yyy; import "HeaderProto.proto"; message VLMItemProto { } message VLMProto { com.lotus.biz.bean.HeaderProto headerProto = 1; int32 from = 2; repeated VLMItemProto vlmItemProtos = 3; }
- 安装protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protoc-3.11.2-linux-x86_64.zip sudo 7z x protoc-3.11.2-linux-x86_64.zip -o/usr/local
- 根据开发语言,选择生成的目标文件类型,以go为例
go get -u github.com/golang/protobuf/protoc-gen-go
- 生成go文件
protoc --go_out=. --go_opt=MHeaderProto.proto=./protobean HeaderProto.proto protoc --go_out=. --go_opt=MVLMProto.proto=./protobean --go_opt=MHeaderProto.proto=./protobean VLMProto.proto
当前生成的proto文件中如果有依赖其他proto,需要通过--go_opt 指定其生成的package名称