forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
values.go
139 lines (110 loc) · 2.02 KB
/
values.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package tsdb
import (
"fmt"
"time"
tsm "github.com/influxdb/influxdb/tsdb/engine/tsm1"
)
type FloatValue struct {
T time.Time
V float64
}
func (f *FloatValue) Time() time.Time {
return f.T
}
func (f *FloatValue) UnixNano() int64 {
return f.T.UnixNano()
}
func (f *FloatValue) Value() interface{} {
return f.V
}
func (f *FloatValue) Size() int {
return 16
}
func (f *FloatValue) String() string {
return fmt.Sprintf("%v %v", f.Time(), f.Value())
}
type BoolValue struct {
T time.Time
V bool
}
func (b *BoolValue) Time() time.Time {
return b.T
}
func (b *BoolValue) Size() int {
return 9
}
func (b *BoolValue) UnixNano() int64 {
return b.T.UnixNano()
}
func (b *BoolValue) Value() interface{} {
return b.V
}
func (f *BoolValue) String() string {
return fmt.Sprintf("%v %v", f.Time(), f.Value())
}
type Int64Value struct {
T time.Time
V int64
}
func (v *Int64Value) Time() time.Time {
return v.T
}
func (v *Int64Value) Value() interface{} {
return v.V
}
func (v *Int64Value) UnixNano() int64 {
return v.T.UnixNano()
}
func (v *Int64Value) Size() int {
return 16
}
func (f *Int64Value) String() string {
return fmt.Sprintf("%v %v", f.Time(), f.Value())
}
type StringValue struct {
T time.Time
V string
}
func (v *StringValue) Time() time.Time {
return v.T
}
func (v *StringValue) Value() interface{} {
return v.V
}
func (v *StringValue) UnixNano() int64 {
return v.T.UnixNano()
}
func (v *StringValue) Size() int {
return 8 + len(v.V)
}
func (f *StringValue) String() string {
return fmt.Sprintf("%v %v", f.Time(), f.Value())
}
func ConvertToValue(k int64, v interface{}) tsm.Value {
var value tsm.Value
switch v := v.(type) {
case int64:
value = &Int64Value{
T: time.Unix(0, k),
V: v,
}
case float64:
value = &FloatValue{
T: time.Unix(0, k),
V: v,
}
case bool:
value = &BoolValue{
T: time.Unix(0, k),
V: v,
}
case string:
value = &StringValue{
T: time.Unix(0, k),
V: v,
}
default:
panic(fmt.Sprintf("value type %T unsupported for conversion", v))
}
return value
}