(value any, buf []byte)
| 85 | } |
| 86 | |
| 87 | func (p *encodePlanMultirangeCodecText) Encode(value any, buf []byte) (newBuf []byte, err error) { |
| 88 | multirange := value.(MultirangeGetter) |
| 89 | |
| 90 | if multirange.IsNull() { |
| 91 | return nil, nil |
| 92 | } |
| 93 | |
| 94 | elementCount := multirange.Len() |
| 95 | |
| 96 | buf = append(buf, '{') |
| 97 | |
| 98 | var encodePlan EncodePlan |
| 99 | var lastElemType reflect.Type |
| 100 | inElemBuf := make([]byte, 0, 32) |
| 101 | for i := range elementCount { |
| 102 | if i > 0 { |
| 103 | buf = append(buf, ',') |
| 104 | } |
| 105 | |
| 106 | elem := multirange.Index(i) |
| 107 | var elemBuf []byte |
| 108 | if elem != nil { |
| 109 | elemType := reflect.TypeOf(elem) |
| 110 | if lastElemType != elemType { |
| 111 | lastElemType = elemType |
| 112 | encodePlan = p.m.PlanEncode(p.ac.ElementType.OID, TextFormatCode, elem) |
| 113 | if encodePlan == nil { |
| 114 | return nil, fmt.Errorf("unable to encode %v", multirange.Index(i)) |
| 115 | } |
| 116 | } |
| 117 | elemBuf, err = encodePlan.Encode(elem, inElemBuf) |
| 118 | if err != nil { |
| 119 | return nil, err |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if elemBuf == nil { |
| 124 | return nil, fmt.Errorf("multirange cannot contain NULL element") |
| 125 | } else { |
| 126 | buf = append(buf, elemBuf...) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | buf = append(buf, '}') |
| 131 | |
| 132 | return buf, nil |
| 133 | } |
| 134 | |
| 135 | type encodePlanMultirangeCodecBinary struct { |
| 136 | ac *MultirangeCodec |
nothing calls this directly
no test coverage detected