-
Notifications
You must be signed in to change notification settings - Fork 84
/
encoding.go
93 lines (84 loc) · 2.86 KB
/
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
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// Package encoding implements encoding/decoding data points.
package encoding
// SeriesEncoderPool allows putting and getting SeriesEncoder.
type SeriesEncoderPool interface {
Get(metadata []byte, buffer BufferWriter) SeriesEncoder
Put(encoder SeriesEncoder)
}
// SeriesEncoder encodes time series data point.
type SeriesEncoder interface {
// Append a data point
Append(ts uint64, value []byte)
// IsFull returns whether the encoded data reached its capacity
IsFull() bool
// Reset the underlying buffer
Reset(key []byte, buffer BufferWriter)
// Encode the time series data point to a binary
Encode() error
// StartTime indicates the first entry's time
StartTime() uint64
}
// SeriesDecoderPool allows putting and getting SeriesDecoder.
type SeriesDecoderPool interface {
Get(metadata []byte) SeriesDecoder
Put(encoder SeriesDecoder)
}
// SeriesDecoder decodes encoded time series data.
type SeriesDecoder interface {
// Decode the time series data
Decode(key, data []byte) error
// Len denotes the size of iterator
Len() int
// IsFull returns whether the encoded data reached its capacity
IsFull() bool
// Get the data point by its time
Get(ts uint64) ([]byte, error)
// Iterator returns a SeriesIterator
Iterator() SeriesIterator
// Range returns the start and end time of this series
Range() (start, end uint64)
}
// SeriesIterator iterates time series data.
type SeriesIterator interface {
// Next scroll the cursor to the next
Next() bool
// Val returns the value of the current data point
Val() []byte
// Time returns the time of the current data point
Time() uint64
// Error might return an error indicates a decode failure
Error() error
}
// BufferWriter allows writing a variable-sized buffer of bytes.
type BufferWriter interface {
Write(data []byte) (n int, err error)
WriteByte(b byte) error
Bytes() []byte
}
// EncodeType indicates the encoding type of a series.
type EncodeType byte
// EncodeType constants.
const (
EncodeTypeUnknown EncodeType = iota
EncodeTypeConst
EncodeTypeDeltaConst
EncodeTypeDelta
EncodeTypeDeltaOfDelta
EncodeTypeXOR
)