forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_encoding.go
112 lines (95 loc) · 2.76 KB
/
array_encoding.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
package tsm1
import (
"fmt"
"github.com/influxdata/influxdb/tsdb"
)
// DecodeBooleanArrayBlock decodes the boolean block from the byte slice
// and writes the values to a.
func DecodeBooleanArrayBlock(block []byte, a *tsdb.BooleanArray) error {
blockType := block[0]
if blockType != BlockBoolean {
return fmt.Errorf("invalid block type: exp %d, got %d", BlockBoolean, blockType)
}
tb, vb, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
if err != nil {
return err
}
a.Values, err = BooleanArrayDecodeAll(vb, a.Values)
return err
}
// DecodeFloatArrayBlock decodes the float block from the byte slice
// and writes the values to a.
func DecodeFloatArrayBlock(block []byte, a *tsdb.FloatArray) error {
blockType := block[0]
if blockType != BlockFloat64 {
return fmt.Errorf("invalid block type: exp %d, got %d", BlockFloat64, blockType)
}
tb, vb, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
if err != nil {
return err
}
a.Values, err = FloatArrayDecodeAll(vb, a.Values)
return err
}
// DecodeIntegerArrayBlock decodes the integer block from the byte slice
// and writes the values to a.
func DecodeIntegerArrayBlock(block []byte, a *tsdb.IntegerArray) error {
blockType := block[0]
if blockType != BlockInteger {
return fmt.Errorf("invalid block type: exp %d, got %d", BlockInteger, blockType)
}
tb, vb, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
if err != nil {
return err
}
a.Values, err = IntegerArrayDecodeAll(vb, a.Values)
return err
}
// DecodeUnsignedArrayBlock decodes the unsigned integer block from the byte slice
// and writes the values to a.
func DecodeUnsignedArrayBlock(block []byte, a *tsdb.UnsignedArray) error {
blockType := block[0]
if blockType != BlockUnsigned {
return fmt.Errorf("invalid block type: exp %d, got %d", BlockUnsigned, blockType)
}
tb, vb, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
if err != nil {
return err
}
a.Values, err = UnsignedArrayDecodeAll(vb, a.Values)
return err
}
// DecodeStringArrayBlock decodes the string block from the byte slice
// and writes the values to a.
func DecodeStringArrayBlock(block []byte, a *tsdb.StringArray) error {
blockType := block[0]
if blockType != BlockString {
return fmt.Errorf("invalid block type: exp %d, got %d", BlockString, blockType)
}
tb, vb, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
if err != nil {
return err
}
a.Values, err = StringArrayDecodeAll(vb, a.Values)
return err
}