1、proto2 extension
proto2 extensions 官网指导说明:
https://developers.google.com/protocol-buffers/docs/proto#extensions
定义:
https://github.com/golang/protobuf/blob/4846b58453b3708320bdb524f25cc5a1d9cda4d4/internal/testprotos/proto2_proto/test.proto#L266
使用方法:
https://github.com/golang/protobuf/blob/master/proto/extensions_test.go
本文重点说明proto3,但proto3也是在proto2的基础上展开的,在理解以上链接内容可以继续向下阅读。
2、proto3 option
proto3 不支持extension,只支持option, option传值设置:
https://developers.google.com/protocol-buffers/docs/proto3#options
具体option可以分为:
FileOptions
MessageOptions
FieldOptions
OneofOptions
EnumOptions
EnumValueOptions
ServiceOptions
MethodOptions
UninterpretedOption
其字段定义见:
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto
官网也有对应使用测试:
https://github.com/protocolbuffers/protobuf/blob/master/csharp/protos/unittest_custom_options_proto3.proto
3、go代码 处理proto3 option值
test.proto:
syntax = "proto3";
import "google/protobuf/descriptor.proto";
import "google/protobuf/any.proto";
extend google.protobuf.FileOptions {
uint64 file_opt1 &