MCPcopy Create free account
hub / github.com/vmihailenco/msgpack / _getDecoder

Function _getDecoder

decode_value.go:58–124  ·  view source on GitHub ↗
(typ reflect.Type)

Source from the content-addressed store, hash-verified

56}
57
58func _getDecoder(typ reflect.Type) decoderFunc {
59 kind := typ.Kind()
60
61 if kind == reflect.Ptr {
62 if _, ok := typeDecMap.Load(typ.Elem()); ok {
63 return ptrValueDecoder(typ)
64 }
65 }
66
67 if typ.Implements(customDecoderType) {
68 return nilAwareDecoder(typ, decodeCustomValue)
69 }
70 if typ.Implements(unmarshalerType) {
71 return nilAwareDecoder(typ, unmarshalValue)
72 }
73 if typ.Implements(binaryUnmarshalerType) {
74 return nilAwareDecoder(typ, unmarshalBinaryValue)
75 }
76 if typ.Implements(textUnmarshalerType) {
77 return nilAwareDecoder(typ, unmarshalTextValue)
78 }
79
80 // Addressable struct field value.
81 if kind != reflect.Ptr {
82 ptr := reflect.PtrTo(typ)
83 if ptr.Implements(customDecoderType) {
84 return addrDecoder(nilAwareDecoder(typ, decodeCustomValue))
85 }
86 if ptr.Implements(unmarshalerType) {
87 return addrDecoder(nilAwareDecoder(typ, unmarshalValue))
88 }
89 if ptr.Implements(binaryUnmarshalerType) {
90 return addrDecoder(nilAwareDecoder(typ, unmarshalBinaryValue))
91 }
92 if ptr.Implements(textUnmarshalerType) {
93 return addrDecoder(nilAwareDecoder(typ, unmarshalTextValue))
94 }
95 }
96
97 switch kind {
98 case reflect.Ptr:
99 return ptrValueDecoder(typ)
100 case reflect.Slice:
101 elem := typ.Elem()
102 if elem.Kind() == reflect.Uint8 {
103 return decodeBytesValue
104 }
105 if elem == stringType {
106 return decodeStringSliceValue
107 }
108 case reflect.Array:
109 if typ.Elem().Kind() == reflect.Uint8 {
110 return decodeByteArrayValue
111 }
112 case reflect.Map:
113 if typ.Key() == stringType {
114 switch typ.Elem() {
115 case stringType:

Callers 1

getDecoderFunction · 0.85

Calls 3

ptrValueDecoderFunction · 0.85
nilAwareDecoderFunction · 0.85
addrDecoderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…