This commit is contained in:
crusader 2017-11-03 21:23:12 +09:00
parent 62fcae57f7
commit d466ca204b
3 changed files with 36 additions and 16 deletions

View File

@ -3,7 +3,6 @@ package json
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"log"
"sync" "sync"
"git.loafle.net/commons_go/rpc/encode" "git.loafle.net/commons_go/rpc/encode"
@ -177,20 +176,28 @@ func (scr *ServerCodecRequest) ReadParams(args []interface{}) error {
// Data: scr.request.Params, // Data: scr.request.Params,
// } // }
// } // }
jss := make([]json.RawMessage, len(args)) raws := make([]json.RawMessage, len(args))
if err := json.Unmarshal(*scr.request.Params, &jss); err != nil { if err := json.Unmarshal(*scr.request.Params, &raws); err != nil {
log.Printf("err:%v", err) scr.err = &Error{
Code: E_INVALID_REQ,
Message: err.Error(),
Data: scr.request.Params,
}
return scr.err
} }
for indexI := 0; indexI < len(args); indexI++ { for indexI := 0; indexI < len(args); indexI++ {
js := jss[indexI] raw := raws[indexI]
arg := args[indexI] arg := args[indexI]
if err := json.Unmarshal(js, &arg); err != nil { if err := json.Unmarshal(raw, &arg); err != nil {
log.Printf("err:%v", err) scr.err = &Error{
Code: E_INVALID_REQ,
Message: err.Error(),
Data: scr.request.Params,
}
return scr.err
} }
} }
} }
return scr.err return scr.err
} }

View File

@ -86,8 +86,11 @@ func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec) (result interface{},
pCount := len(pInstances) pCount := len(pInstances)
in = make([]reflect.Value, pCount+1) in = make([]reflect.Value, pCount+1)
for indexI := 0; indexI < pCount; indexI++ { for indexI := 0; indexI < pCount; indexI++ {
in[indexI+1] = pValues[indexI] if pValues[indexI].Type().Kind() == reflect.Ptr && pValues[indexI].Type().Elem().Kind() != reflect.Struct {
//in[indexI+1] = reflect.ValueOf(pInstances[indexI]).Convert(methodSpec.paramTypes[indexI]) in[indexI+1] = reflect.Indirect(pValues[indexI])
} else {
in[indexI+1] = pValues[indexI]
}
} }
} else { } else {
in = make([]reflect.Value, 1) in = make([]reflect.Value, 1)

View File

@ -54,11 +54,21 @@ func getValue(t reflect.Type) reflect.Value {
rt = rt.Elem() rt = rt.Elem()
} }
rv := reflect.New(rt) // rv := reflect.New(rt)
if rt.Kind() != reflect.Struct { // if rt.Kind() != reflect.Struct {
rv = reflect.Indirect(rv) // rv = reflect.Indirect(rv)
} // }
return rv
// var rv reflect.Value
// switch rt.Kind() {
// case reflect.Slice:
// rv = reflect.New(reflect.SliceOf(rt.Elem()))
// default:
// rv = reflect.New(rt)
// }
return reflect.New(rt)
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------