Skip to content

Commit

Permalink
added support for optional enums for gorm protoc generator.
Browse files Browse the repository at this point in the history
based on the issue I opened here:

infobloxopen#280
  • Loading branch information
RomanSter committed Dec 9, 2024
1 parent c61100d commit 2e40225
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,13 +1458,16 @@ func (b *ORMBuilder) generateFieldConversion(message *protogen.Message, field *p
fieldType = b.typeName(field.Enum.GoIdent, g)
if toORM {
if b.stringEnums {
g.P(`to.`, fieldName, ` = `, fieldType, `_name[int32(m.`, fieldName, `)]`)
} else if field.Desc.HasOptionalKeyword() {
g.P(`to.`, fieldName, ` = (*int32)(m.`, fieldName, `)`)
} else {
g.P(`to.`, fieldName, ` = int32(m.`, fieldName, `)`)
}
} else {
if b.stringEnums {
g.P(`to.`, fieldName, ` = `, fieldType, `(`, fieldType, `_value[m.`, fieldName, `])`)
} else if field.Desc.HasOptionalKeyword() {
g.P(`to.`, fieldName, ` = (*`, fieldType, `)(m.`, fieldName, `)`)
} else {
g.P(`to.`, fieldName, ` = `, fieldType, `(m.`, fieldName, `)`)
}
Expand Down

0 comments on commit 2e40225

Please sign in to comment.