You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/12/16 00:44:33 UTC
[GitHub] [dubbo-go-hessian2] wongoo commented on a change in pull request #297: fix basic type alias cann't parse to basic type bug
wongoo commented on a change in pull request #297:
URL: https://github.com/apache/dubbo-go-hessian2/pull/297#discussion_r770143404
##########
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.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org