MCPcopy Index your code
hub / github.com/segmentio/encoding / constructCodec

Function constructCodec

json/codec.go:98–232  ·  view source on GitHub ↗
(t reflect.Type, seen map[reflect.Type]*structType, canAddr bool)

Source from the content-addressed store, hash-verified

96}
97
98func constructCodec(t reflect.Type, seen map[reflect.Type]*structType, canAddr bool) (c codec) {
99 switch t {
100 case nullType, nil:
101 c = codec{encode: encoder.encodeNull, decode: decoder.decodeNull}
102
103 case numberType:
104 c = codec{encode: encoder.encodeNumber, decode: decoder.decodeNumber}
105
106 case bytesType:
107 c = codec{encode: encoder.encodeBytes, decode: decoder.decodeBytes}
108
109 case durationType:
110 c = codec{encode: encoder.encodeDuration, decode: decoder.decodeDuration}
111
112 case timeType:
113 c = codec{encode: encoder.encodeTime, decode: decoder.decodeTime}
114
115 case interfaceType:
116 c = codec{encode: encoder.encodeInterface, decode: decoder.decodeInterface}
117
118 case rawMessageType:
119 c = codec{encode: encoder.encodeRawMessage, decode: decoder.decodeRawMessage}
120
121 case numberPtrType:
122 c = constructPointerCodec(numberPtrType, nil)
123
124 case durationPtrType:
125 c = constructPointerCodec(durationPtrType, nil)
126
127 case timePtrType:
128 c = constructPointerCodec(timePtrType, nil)
129
130 case rawMessagePtrType:
131 c = constructPointerCodec(rawMessagePtrType, nil)
132 }
133
134 if c.encode != nil {
135 return
136 }
137
138 switch t.Kind() {
139 case reflect.Bool:
140 c = codec{encode: encoder.encodeBool, decode: decoder.decodeBool}
141
142 case reflect.Int:
143 c = codec{encode: encoder.encodeInt, decode: decoder.decodeInt}
144
145 case reflect.Int8:
146 c = codec{encode: encoder.encodeInt8, decode: decoder.decodeInt8}
147
148 case reflect.Int16:
149 c = codec{encode: encoder.encodeInt16, decode: decoder.decodeInt16}
150
151 case reflect.Int32:
152 c = codec{encode: encoder.encodeInt32, decode: decoder.decodeInt32}
153
154 case reflect.Int64:
155 c = codec{encode: encoder.encodeInt64, decode: decoder.decodeInt64}

Callers 7

constructCachedCodecFunction · 0.85
constructStringCodecFunction · 0.85
constructArrayCodecFunction · 0.85
constructSliceCodecFunction · 0.85
constructMapCodecFunction · 0.85
appendStructFieldsFunction · 0.85
constructPointerCodecFunction · 0.85

Calls 12

constructPointerCodecFunction · 0.85
constructInterfaceCodecFunction · 0.85
constructArrayCodecFunction · 0.85
constructSliceCodecFunction · 0.85
constructMapCodecFunction · 0.85
constructStructCodecFunction · 0.85
KindMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…