diff --git a/protocol/json/client.go b/protocol/json/client.go index bce8333..bf52930 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -158,14 +158,18 @@ func (ccrn *ClientCodecResponseOrNotify) Complete() { var clientRequestPool sync.Pool func retainClientRequest(method string, params interface{}, id interface{}) *clientRequest { + var cr *clientRequest v := clientRequestPool.Get() if v == nil { - return &clientRequest{} + cr = &clientRequest{} + } else { + cr = v.(*clientRequest) } - cr := v.(*clientRequest) + cr.Method = method cr.Params = params cr.ID = id + return cr } diff --git a/protocol/json/server.go b/protocol/json/server.go index 566c1d6..4e50388 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -226,12 +226,14 @@ type EmptyResponse struct { var serverCodecRequestPool sync.Pool func retainServerCodecRequest(request *serverRequest, err error, encoder encode.Encoder) *ServerCodecRequest { + var scr *ServerCodecRequest v := serverCodecRequestPool.Get() if v == nil { - return &ServerCodecRequest{} + scr = &ServerCodecRequest{} + } else { + scr = v.(*ServerCodecRequest) } - scr := v.(*ServerCodecRequest) scr.request = request scr.err = err scr.encoder = encoder @@ -268,11 +270,14 @@ func releaseServerRequest(sr *serverRequest) { var serverResponsePool sync.Pool func retainServerResponse(version string, result interface{}, err *Error, id *json.RawMessage) *serverResponse { + var sr *serverResponse v := serverResponsePool.Get() if v == nil { - return &serverResponse{} + sr = &serverResponse{} + } else { + sr = v.(*serverResponse) } - sr := v.(*serverResponse) + sr.Version = version sr.Result = result sr.Error = err