luky116 commented on a change in pull request #297:
URL: https://github.com/apache/dubbo-go-hessian2/pull/297#discussion_r770155913



##########
File path: codec.go
##########
@@ -196,48 +196,32 @@ func SprintHex(b []byte) (rs string) {
 
 // EnsureFloat64 convert i to float64
 func EnsureFloat64(i interface{}) float64 {
-       if i64, ok := i.(float64); ok {
-               return i64
-       }
-       if i32, ok := i.(float32); ok {
-               return float64(i32)
+       v := reflect.ValueOf(i)
+       k := v.Kind()
+       if k == reflect.Float32 || k == reflect.Float64 {
+               return v.Float()
        }
        panic(fmt.Errorf("can't convert to float64: %v, type:%v", i, 
reflect.TypeOf(i)))
 }
 
 // EnsureInt64 convert i to int64
 func EnsureInt64(i interface{}) int64 {
-       if i64, ok := i.(int64); ok {
-               return i64
-       }
-       if i32, ok := i.(int32); ok {
-               return int64(i32)
-       }
-       if i, ok := i.(int); ok {
-               return int64(i)
-       }
-       if i16, ok := i.(int16); ok {
-               return int64(i16)
-       }
-       if i8, ok := i.(int8); ok {
-               return int64(i8)
+       v := reflect.ValueOf(i)
+       k := v.Kind()
+       if k == reflect.Int || k == reflect.Int8 || k == reflect.Int16 ||

Review comment:
       > @luky116 I can't get what's the difference between the pr implement 
and the original.
   
   if param i is a type alias of int, it can't convert to int64 value through 
the original logic




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to