(typ reflect.Type)
| 49 | } |
| 50 | |
| 51 | func _getEncoder(typ reflect.Type) encoderFunc { |
| 52 | kind := typ.Kind() |
| 53 | |
| 54 | if kind == reflect.Ptr { |
| 55 | if _, ok := typeEncMap.Load(typ.Elem()); ok { |
| 56 | return ptrEncoderFunc(typ) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if typ.Implements(customEncoderType) { |
| 61 | return encodeCustomValue |
| 62 | } |
| 63 | if typ.Implements(marshalerType) { |
| 64 | return marshalValue |
| 65 | } |
| 66 | if typ.Implements(binaryMarshalerType) { |
| 67 | return marshalBinaryValue |
| 68 | } |
| 69 | if typ.Implements(textMarshalerType) { |
| 70 | return marshalTextValue |
| 71 | } |
| 72 | |
| 73 | // Addressable struct field value. |
| 74 | if kind != reflect.Ptr { |
| 75 | ptr := reflect.PtrTo(typ) |
| 76 | if ptr.Implements(customEncoderType) { |
| 77 | return encodeCustomValuePtr |
| 78 | } |
| 79 | if ptr.Implements(marshalerType) { |
| 80 | return marshalValuePtr |
| 81 | } |
| 82 | if ptr.Implements(binaryMarshalerType) { |
| 83 | return marshalBinaryValueAddr |
| 84 | } |
| 85 | if ptr.Implements(textMarshalerType) { |
| 86 | return marshalTextValueAddr |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if typ == errorType { |
| 91 | return encodeErrorValue |
| 92 | } |
| 93 | |
| 94 | switch kind { |
| 95 | case reflect.Ptr: |
| 96 | return ptrEncoderFunc(typ) |
| 97 | case reflect.Slice: |
| 98 | elem := typ.Elem() |
| 99 | if elem.Kind() == reflect.Uint8 { |
| 100 | return encodeByteSliceValue |
| 101 | } |
| 102 | if elem == stringType { |
| 103 | return encodeStringSliceValue |
| 104 | } |
| 105 | case reflect.Array: |
| 106 | if typ.Elem().Kind() == reflect.Uint8 { |
| 107 | return encodeByteArrayValue |
| 108 | } |
no test coverage detected
searching dependent graphs…