39 lines
773 B
Go
39 lines
773 B
Go
|
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)
|
||
|
}
|