-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add plugin annotation, which add a annotation of string for message t…
…ype, which can be used like JAVA's runtime annotation.
- Loading branch information
Showing
8 changed files
with
186 additions
and
85 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters