@@ -118,92 +118,17 @@ func createDecoderOfType(cfg *frozenConfig, prefix string, typ reflect.Type) Val
118118 if decoder != nil {
119119 return decoder
120120 }
121- if typ .Kind () == reflect .Slice && typ .Elem ().Kind () == reflect .Uint8 {
122- sliceDecoder := decoderOfSlice (cfg , prefix , typ )
123- return & base64Codec {sliceDecoder : sliceDecoder }
124- }
125121 if typ == anyType {
126122 return & directAnyCodec {}
127123 }
128124 if typ .Implements (anyType ) {
129125 return & anyCodec {}
130126 }
127+ decoder = createDecoderOfNative (cfg , prefix , typ )
128+ if decoder != nil {
129+ return decoder
130+ }
131131 switch typ .Kind () {
132- case reflect .String :
133- if typeName != "string" {
134- return decoderOfType (cfg , prefix , reflect .TypeOf ((* string )(nil )).Elem ())
135- }
136- return & stringCodec {}
137- case reflect .Int :
138- if typeName != "int" {
139- return decoderOfType (cfg , prefix , reflect .TypeOf ((* int )(nil )).Elem ())
140- }
141- return & intCodec {}
142- case reflect .Int8 :
143- if typeName != "int8" {
144- return decoderOfType (cfg , prefix , reflect .TypeOf ((* int8 )(nil )).Elem ())
145- }
146- return & int8Codec {}
147- case reflect .Int16 :
148- if typeName != "int16" {
149- return decoderOfType (cfg , prefix , reflect .TypeOf ((* int16 )(nil )).Elem ())
150- }
151- return & int16Codec {}
152- case reflect .Int32 :
153- if typeName != "int32" {
154- return decoderOfType (cfg , prefix , reflect .TypeOf ((* int32 )(nil )).Elem ())
155- }
156- return & int32Codec {}
157- case reflect .Int64 :
158- if typeName != "int64" {
159- return decoderOfType (cfg , prefix , reflect .TypeOf ((* int64 )(nil )).Elem ())
160- }
161- return & int64Codec {}
162- case reflect .Uint :
163- if typeName != "uint" {
164- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uint )(nil )).Elem ())
165- }
166- return & uintCodec {}
167- case reflect .Uint8 :
168- if typeName != "uint8" {
169- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uint8 )(nil )).Elem ())
170- }
171- return & uint8Codec {}
172- case reflect .Uint16 :
173- if typeName != "uint16" {
174- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uint16 )(nil )).Elem ())
175- }
176- return & uint16Codec {}
177- case reflect .Uint32 :
178- if typeName != "uint32" {
179- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uint32 )(nil )).Elem ())
180- }
181- return & uint32Codec {}
182- case reflect .Uintptr :
183- if typeName != "uintptr" {
184- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uintptr )(nil )).Elem ())
185- }
186- return & uintptrCodec {}
187- case reflect .Uint64 :
188- if typeName != "uint64" {
189- return decoderOfType (cfg , prefix , reflect .TypeOf ((* uint64 )(nil )).Elem ())
190- }
191- return & uint64Codec {}
192- case reflect .Float32 :
193- if typeName != "float32" {
194- return decoderOfType (cfg , prefix , reflect .TypeOf ((* float32 )(nil )).Elem ())
195- }
196- return & float32Codec {}
197- case reflect .Float64 :
198- if typeName != "float64" {
199- return decoderOfType (cfg , prefix , reflect .TypeOf ((* float64 )(nil )).Elem ())
200- }
201- return & float64Codec {}
202- case reflect .Bool :
203- if typeName != "bool" {
204- return decoderOfType (cfg , prefix , reflect .TypeOf ((* bool )(nil )).Elem ())
205- }
206- return & boolCodec {}
207132 case reflect .Interface :
208133 if typ .NumMethod () == 0 {
209134 return & emptyInterfaceCodec {}
@@ -305,9 +230,6 @@ func createEncoderOfType(cfg *frozenConfig, prefix string, typ reflect.Type) Val
305230 if encoder != nil {
306231 return encoder
307232 }
308- if typ .Kind () == reflect .Slice && typ .Elem ().Kind () == reflect .Uint8 {
309- return & base64Codec {}
310- }
311233 if typ == anyType {
312234 return & directAnyCodec {}
313235 }
@@ -370,84 +292,12 @@ func createCheckIsEmpty(cfg *frozenConfig, typ reflect.Type) checkIsEmpty {
370292}
371293
372294func createEncoderOfSimpleType (cfg * frozenConfig , prefix string , typ reflect.Type ) ValEncoder {
373- typeName := typ .String ()
295+ encoder := createEncoderOfNative (cfg , prefix , typ )
296+ if encoder != nil {
297+ return encoder
298+ }
374299 kind := typ .Kind ()
375300 switch kind {
376- case reflect .String :
377- if typeName != "string" {
378- return encoderOfType (cfg , prefix , reflect .TypeOf ((* string )(nil )).Elem ())
379- }
380- return & stringCodec {}
381- case reflect .Int :
382- if typeName != "int" {
383- return encoderOfType (cfg , prefix , reflect .TypeOf ((* int )(nil )).Elem ())
384- }
385- return & intCodec {}
386- case reflect .Int8 :
387- if typeName != "int8" {
388- return encoderOfType (cfg , prefix , reflect .TypeOf ((* int8 )(nil )).Elem ())
389- }
390- return & int8Codec {}
391- case reflect .Int16 :
392- if typeName != "int16" {
393- return encoderOfType (cfg , prefix , reflect .TypeOf ((* int16 )(nil )).Elem ())
394- }
395- return & int16Codec {}
396- case reflect .Int32 :
397- if typeName != "int32" {
398- return encoderOfType (cfg , prefix , reflect .TypeOf ((* int32 )(nil )).Elem ())
399- }
400- return & int32Codec {}
401- case reflect .Int64 :
402- if typeName != "int64" {
403- return encoderOfType (cfg , prefix , reflect .TypeOf ((* int64 )(nil )).Elem ())
404- }
405- return & int64Codec {}
406- case reflect .Uint :
407- if typeName != "uint" {
408- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uint )(nil )).Elem ())
409- }
410- return & uintCodec {}
411- case reflect .Uint8 :
412- if typeName != "uint8" {
413- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uint8 )(nil )).Elem ())
414- }
415- return & uint8Codec {}
416- case reflect .Uint16 :
417- if typeName != "uint16" {
418- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uint16 )(nil )).Elem ())
419- }
420- return & uint16Codec {}
421- case reflect .Uint32 :
422- if typeName != "uint32" {
423- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uint32 )(nil )).Elem ())
424- }
425- return & uint32Codec {}
426- case reflect .Uintptr :
427- if typeName != "uintptr" {
428- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uintptr )(nil )).Elem ())
429- }
430- return & uintptrCodec {}
431- case reflect .Uint64 :
432- if typeName != "uint64" {
433- return encoderOfType (cfg , prefix , reflect .TypeOf ((* uint64 )(nil )).Elem ())
434- }
435- return & uint64Codec {}
436- case reflect .Float32 :
437- if typeName != "float32" {
438- return encoderOfType (cfg , prefix , reflect .TypeOf ((* float32 )(nil )).Elem ())
439- }
440- return & float32Codec {}
441- case reflect .Float64 :
442- if typeName != "float64" {
443- return encoderOfType (cfg , prefix , reflect .TypeOf ((* float64 )(nil )).Elem ())
444- }
445- return & float64Codec {}
446- case reflect .Bool :
447- if typeName != "bool" {
448- return encoderOfType (cfg , prefix , reflect .TypeOf ((* bool )(nil )).Elem ())
449- }
450- return & boolCodec {}
451301 case reflect .Interface :
452302 return & dynamicEncoder {reflect2 .Type2 (typ )}
453303 case reflect .Struct :
0 commit comments