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)
| 656 | // convertType produces code to initialize a target type from a source type |
| 657 | // held by sourceVar. |
| 658 | func 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 | |
| 687 | const convertGoAnyToProtobufValueFunc = `func() *structpb.Value { |
| 688 | // Convert Go any to protobuf Value directly |
no test coverage detected