forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffered.go
30 lines (25 loc) · 845 Bytes
/
buffered.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
package edge
type BufferedReceiver interface {
Receiver
// BufferedBatch processes an entire buffered batch.
// Do not modify the batch or the slice of Points as it is shared.
BufferedBatch(batch BufferedBatchMessage) error
}
// BatchBuffer buffers batch messages into a BufferedBatchMessage.
type BatchBuffer struct {
begin BeginBatchMessage
points []BatchPointMessage
}
func (r *BatchBuffer) BeginBatch(begin BeginBatchMessage) error {
r.begin = begin.ShallowCopy()
r.points = make([]BatchPointMessage, 0, begin.SizeHint())
return nil
}
func (r *BatchBuffer) BatchPoint(bp BatchPointMessage) error {
r.points = append(r.points, bp)
return nil
}
func (r *BatchBuffer) BufferedBatchMessage(end EndBatchMessage) BufferedBatchMessage {
r.begin.SetSizeHint(len(r.points))
return NewBufferedBatchMessage(r.begin, r.points, end)
}