MCPcopy Create free account
hub / github.com/goadesign/goa / convertType

Function convertType

grpc/codegen/protobuf_transform.go:658–685  ·  view source on GitHub ↗

convertType produces code to initialize a target type from a source type held by sourceVar.

(src, tgt *expr.AttributeExpr, srcPtr bool, tgtPtr bool, srcVar string, ta *transformAttrs)

Source from the content-addressed store, hash-verified

656// convertType produces code to initialize a target type from a source type
657// held by sourceVar.
658func convertType(src, tgt *expr.AttributeExpr, srcPtr bool, tgtPtr bool, srcVar string, ta *transformAttrs) string {
659 if expr.IsAlias(src.Type) || expr.IsAlias(tgt.Type) {
660 srcp, tgtp := unAlias(src), unAlias(tgt)
661 if srcp.Type == tgtp.Type {
662 if ta.proto {
663 return convertPrimitiveToProto(src, tgtp, srcPtr, tgtPtr, srcVar, ta)
664 }
665 return convertPrimitiveFromProto(srcp, tgt, srcPtr, tgtPtr, srcVar, ta)
666 }
667 return fmt.Sprintf("%s(%s)", transformHelperName(src, tgt, ta), srcVar)
668 }
669
670 if _, ok := src.Type.(expr.UserType); ok {
671 return fmt.Sprintf("%s(%s)", transformHelperName(src, tgt, ta), srcVar)
672 }
673
674 srcType, _ := codegen.GetMetaType(src)
675 tgtType, _ := codegen.GetMetaType(tgt)
676 if srcType == "" && tgtType == "" && (src.Type != expr.Int) && (src.Type != expr.UInt) && (src.Type != expr.Any) {
677 // Nothing to do, except for Any type which needs special conversion
678 return srcVar
679 }
680
681 if ta.proto {
682 return convertPrimitiveToProto(src, tgt, srcPtr, tgtPtr, srcVar, ta)
683 }
684 return convertPrimitiveFromProto(src, tgt, srcPtr, tgtPtr, srcVar, ta)
685}
686
687const convertGoAnyToProtobufValueFunc = `func() *structpb.Value {
688 // Convert Go any to protobuf Value directly

Callers 2

transformAttributeFunction · 0.85
transformObjectFunction · 0.85

Calls 6

IsAliasFunction · 0.92
GetMetaTypeFunction · 0.92
unAliasFunction · 0.85
convertPrimitiveToProtoFunction · 0.85
transformHelperNameFunction · 0.70

Tested by

no test coverage detected