/
point.go
61 lines (51 loc) · 1.33 KB
/
point.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
60
61
package common
import (
"encoding/gob"
"sync"
"time"
)
// Point wraps a single data point. It stores database-agnostic data
// representing one point in time of one measurement.
//
// Internally, Point uses byte slices instead of strings to try to minimize
// overhead.
type Point struct {
MeasurementName []byte
TagKeys [][]byte
TagValues [][]byte
FieldKeys [][]byte
FieldValues []interface{}
Timestamp *time.Time
encoder *gob.Encoder
}
// Using these literals prevents the slices from escaping to the heap, saving
// a few micros per call:
var ()
// scratchBufPool helps reuse serialization scratch buffers.
var scratchBufPool = &sync.Pool{
New: func() interface{} {
return make([]byte, 0, 1024)
},
}
func (p *Point) Reset() {
p.MeasurementName = nil
p.TagKeys = p.TagKeys[:0]
p.TagValues = p.TagValues[:0]
p.FieldKeys = p.FieldKeys[:0]
p.FieldValues = p.FieldValues[:0]
p.Timestamp = nil
}
func (p *Point) SetTimestamp(t *time.Time) {
p.Timestamp = t
}
func (p *Point) SetMeasurementName(s []byte) {
p.MeasurementName = s
}
func (p *Point) AppendTag(key, value []byte) {
p.TagKeys = append(p.TagKeys, key)
p.TagValues = append(p.TagValues, value)
}
func (p *Point) AppendField(key []byte, value interface{}) {
p.FieldKeys = append(p.FieldKeys, key)
p.FieldValues = append(p.FieldValues, value)
}