Skip to content

Commit

Permalink
tool: mapping functions for more types
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyih committed Jan 14, 2025
1 parent 3625357 commit e7221d1
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dev/tools/controllerbuilder/pkg/codegen/mappergenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,18 @@ func krmFromProtoFunctionName(protoField protoreflect.FieldDescriptor, krmFieldN
return "direct.StringValue_FromProto"
case "google.protobuf.BoolValue":
return "direct.BoolValue_FromProto"
case "google.protobuf.FloatValue":
return "direct.FloatValue_FromProto"
case "google.protobuf.DoubleValue":
return "direct.DoubleValue_FromProto"
case "google.protobuf.Int32Value":
return "direct.Int32Value_FromProto"
case "google.protobuf.UInt32Value":
return "direct.UInt32Value_FromProto"
case "google.protobuf.UInt64Value":
return "direct.UInt64Value_FromProto"
case "google.protobuf.BytesValue":
return "direct.BytesValue_FromProto"
}
klog.Fatalf("unhandled case in krmFromProtoFunctionName for proto field %s", fullname)
return ""
Expand All @@ -752,6 +764,18 @@ func krmToProtoFunctionName(protoField protoreflect.FieldDescriptor, krmFieldNam
return "direct.StringValue_ToProto"
case "google.protobuf.BoolValue":
return "direct.BoolValue_ToProto"
case "google.protobuf.FloatValue":
return "direct.FloatValue_ToProto"
case "google.protobuf.DoubleValue":
return "direct.DoubleValue_ToProto"
case "google.protobuf.Int32Value":
return "direct.Int32Value_ToProto"
case "google.protobuf.UInt32Value":
return "direct.UInt32Value_ToProto"
case "google.protobuf.UInt64Value":
return "direct.UInt64Value_ToProto"
case "google.protobuf.BytesValue":
return "direct.BytesValue_ToProto"
}
klog.Fatalf("unhandled case in krmToProtoFunctionName for proto field %s", fullname)
return ""
Expand Down
95 changes: 95 additions & 0 deletions pkg/controller/direct/maputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,98 @@ func Int64Value_FromProto(mapCtx *MapContext, ts *wrapperspb.Int64Value) int64 {
func Int64Value_ToProto(mapCtx *MapContext, s int64) *wrapperspb.Int64Value {
return wrapperspb.Int64(s)
}

func FloatValue_FromProto(mapCtx *MapContext, in *wrapperspb.FloatValue) *float32 {
if in == nil {
return nil
}
out := in.Value
return &out
}

func FloatValue_ToProto(mapCtx *MapContext, in *float32) *wrapperspb.FloatValue {
if in == nil {
return nil
}
out := wrapperspb.Float(*in)
return out
}

// Float64 wrapper functions
func DoubleValue_FromProto(mapCtx *MapContext, in *wrapperspb.DoubleValue) *float64 {
if in == nil {
return nil
}
out := in.Value
return &out
}

func DoubleValue_ToProto(mapCtx *MapContext, in *float64) *wrapperspb.DoubleValue {
if in == nil {
return nil
}
out := wrapperspb.Double(*in)
return out
}

func Int32Value_FromProto(mapCtx *MapContext, in *wrapperspb.Int32Value) *int32 {
if in == nil {
return nil
}
out := in.Value
return &out
}

func Int32Value_ToProto(mapCtx *MapContext, in *int32) *wrapperspb.Int32Value {
if in == nil {
return nil
}
out := wrapperspb.Int32(*in)
return out
}

func UInt32Value_FromProto(mapCtx *MapContext, in *wrapperspb.UInt32Value) *uint32 {
if in == nil {
return nil
}
out := in.Value
return &out
}

func UInt32Value_ToProto(mapCtx *MapContext, in *uint32) *wrapperspb.UInt32Value {
if in == nil {
return nil
}
out := wrapperspb.UInt32(*in)
return out
}

func UInt64Value_FromProto(mapCtx *MapContext, in *wrapperspb.UInt64Value) *uint64 {
if in == nil {
return nil
}
out := in.Value
return &out
}

func UInt64Value_ToProto(mapCtx *MapContext, in *uint64) *wrapperspb.UInt64Value {
if in == nil {
return nil
}
out := wrapperspb.UInt64(*in)
return out
}

func BytesValue_FromProto(mapCtx *MapContext, in *wrapperspb.BytesValue) []byte {
if in == nil {
return nil
}
return in.Value
}

func BytesValue_ToProto(mapCtx *MapContext, in []byte) *wrapperspb.BytesValue {
if in == nil {
return nil
}
return wrapperspb.Bytes(in)
}

0 comments on commit e7221d1

Please sign in to comment.