From 63287dfd5bde38d78afd0fc85a5d74de245668be Mon Sep 17 00:00:00 2001 From: shockerli Date: Wed, 6 Oct 2021 17:21:41 +0800 Subject: [PATCH] support indirect type for []byte * support indirect type for []byte eg: `type NewBytes []byte` * remove unused complex/uintptr --- cvte.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cvte.go b/cvte.go index 20aea62..6a0d63f 100644 --- a/cvte.go +++ b/cvte.go @@ -70,6 +70,7 @@ func indirect(a interface{}) (val interface{}, rt reflect.Type, rv reflect.Value rt = reflect.TypeOf(a) rv = reflect.ValueOf(a) + val = rv.Interface() switch rt.Kind() { case reflect.Ptr: // indirect the base type, if is be referenced many times @@ -99,20 +100,17 @@ func indirect(a interface{}) (val interface{}, rt reflect.Type, rv reflect.Value val = uint32(rv.Uint()) case reflect.Uint64: val = rv.Uint() - case reflect.Uintptr: - val = uintptr(rv.Uint()) case reflect.Float32: val = float32(rv.Float()) case reflect.Float64: val = rv.Float() - case reflect.Complex64: - val = complex64(rv.Complex()) - case reflect.Complex128: - val = rv.Complex() case reflect.String: val = rv.String() - default: - val = rv.Interface() + case reflect.Slice: + // []byte + if rv.Type().Elem().Kind() == reflect.Uint8 { + val = rv.Bytes() + } } return