-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
…ype, which can be used like JAVA's runtime annotation.
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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()) | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.