-
Notifications
You must be signed in to change notification settings - Fork 4
/
receivers.go
59 lines (47 loc) · 1.03 KB
/
receivers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package silk
type FlowReceiver interface {
HandleHeader(h Header)
HandleFlow(f Flow)
Close()
}
type SliceFlowReceiver struct {
File
}
func NewSliceFlowReceiver(initialSize int) *SliceFlowReceiver {
return &SliceFlowReceiver{
File{
Flows: make([]Flow, 0, initialSize),
},
}
}
func (a *SliceFlowReceiver) HandleHeader(h Header) {
a.Header = h
}
func (a *SliceFlowReceiver) HandleFlow(f Flow) {
a.Flows = append(a.Flows, f)
}
func (a *SliceFlowReceiver) Close() {
// Nothing to do in the slice case
}
type ChannelFlowReceiver struct {
Header Header
rwChannel chan Flow
}
func NewChannelFlowReceiver(channelBufferSize int) *ChannelFlowReceiver {
rwChannel := make(chan Flow, channelBufferSize)
return &ChannelFlowReceiver{
rwChannel: rwChannel,
}
}
func (c ChannelFlowReceiver) Read() <-chan Flow {
return c.rwChannel
}
func (c *ChannelFlowReceiver) HandleHeader(h Header) {
c.Header = h
}
func (c *ChannelFlowReceiver) HandleFlow(f Flow) {
c.rwChannel <- f
}
func (c *ChannelFlowReceiver) Close() {
close(c.rwChannel)
}