Documentation ¶
Overview ¶
Package encoding handles encoding of zenodb data in binary form.
Index ¶
- Constants
- Variables
- func EncodeTime(b []byte, ts time.Time)
- func Read(b []byte, l int) ([]byte, []byte)
- func ReadByteMap(b []byte, l int) (bytemap.ByteMap, []byte)
- func ReadInt16(b []byte) (int, []byte)
- func ReadInt32(b []byte) (int, []byte)
- func ReadInt64(b []byte) (int, []byte)
- func RoundTimeDown(ts time.Time, resolution time.Duration) time.Time
- func RoundTimeUntilDown(ts time.Time, resolution time.Duration, until time.Time) time.Time
- func RoundTimeUntilUp(ts time.Time, resolution time.Duration, until time.Time) time.Time
- func RoundTimeUp(ts time.Time, resolution time.Duration) time.Time
- func TimeFromBytes(b []byte) time.Time
- func TimeFromInt(ts int64) time.Time
- func TimeFromMillis(millis int64) time.Time
- func TimeIntFromBytes(b []byte) int64
- func Write(b []byte, d []byte) []byte
- func WriteInt16(b []byte, i int) []byte
- func WriteInt32(b []byte, i int) []byte
- func WriteInt64(b []byte, i int) []byte
- type Sequence
- func (seq Sequence) AsOf(width int, resolution time.Duration) time.Time
- func (seq Sequence) DataLength() int
- func (seq Sequence) Merge(other Sequence, e expr.Expr, resolution time.Duration, ...) Sequence
- func (seq Sequence) NumPeriods(width int) int
- func (seq Sequence) SetUntil(t time.Time)
- func (seq Sequence) String(e expr.Expr, resolution time.Duration) string
- func (seq Sequence) SubMerge(other Sequence, metadata goexpr.Params, resolution time.Duration, ...) (result Sequence)
- func (seq Sequence) Truncate(width int, resolution time.Duration, asOf time.Time, until time.Time) (result Sequence)
- func (seq Sequence) Until() time.Time
- func (seq Sequence) UntilInt() int64
- func (seq Sequence) Update(tsp TSParams, metadata goexpr.Params, e expr.Expr, resolution time.Duration, ...) Sequence
- func (seq Sequence) UpdateValue(ts time.Time, params expr.Params, metadata goexpr.Params, e expr.Expr, ...) Sequence
- func (seq Sequence) UpdateValueAt(period int, e expr.Expr, params expr.Params, metadata goexpr.Params)
- func (seq Sequence) UpdateValueAtOffset(offset int, e expr.Expr, params expr.Params, metadata goexpr.Params)
- func (seq Sequence) ValueAt(period int, e expr.Expr) (val float64, found bool)
- func (seq Sequence) ValueAtOffset(offset int, e expr.Expr) (val float64, found bool)
- func (seq Sequence) ValueAtTime(t time.Time, e expr.Expr, resolution time.Duration) (val float64, found bool)
- type TSParams
Constants ¶
const ( Width16bits = 2 Width32bits = 4 Width64bits = 8 )
const (
WidthTime = Width64bits
)
Variables ¶
var ( // Binary is the standard number encoding for zenodb Binary = binary.BigEndian )
Functions ¶
func EncodeTime ¶
func RoundTimeUntilDown ¶
func RoundTimeUntilUp ¶
func TimeFromBytes ¶
func TimeFromInt ¶
func TimeFromMillis ¶
func TimeIntFromBytes ¶
func WriteInt16 ¶
func WriteInt32 ¶
func WriteInt64 ¶
Types ¶
type Sequence ¶
type Sequence []byte
Sequence represents a time-ordered sequence of accumulator states in descending time order. The first 8 bytes are the timestamp at which the Sequence ends, and after that each n bytes are data for the next interval in the Sequence going back in time, where n is determined by the type of Expr.
func NewFloatValue ¶
NewFloatValue makes a single-value sequence from a simple expression, timestamp float value.
func NewSequence ¶
NewSequence allocates a new Sequence that holds the given number of periods with accumulator states of the given width.
func NewValue ¶
NewValue makes a single-value sequence from a simple expression, timestamp, params and metadata.
func (Sequence) DataLength ¶
DataLength returns the number of bytes in this Sequence excluding the start time.
func (Sequence) Merge ¶
func (seq Sequence) Merge(other Sequence, e expr.Expr, resolution time.Duration, truncateBefore time.Time) Sequence
Merge merges the other Sequence into this Sequence by applying the given Expr's merge operator to each period in both Sequences. The resulting Sequence will start at the early of the two Sequence's start times, and will end at the later of the two Sequence's start times, or at the given truncateBefore if that's later.
The returned Sequence may reference the same underlying byte array as one or the other Sequence if nothing needed merging, otherwise it will be a newly allocated byte array. Merge will NOT update either of the supplied arrays.
func (Sequence) NumPeriods ¶
NumPeriods returns the number of periods in this Sequence assuming the given width.
func (Sequence) String ¶
String provides a string representation of this Sequence assuming that it holds data for the given Expr.
func (Sequence) Truncate ¶
func (seq Sequence) Truncate(width int, resolution time.Duration, asOf time.Time, until time.Time) (result Sequence)
Truncate truncates all periods in the Sequence that fall outside of the given asOf and until.
func (Sequence) UntilInt ¶
Until returns the most recent date represented by this Sequence as an integer
func (Sequence) Update ¶
func (seq Sequence) Update(tsp TSParams, metadata goexpr.Params, e expr.Expr, resolution time.Duration, truncateBefore time.Time) Sequence
Update unpacks the given TSParams and calls UpdateValue.
func (Sequence) UpdateValue ¶
func (seq Sequence) UpdateValue(ts time.Time, params expr.Params, metadata goexpr.Params, e expr.Expr, resolution time.Duration, truncateBefore time.Time) Sequence
UpdateValue updates the value at the given time by applying the given params using the given Expr. The resolution indicates how wide we assume each period of data to be. Any values in the sequence older than truncateBefore including the new value) will be omitted from the sequence. If the sequence needs to be grown to accommodate the updated value, it will be. metadata represents metadata about the operation that's used by the Expr as well (e.g. information about the dimensions associated to the value).
The returned Sequence may reference the same underlying byte array as the updated sequence, or it may be a newly allocated byte array (i.e. if the sequence grew).
func (Sequence) UpdateValueAt ¶
func (seq Sequence) UpdateValueAt(period int, e expr.Expr, params expr.Params, metadata goexpr.Params)
UpdateValueAt updates the value at the given period by applying the supplied Params to the given expression. metadata represents metadata about the operation that's used by the Expr as well (e.g. information about the dimensions associated to the value).
func (Sequence) UpdateValueAtOffset ¶
func (seq Sequence) UpdateValueAtOffset(offset int, e expr.Expr, params expr.Params, metadata goexpr.Params)
UpdateValueAtOffset updates the value at the given byte offset by applying the supplied Params to the given expression. metadata represents metadata about the operation that's used by the Expr as well (e.g. information about the dimensions associated to the value).
func (Sequence) ValueAt ¶
ValueAt returns the value at the given period extracted using the given Expr. If no value is set for the given period, found will be false.
func (Sequence) ValueAtOffset ¶
ValueAtOffset returns the value at the given byte offset in the Sequence (not including the start time) extracted using the given Expr. If no value is set for the given offset, found will be false.
func (Sequence) ValueAtTime ¶
func (seq Sequence) ValueAtTime(t time.Time, e expr.Expr, resolution time.Duration) (val float64, found bool)
ValueAtTime returns the value at the given time within this sequence, extracted using the given Expr and assuming each period represents 1 * resolution. If no value is set for the given time, found will be false.
type TSParams ¶
type TSParams []byte
TSParams combines a timestamp with a ByteMap.
func NewTSParams ¶
NewTSParams constructs a new TSParams using the given Time and ByteMap.
func (TSParams) TimeAndParams ¶
TimeAndParams returns the Time and Params components of this TSParams.