diff --git a/protocol/json/client_notify.go b/protocol/json/client_notify.go index d5ea9aa..2fb5762 100644 --- a/protocol/json/client_notify.go +++ b/protocol/json/client_notify.go @@ -47,7 +47,7 @@ func (ccn *ClientCodecNotify) Method() string { return ccn.notify.Method } -func (ccn *ClientCodecNotify) ReadParams(args []interface{}) error { +func (ccn *ClientCodecNotify) ReadParams(args *[]interface{}) error { if ccn.err == nil && ccn.notify.Params != nil { // Note: if scr.request.Params is nil it's not an error, it's an optional member. // JSON params structured object. Unmarshal to the args object. diff --git a/protocol/json/server.go b/protocol/json/server.go index 878122e..fc580ff 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -160,11 +160,11 @@ func (scr *ServerCodecRequest) Method() string { // absence of expected names MAY result in an error being // generated. The names MUST match exactly, including // case, to the method's expected parameters. -func (scr *ServerCodecRequest) ReadParams(args []interface{}) error { +func (scr *ServerCodecRequest) ReadParams(args *[]interface{}) error { if scr.err == nil && scr.request.Params != nil { // Note: if scr.request.Params is nil it's not an error, it's an optional member. // JSON params structured object. Unmarshal to the args object. - if err := json.Unmarshal(*scr.request.Params, &args); err != nil { + if err := json.Unmarshal(*scr.request.Params, args); err != nil { // Clearly JSON params is not a structured object, // fallback and attempt an unmarshal with JSON params as // array value and RPC params is struct. Unmarshal into diff --git a/protocol/registry_codec.go b/protocol/registry_codec.go index 61d76ca..d4fa450 100644 --- a/protocol/registry_codec.go +++ b/protocol/registry_codec.go @@ -8,6 +8,6 @@ type RegistryCodec interface { // Reads the request and returns the RPC method name. Method() string // Reads the request filling the RPC method args. - ReadParams([]interface{}) error + ReadParams(args *[]interface{}) error Complete() } diff --git a/registry.go b/registry.go index 8f926b2..2984ed9 100644 --- a/registry.go +++ b/registry.go @@ -77,16 +77,16 @@ func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec) (result interface{}, // Decode the args. var in []reflect.Value - paramValues := methodSpec.paramValues + params := methodSpec.getInterfaces() - if nil != paramValues { - params := methodSpec.getInterfaces() - if errRead := codec.ReadParams(params); errRead != nil { + if nil != params && 0 < len(params) { + if errRead := codec.ReadParams(¶ms); errRead != nil { return nil, errRead } - in = make([]reflect.Value, len(paramValues)+1) - for indexI := 0; indexI < len(paramValues); indexI++ { - in[indexI+1] = paramValues[indexI] + pCount := len(params) + in = make([]reflect.Value, pCount+1) + for indexI := 0; indexI < pCount; indexI++ { + in[indexI+1] = reflect.ValueOf(params[indexI]) } } else { in = make([]reflect.Value, 1)