ing
This commit is contained in:
parent
f9912b5cf0
commit
5f64fccd7c
|
@ -123,6 +123,24 @@ func (src *ServerRequestCodec) Params() ([]string, error) {
|
|||
}
|
||||
|
||||
func (src *ServerRequestCodec) NewResponse(reply interface{}, err error) ([]byte, error) {
|
||||
res := src.newServerResponse(reply, err)
|
||||
return json.Marshal(res)
|
||||
}
|
||||
|
||||
func (src *ServerRequestCodec) NewResponseWithString(reply string, err error) ([]byte, error) {
|
||||
res := src.newServerResponse(nil, err)
|
||||
|
||||
var i interface{}
|
||||
mErr := json.Unmarshal([]byte(reply), &i)
|
||||
if nil != mErr {
|
||||
return nil, mErr
|
||||
}
|
||||
|
||||
res.Result = i
|
||||
return json.Marshal(res)
|
||||
}
|
||||
|
||||
func (src *ServerRequestCodec) newServerResponse(reply interface{}, err error) *serverResponse {
|
||||
res := &serverResponse{Version: Version, Result: reply, ID: src.req.ID}
|
||||
|
||||
if nil != err {
|
||||
|
@ -136,10 +154,5 @@ func (src *ServerRequestCodec) NewResponse(reply interface{}, err error) ([]byte
|
|||
res.Error = jsonErr
|
||||
}
|
||||
|
||||
return src.newServerResponse(res)
|
||||
}
|
||||
|
||||
func (src *ServerRequestCodec) newServerResponse(res *serverResponse) ([]byte, error) {
|
||||
|
||||
return json.Marshal(res)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -14,4 +14,5 @@ type ServerRequestCodec interface {
|
|||
|
||||
HasResponse() bool
|
||||
NewResponse(reply interface{}, err error) ([]byte, error)
|
||||
NewResponseWithString(reply string, err error) ([]byte, error)
|
||||
}
|
||||
|
|
|
@ -100,13 +100,31 @@ func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec, leadingParams ...int
|
|||
|
||||
var in []reflect.Value
|
||||
pValues, pInstances := methodSpec.getParamValues()
|
||||
var lParamLen int
|
||||
if nil != leadingParams {
|
||||
lParamLen = len(leadingParams)
|
||||
}
|
||||
|
||||
if nil != pInstances && 0 < len(pInstances) {
|
||||
if errRead := codec.ReadParams(pInstances); errRead != nil {
|
||||
if errRead := codec.ReadParams(pInstances[lParamLen:]); errRead != nil {
|
||||
return nil, errRead
|
||||
}
|
||||
|
||||
for indexI := 0; indexI < lParamLen; indexI++ {
|
||||
i := pInstances[indexI]
|
||||
rv := reflect.ValueOf(i)
|
||||
iv := reflect.ValueOf(leadingParams[indexI])
|
||||
switch reflect.TypeOf(i).Elem().Kind() {
|
||||
case reflect.Struct:
|
||||
rv.Elem().Set(iv.Elem())
|
||||
default:
|
||||
rv.Elem().Set(iv)
|
||||
}
|
||||
}
|
||||
|
||||
pCount := len(pInstances)
|
||||
in = make([]reflect.Value, pCount+1)
|
||||
|
||||
for indexI := 0; indexI < pCount; indexI++ {
|
||||
if pValues[indexI].Type().Kind() == reflect.Ptr && pValues[indexI].Type().Elem().Kind() != reflect.Struct {
|
||||
in[indexI+1] = reflect.Indirect(pValues[indexI])
|
||||
|
|
Loading…
Reference in New Issue
Block a user