Skip to content

Commit

Permalink
support indirect type for []byte
Browse files Browse the repository at this point in the history
* support indirect type for []byte
    eg: `type NewBytes []byte`
* remove unused complex/uintptr
  • Loading branch information
shockerli committed Oct 6, 2021
1 parent 7438130 commit 63287df
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions cvte.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 63287df

Please sign in to comment.