diff --git a/protocol/client_codec.go b/protocol/client_codec.go index ecee9c5..e8d4f1a 100644 --- a/protocol/client_codec.go +++ b/protocol/client_codec.go @@ -22,7 +22,7 @@ type ClientCodecResponseOrNotify interface { type ClientCodecResponse interface { ID() interface{} - Result() interface{} + Result(result interface{}) error Error() error Complete() } diff --git a/protocol/json/client.go b/protocol/json/client.go index 33f9f30..0d05df3 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -32,10 +32,10 @@ type clientRequest struct { // clientResponse represents a JSON-RPC response returned to a client. type clientResponse struct { - Version string `json:"jsonrpc"` - Result interface{} `json:"result,omitempty"` - Error error `json:"error,omitempty"` - ID interface{} `json:"id"` + Version string `json:"jsonrpc"` + Result *json.RawMessage `json:"result,omitempty"` + Error error `json:"error,omitempty"` + ID interface{} `json:"id"` } // clientRequest represents a JSON-RPC request sent by a client. diff --git a/protocol/json/client_response.go b/protocol/json/client_response.go index b1d29db..4d4a3cd 100644 --- a/protocol/json/client_response.go +++ b/protocol/json/client_response.go @@ -47,8 +47,16 @@ func (ccr *ClientCodecResponse) ID() interface{} { return ccr.response.ID } -func (ccr *ClientCodecResponse) Result() interface{} { - return ccr.response.Result +func (ccr *ClientCodecResponse) Result(result interface{}) error { + if ccr.err == nil && ccr.response.Result != nil { + if err := json.Unmarshal(*ccr.response.Result, result); err != nil { + params := [1]interface{}{result} + if err = json.Unmarshal(*ccr.response.Result, ¶ms); err != nil { + ccr.err = err + } + } + } + return ccr.err } func (ccr *ClientCodecResponse) Error() error {