rpc/protocol/json/server_notification.go

39 lines
773 B
Go
Raw Normal View History

2017-11-26 10:15:51 +00:00
package json
import (
"sync"
)
// clientRequest represents a JSON-RPC request sent by a client.
type serverNotification struct {
// 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"`
}
var serverNotificationPool sync.Pool
func retainServerNotification(method string, args interface{}) *serverNotification {
var sn *serverNotification
v := serverNotificationPool.Get()
if v == nil {
sn = &serverNotification{}
} else {
sn = v.(*serverNotification)
}
sn.Method = method
sn.Params = args
return sn
}
func releaseServerNotification(sn *serverNotification) {
sn.Method = ""
sn.Params = nil
serverNotificationPool.Put(sn)
}