From 60c7190853500ba35e783b9e279df5bbc819a557 Mon Sep 17 00:00:00 2001 From: leiiwang Date: Sun, 17 May 2020 15:54:15 +0800 Subject: [PATCH] add plugin annotation, which add a annotation of string for message type, which can be used like JAVA's runtime annotation. --- gogoproto/gogo.pb.go | 180 +++++++++++++------------ gogoproto/gogo.proto | 2 + gogoproto/helper.go | 5 + plugin/annotation/annotation.go | 41 ++++++ proto/extensions_gogo.go | 15 +++ proto/properties.go | 25 ++++ protoc-gen-gogo/generator/generator.go | 2 +- vanity/command/command.go | 1 + 8 files changed, 186 insertions(+), 85 deletions(-) create mode 100644 plugin/annotation/annotation.go diff --git a/gogoproto/gogo.pb.go b/gogoproto/gogo.pb.go index 1e91766aee..7cb748de14 100644 --- a/gogoproto/gogo.pb.go +++ b/gogoproto/gogo.pb.go @@ -597,6 +597,15 @@ var E_GoprotoUnkeyed = &proto.ExtensionDesc{ Filename: "gogo.proto", } +var E_Annotation = &proto.ExtensionDesc{ + ExtendedType: (*descriptor.MessageOptions)(nil), + ExtensionType: (*string)(nil), + Field: 64036, + Name: "gogoproto.annotation", + Tag: "bytes,64036,opt,name=annotation", + Filename: "gogo.proto", +} + var E_Nullable = &proto.ExtensionDesc{ ExtendedType: (*descriptor.FieldOptions)(nil), ExtensionType: (*bool)(nil), @@ -770,6 +779,7 @@ func init() { proto.RegisterExtension(E_Messagename) proto.RegisterExtension(E_GoprotoSizecache) proto.RegisterExtension(E_GoprotoUnkeyed) + proto.RegisterExtension(E_Annotation) proto.RegisterExtension(E_Nullable) proto.RegisterExtension(E_Embed) proto.RegisterExtension(E_Customtype) @@ -787,88 +797,90 @@ func init() { func init() { proto.RegisterFile("gogo.proto", fileDescriptor_592445b5231bc2b9) } var fileDescriptor_592445b5231bc2b9 = []byte{ - // 1328 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x98, 0x49, 0x6f, 0x1c, 0x45, - 0x14, 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x6c, - 0xd0, 0x93, 0xc5, 0x2d, 0x59, 0xe0, 0x97, 0x10, 0x1f, 0x20, 0x06, 0x15, 0xb1, 0x8c, 0xb3, 0xc0, - 0x51, 0x36, 0x3b, 0x78, 0x85, 0x14, 0xc4, 0xa0, 0xa2, 0x87, 0xb0, 0xbe, 0x4a, 0x8a, 0x54, 0x8b, - 0xe7, 0x0c, 0x1b, 0x90, 0x51, 0xb0, 0x21, 0x23, 0x9b, 0x4d, 0x5c, 0x46, 0x03, 0x43, 0x04, 0x04, - 0xd3, 0xac, 0x66, 0x9b, 0x88, 0x37, 0x36, 0xe9, 0x78, 0x50, 0x06, 0x16, 0xd8, 0x08, 0x15, 0x28, - 0x5f, 0x46, 0x16, 0x8a, 0x37, 0x51, 0x31, 0xac, 0x61, 0x78, 0x1b, 0x4a, 0xa4, 0xca, 0x13, 0x36, - 0x92, 0xb7, 0xe8, 0x36, 0x10, 0xc1, 0x50, 0x36, 0x45, 0xe4, 0xae, 0xd9, 0x19, 0xde, 0xa6, 0x50, - 0x12, 0x03, 0x8a, 0x39, 0x36, 0x14, 0x3a, 0x49, 0xba, 0xe6, 0x04, 0x56, 0xe9, 0x78, 0x07, 0x1d, - 0x83, 0x25, 0x84, 0x11, 0xc9, 0xa2, 0x5e, 0x34, 0xef, 0x52, 0x44, 0x34, 0x0c, 0x8f, 0x5e, 0xaa, - 0x9c, 0x66, 0x20, 0x1a, 0xbd, 0xd8, 0xde, 0xa3, 0xa3, 0x57, 0xb0, 0x8b, 0xba, 0x71, 0x9a, 0xd5, - 0x52, 0xff, 0x8c, 0x95, 0xe6, 0x7d, 0xca, 0x74, 0x0e, 0x00, 0x7c, 0x0f, 0xbb, 0xae, 0x6b, 0x9b, - 0xb0, 0x90, 0x7d, 0x80, 0xb2, 0x89, 0x2e, 0xad, 0x02, 0x4b, 0x42, 0xaf, 0xca, 0x0f, 0xa9, 0x24, - 0x88, 0x8a, 0x6b, 0x89, 0x8d, 0x67, 0x51, 0xea, 0xac, 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xf3, 0xd5, 0x5a, 0xd6, 0x9c, 0x74, 0x65, 0x38, 0x05, 0xbf, 0x3c, 0xda, 0x2f, 0x54, 0xcb, - 0xdf, 0x21, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xaf, 0x70, 0x4e, 0x83, 0x15, 0x00, 0x00, + // 1345 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x98, 0xc9, 0x6f, 0x1c, 0x45, + 0x17, 0xc0, 0xf5, 0xe9, 0x4b, 0x14, 0x4f, 0xd9, 0x8e, 0xe3, 0xb1, 0x31, 0x21, 0x02, 0x11, 0x38, + 0x71, 0xb2, 0x4f, 0x11, 0x4a, 0x59, 0x91, 0xe5, 0x58, 0x8e, 0x15, 0x84, 0x83, 0x71, 0xe2, 0xb0, + 0x1d, 0x46, 0x3d, 0x3d, 0xe5, 0x76, 0xe3, 0xee, 0xae, 0xa6, 0xbb, 0x3a, 0xc4, 0xb9, 0xa1, 0xb0, + 0x08, 0x21, 0x76, 0x24, 0x48, 0x48, 0x02, 0x61, 0xdf, 0x21, 0xec, 0xcb, 0x85, 0x0b, 0xcb, 0x95, + 0xff, 0x81, 0x0b, 0x60, 0xf6, 0xb9, 0xf9, 0x82, 0x5e, 0xf7, 0x7b, 0x3d, 0x35, 0xed, 0x91, 0xaa, + 0xe6, 0xd6, 0x1e, 0xd7, 0xef, 0x37, 0xd5, 0xef, 0x75, 0xbd, 0xf7, 0xa6, 0x19, 0xf3, 0xa4, 0x27, + 0x27, 0xe3, 0x44, 0x2a, 0x59, 0xaf, 0xc1, 0x75, 0x7e, 0xb9, 0x6f, 0xbf, 0x27, 0xa5, 0x17, 0x88, + 0xa9, 0xfc, 0xaf, 0x66, 0xb6, 0x3a, 0xd5, 0x12, 0xa9, 0x9b, 0xf8, 0xb1, 0x92, 0x49, 0xb1, 0x98, + 0x1f, 0x63, 0x63, 0xb8, 0xb8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fc, 0x10, 0xab, 0xc1, 0x65, 0xfe, 0x62, 0xca, 0x04, 0xff, 0x8d, 0x70, + 0x87, 0x80, 0x6f, 0x4e, 0x55, 0x4b, 0xf9, 0xe6, 0x60, 0xff, 0x83, 0x99, 0xa6, 0xf5, 0x7c, 0x96, + 0x0d, 0xa6, 0xaa, 0xd5, 0xca, 0x70, 0xc4, 0x35, 0xe0, 0xff, 0x6e, 0x95, 0x6f, 0x3d, 0x4a, 0x06, + 0xb2, 0x7d, 0xff, 0xba, 0x8a, 0xa5, 0x1f, 0x29, 0x91, 0x98, 0x0c, 0x6d, 0x34, 0x68, 0xc8, 0xe1, + 0x79, 0x36, 0xe6, 0xca, 0xb0, 0xca, 0x1d, 0x66, 0x0b, 0x72, 0x41, 0x2e, 0xe5, 0xa5, 0xea, 0xee, + 0x1b, 0x3d, 0x5f, 0xad, 0x65, 0xcd, 0x49, 0x57, 0x86, 0x53, 0xf0, 0xe3, 0xa5, 0xf3, 0x4e, 0xb6, + 0xfc, 0x29, 0xf3, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0xbf, 0x17, 0xde, 0xc6, 0x15, 0x00, + 0x00, } diff --git a/gogoproto/gogo.proto b/gogoproto/gogo.proto index b80c85653f..d3f2fd349e 100644 --- a/gogoproto/gogo.proto +++ b/gogoproto/gogo.proto @@ -124,6 +124,8 @@ extend google.protobuf.MessageOptions { optional bool goproto_sizecache = 64034; optional bool goproto_unkeyed = 64035; + + optional string annotation = 64036; } extend google.protobuf.FieldOptions { diff --git a/gogoproto/helper.go b/gogoproto/helper.go index 390d4e4be6..2c198aa4fd 100644 --- a/gogoproto/helper.go +++ b/gogoproto/helper.go @@ -306,6 +306,11 @@ func IsUnion(file *google_protobuf.FileDescriptorProto, message *google_protobuf return proto.GetBoolExtension(message.Options, E_Onlyone, proto.GetBoolExtension(file.Options, E_OnlyoneAll, false)) } + +func GetStringAnnotation(message *google_protobuf.DescriptorProto) string { + return proto.GetStringExtension(message.Options, E_Annotation) +} + func HasGoString(file *google_protobuf.FileDescriptorProto, message *google_protobuf.DescriptorProto) bool { return proto.GetBoolExtension(message.Options, E_Gostring, proto.GetBoolExtension(file.Options, E_GostringAll, false)) } diff --git a/plugin/annotation/annotation.go b/plugin/annotation/annotation.go new file mode 100644 index 0000000000..35e51e459b --- /dev/null +++ b/plugin/annotation/annotation.go @@ -0,0 +1,41 @@ +package annotation + +import ( + "github.com/gogo/protobuf/gogoproto" + "github.com/gogo/protobuf/protoc-gen-gogo/generator" +) + + +type annotation struct { + *generator.Generator + generator.PluginImports +} + +func NewAnnotation() *annotation { + return &annotation{} +} + +func (p *annotation) Name() string { + return "annotation" +} + +func (p *annotation) Init(g *generator.Generator) { + p.Generator = g +} + +func (p *annotation) Generate(file *generator.FileDescriptor) { + p.PluginImports = generator.NewPluginImports(p.Generator) + for _, message := range file.Messages() { + if gogoproto.GetStringAnnotation(message.DescriptorProto) == "" { + continue + } + + ccTypeName := generator.CamelCaseSlice(message.TypeName()) + p.P(`func init(){ proto.RegisterAnnotation(`, + `(*`, ccTypeName, ")(nil), `",gogoproto.GetStringAnnotation(message.DescriptorProto) ,"`)}") + } +} + +func init() { + generator.RegisterPlugin(NewAnnotation()) +} diff --git a/proto/extensions_gogo.go b/proto/extensions_gogo.go index 6f1ae120ec..7944a5579d 100644 --- a/proto/extensions_gogo.go +++ b/proto/extensions_gogo.go @@ -79,6 +79,21 @@ func GetBoolExtension(pb Message, extension *ExtensionDesc, ifnotset bool) bool return *(value.(*bool)) } +func GetStringExtension(pb Message, extension *ExtensionDesc) string { + if reflect.ValueOf(pb).IsNil() { + return "" + } + value, err := GetExtension(pb, extension) + if err != nil { + return "" + } + + if value.(*string) == nil { + return "" + } + return *(value.(*string)) +} + func (this *Extension) Equal(that *Extension) bool { if err := this.Encode(); err != nil { return false diff --git a/proto/properties.go b/proto/properties.go index 28da1475fb..1e42e82957 100644 --- a/proto/properties.go +++ b/proto/properties.go @@ -595,6 +595,31 @@ func MessageType(name string) reflect.Type { return protoMapTypes[name] } +// A registry of message type's annotations. +var ( + annotations = make(map[reflect.Type]string) // message type => annotation +) + +// RegisterAnnotation is called from generated code and maps from the +// message type to its annotation. +func RegisterAnnotation(x Message, annotation string) { + annotations[reflect.TypeOf(x)] = annotation +} + +// GetAnnotation returns the annotation for a message. +func GetAnnotation(x Message) string { + return annotations[reflect.TypeOf(x)] +} + +// GetAnnotations returns all annotations registered. +func GetAnnotations() []string { + var ret []string + for _, v := range annotations { + ret = append(ret, v) + } + return ret +} + // A registry of all linked proto files. var ( protoFiles = make(map[string][]byte) // file name => fileDescriptor diff --git a/protoc-gen-gogo/generator/generator.go b/protoc-gen-gogo/generator/generator.go index ab07ed61ef..1e3750f3cd 100644 --- a/protoc-gen-gogo/generator/generator.go +++ b/protoc-gen-gogo/generator/generator.go @@ -548,7 +548,7 @@ func (g *Generator) CommandLineParameters(parameter string) { if pluginList == "none" { pluginList = "" } - gogoPluginNames := []string{"unmarshal", "unsafeunmarshaler", "union", "stringer", "size", "protosizer", "populate", "marshalto", "unsafemarshaler", "gostring", "face", "equal", "enumstringer", "embedcheck", "description", "defaultcheck", "oneofcheck", "compare"} + gogoPluginNames := []string{"annotation", "unmarshal", "unsafeunmarshaler", "union", "stringer", "size", "protosizer", "populate", "marshalto", "unsafemarshaler", "gostring", "face", "equal", "enumstringer", "embedcheck", "description", "defaultcheck", "oneofcheck", "compare"} pluginList = strings.Join(append(gogoPluginNames, pluginList), "+") if pluginList != "" { // Amend the set of plugins. diff --git a/vanity/command/command.go b/vanity/command/command.go index eeca42ba0d..8d182774c2 100644 --- a/vanity/command/command.go +++ b/vanity/command/command.go @@ -35,6 +35,7 @@ import ( "os" "strings" + _ "github.com/gogo/protobuf/plugin/annotation" _ "github.com/gogo/protobuf/plugin/compare" _ "github.com/gogo/protobuf/plugin/defaultcheck" _ "github.com/gogo/protobuf/plugin/description"