Skip to content

Commit

Permalink
增加enumvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
coderyw committed Oct 23, 2024
1 parent 0eaceac commit 68a8d0d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,28 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
}
g.Out()
g.P("}")

g.P("var ", ccTypeName, "AliasValue = map[string]int32{")
g.In()
generatedStr := make(map[string]bool) // avoid duplicate values
for _, e := range enum.Value {
duplicate := ""
str := ""

if gogoproto.IsEnumAliasCustomName(e) {
str = strconv.Quote(gogoproto.GetEnumAliasCustomName(e))
} else {
str = strconv.Quote(*e.Name)
}

if _, present := generatedStr[str]; present {
duplicate = "// Duplicate value: "
}
g.P(duplicate, str, ": ", e.Number, ",")
generatedStr[str] = true
}
g.Out()
g.P("}")
}

if gogoproto.EnabledGoEnumEqual(enum.file.FileDescriptorProto, enum.EnumDescriptorProto) {
Expand Down

0 comments on commit 68a8d0d

Please sign in to comment.