influxdb/tsdb/tsm1/array_encoding.go

125 lines
3.1 KiB
Go
Raw Normal View History

2018-09-26 17:39:21 +00:00
package tsm1
import (
"fmt"
"github.com/influxdata/influxdb/tsdb"
2018-09-26 17:39:21 +00:00
)
// 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
}
2018-09-05 10:45:15 +00:00
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
2018-09-26 17:39:21 +00:00
if err != nil {
return err
}
2018-09-05 10:40:21 +00:00
a.Values, err = BooleanArrayDecodeAll(vb, a.Values)
2018-09-26 17:39:21 +00:00
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
}
2018-09-05 10:45:15 +00:00
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
2018-09-26 17:39:21 +00:00
if err != nil {
return err
}
2018-09-05 10:13:11 +00:00
a.Values, err = FloatArrayDecodeAll(vb, a.Values)
2018-09-26 17:39:21 +00:00
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
}
2018-09-05 10:45:15 +00:00
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
2018-09-26 17:39:21 +00:00
if err != nil {
return err
}
2018-09-05 10:30:29 +00:00
a.Values, err = IntegerArrayDecodeAll(vb, a.Values)
2018-09-26 17:39:21 +00:00
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
}
2018-09-05 10:45:15 +00:00
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
2018-09-26 17:39:21 +00:00
if err != nil {
return err
}
2018-09-05 10:41:16 +00:00
a.Values, err = UnsignedArrayDecodeAll(vb, a.Values)
2018-09-26 17:39:21 +00:00
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
}
2018-09-05 10:45:15 +00:00
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
2018-09-26 17:39:21 +00:00
if err != nil {
return err
}
2018-09-05 10:41:01 +00:00
a.Values, err = StringArrayDecodeAll(vb, a.Values)
2018-09-26 17:39:21 +00:00
return err
}
// DecodeTimestampArrayBlock decodes the timestamps from the specified
// block, ignoring the block type and the values.
func DecodeTimestampArrayBlock(block []byte, a *tsdb.TimestampArray) error {
tb, _, err := unpackBlock(block[1:])
if err != nil {
return err
}
a.Timestamps, err = TimeArrayDecodeAll(tb, a.Timestamps)
return err
}