71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
|
package discovery
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
|
||
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||
|
)
|
||
|
|
||
|
type ofDiscoveryMessage struct {
|
||
|
request types.DiscoveryRequest
|
||
|
messageType types.DiscoveryMessageType
|
||
|
data interface{}
|
||
|
err error
|
||
|
}
|
||
|
|
||
|
func (dm *ofDiscoveryMessage) Request() types.DiscoveryRequest {
|
||
|
return dm.request
|
||
|
}
|
||
|
|
||
|
func (dm *ofDiscoveryMessage) Type() types.DiscoveryMessageType {
|
||
|
return dm.messageType
|
||
|
}
|
||
|
|
||
|
func (dm *ofDiscoveryMessage) Result() interface{} {
|
||
|
return dm.data
|
||
|
}
|
||
|
|
||
|
func (dm *ofDiscoveryMessage) Error() error {
|
||
|
return dm.err
|
||
|
}
|
||
|
|
||
|
func (dm *ofDiscoveryMessage) Release() {
|
||
|
releaseDiscoveryMessage(dm)
|
||
|
}
|
||
|
|
||
|
func RetainDiscoveryMessage(request types.DiscoveryRequest, messageType types.DiscoveryMessageType, data interface{}, err error) *ofDiscoveryMessage {
|
||
|
return retainDiscoveryMessage(request, messageType, data, err)
|
||
|
}
|
||
|
|
||
|
func ReleaseDiscoveryMessage(dm *ofDiscoveryMessage) {
|
||
|
releaseDiscoveryMessage(dm)
|
||
|
}
|
||
|
|
||
|
var discoveryMessagePool sync.Pool
|
||
|
|
||
|
func retainDiscoveryMessage(request types.DiscoveryRequest, messageType types.DiscoveryMessageType, data interface{}, err error) *ofDiscoveryMessage {
|
||
|
v := discoveryMessagePool.Get()
|
||
|
var dm *ofDiscoveryMessage
|
||
|
if v == nil {
|
||
|
dm = &ofDiscoveryMessage{}
|
||
|
} else {
|
||
|
dm = v.(*ofDiscoveryMessage)
|
||
|
}
|
||
|
|
||
|
dm.request = request
|
||
|
dm.messageType = messageType
|
||
|
dm.data = data
|
||
|
dm.err = err
|
||
|
|
||
|
return dm
|
||
|
}
|
||
|
|
||
|
func releaseDiscoveryMessage(dm *ofDiscoveryMessage) {
|
||
|
dm.request = nil
|
||
|
dm.messageType = types.DiscoveryMessageTypeNone
|
||
|
dm.data = nil
|
||
|
dm.err = nil
|
||
|
|
||
|
discoveryMessagePool.Put(dm)
|
||
|
}
|