Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#623 Adds custom gogoproto.oneof_moretags option to OneofOptions #712

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
180 changes: 96 additions & 84 deletions gogoproto/gogo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gogoproto/gogo.proto
Expand Up @@ -142,3 +142,7 @@ extend google.protobuf.FieldOptions {
optional bool wktpointer = 65012;

}

extend google.protobuf.OneofOptions {
optional string oneof_moretags = 67001;
}
19 changes: 19 additions & 0 deletions gogoproto/helper.go
Expand Up @@ -288,6 +288,25 @@ func GetMoreTags(field *google_protobuf.FieldDescriptorProto) *string {
return nil
}

func GetOneOfMoreTags(oneofField *google_protobuf.OneofDescriptorProto) string {
if oneofField == nil {
return ""
}

if oneofField.Options != nil {
v, err := proto.GetExtension(oneofField.Options, E_OneofMoretags)
if err != nil {
return ""
}

if ptr, ok := v.(*string); ok{
return *ptr
}
}

return ""
}

type EnableFunc func(file *google_protobuf.FileDescriptorProto, message *google_protobuf.DescriptorProto) bool

func EnabledGoEnumPrefix(file *google_protobuf.FileDescriptorProto, enum *google_protobuf.EnumDescriptorProto) bool {
Expand Down
6 changes: 4 additions & 2 deletions protoc-gen-gogo/generator/generator.go
Expand Up @@ -2871,13 +2871,15 @@ func (g *Generator) generateMessage(message *Descriptor) {
// when we've computed any disambiguation.

dname := "is" + goTypeName + "_" + fname
oneOftag := `protobuf_oneof:"` + odp.GetName() + `"`
oneofTag := `protobuf_oneof:"` + odp.GetName() + `"`
oneofMoreTags := gogoproto.GetOneOfMoreTags(odp)
oneofTags := fmt.Sprintf("%s %s", oneofTag, oneofMoreTags)
of := oneofField{
fieldCommon: fieldCommon{
goName: fname,
getterName: gname,
goType: dname,
tags: oneOftag,
tags: oneofTags,
protoName: odp.GetName(),
fullPath: oneofFullPath,
protoField: field,
Expand Down