convert float64 to int
This commit is contained in:
parent
bd0e0d8fec
commit
803ad02772
@ -124,8 +124,19 @@ func (ipc *ipcCommon) handleCall(msg Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var args []reflect.Value
|
var args []reflect.Value
|
||||||
for _, param := range msg.Params {
|
for i, arg := range msg.Args {
|
||||||
args = append(args, reflect.ValueOf(param))
|
paramType := method.Type().In(i)
|
||||||
|
argType := reflect.TypeOf(arg)
|
||||||
|
|
||||||
|
// JSON decodes any number to float64. If we need int, we should check and convert
|
||||||
|
if paramType.Kind() == reflect.Int && argType.Kind() == reflect.Float64 {
|
||||||
|
floatArg := arg.(float64)
|
||||||
|
if float64(int64(floatArg)) == floatArg && !paramType.OverflowInt(int64(floatArg)) {
|
||||||
|
arg = arg.(int)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, reflect.ValueOf(paramType))
|
||||||
}
|
}
|
||||||
|
|
||||||
results := method.Call(args)
|
results := method.Call(args)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user