How vtprotobuf works with protoc
mainvtprotobuf is an auxiliary plugin that must be run alongside the upstream protoc-gen-go generator. It does not replace it; instead, it generates fully-compatible auxiliary code (files ending in _vtproto.pb.go) to speed up serialization and deserialization without using reflection.
Requirements:
- Your project must use the ProtoBuf v2 API (
google.golang.org/protobuf). It is not compatible with APIv1 generated code. - You must pass the desired features via the
--go-vtproto_optflag during compilation.
# Example protoc invocation
protoc \
--go_out=. --plugin protoc-gen-go="${GOBIN}/protoc-gen-go" \
--go-grpc_out=. --plugin protoc-gen-go-grpc="${GOBIN}/protoc-gen-go-grpc" \
--go-vtproto_out=. --plugin protoc-gen-go-vtproto="${GOBIN}/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=marshal+unmarshal+size \
proto/your_file.proto