Skip to content

Commit

Permalink
cast int literal to double if field in proto is double (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
passichenko authored May 2, 2024
1 parent b5a9abe commit fbdeb86
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/sync/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ func (g *goSyncer) compositeLitToProto(x *ast.CompositeLit) protoreflect.Message
panic(fmt.Errorf("unsupported composite literal type %T", clTypeNode))
}
default:
field.Kind()
// Value is not a composite literal - try handling as a primitive
value := g.primitiveToProtoValue(node)
if field.Kind() == protoreflect.EnumKind {
Expand All @@ -648,6 +647,11 @@ func (g *goSyncer) compositeLitToProto(x *ast.CompositeLit) protoreflect.Message
msg.Set(field, protoreflect.ValueOf(protoreflect.EnumNumber(intValue)))
continue
}
// convert int64 to float64 (double) if this is what proto expects
// it's not 100% safe, but should be fine for values < 9007199254740993
if intValue, ok := value.(int64); ok && field.Kind() == protoreflect.DoubleKind {
value = float64(intValue)
}
msg.Set(field, protoreflect.ValueOf(value))
}
}
Expand Down

0 comments on commit fbdeb86

Please sign in to comment.