rpc/protocol/json/client_request.go
crusader 2286a5021e ing
2017-11-26 19:15:51 +09:00

52 lines
1.2 KiB
Go

package json
import "sync"
// ----------------------------------------------------------------------------
// Request and Response
// ----------------------------------------------------------------------------
// clientRequest represents a JSON-RPC request sent by a client.
type clientRequest struct {
// JSON-RPC protocol.
Version string `json:"jsonrpc"`
// A String containing the name of the method to be invoked.
Method string `json:"method"`
// Object to pass as request parameter to the method.
Params interface{} `json:"params"`
// The request id. This can be of any type. It is used to match the
// response with the request that it is replying to.
ID interface{} `json:"id"`
}
var clientRequestPool sync.Pool
func retainClientRequest(method string, params interface{}, id interface{}) *clientRequest {
var cr *clientRequest
v := clientRequestPool.Get()
if v == nil {
cr = &clientRequest{}
} else {
cr = v.(*clientRequest)
}
cr.Version = Version
cr.Method = method
cr.Params = params
cr.ID = id
return cr
}
func releaseClientRequest(cr *clientRequest) {
cr.Version = ""
cr.Method = ""
cr.Params = nil
cr.ID = nil
clientRequestPool.Put(cr)
}