encoding

package
v0.0.0-...-df46cc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package encoding handles encoding of zenodb data in binary form.

Index

Constants

View Source
const (
	Width16bits = 2
	Width32bits = 4
	Width64bits = 8
)
View Source
const (
	WidthTime = Width64bits
)

Variables

View Source
var (
	// Binary is the standard number encoding for zenodb
	Binary = binary.BigEndian
)

Functions

func EncodeTime

func EncodeTime(b []byte, ts time.Time)

func Read

func Read(b []byte, l int) ([]byte, []byte)

func ReadByteMap

func ReadByteMap(b []byte, l int) (bytemap.ByteMap, []byte)

func ReadInt16

func ReadInt16(b []byte) (int, []byte)

func ReadInt32

func ReadInt32(b []byte) (int, []byte)

func ReadInt64

func ReadInt64(b []byte) (int, []byte)

func RoundTimeDown

func RoundTimeDown(ts time.Time, resolution time.Duration) time.Time

func RoundTimeUntilDown

func RoundTimeUntilDown(ts time.Time, resolution time.Duration, until time.Time) time.Time

func RoundTimeUntilUp

func RoundTimeUntilUp(ts time.Time, resolution time.Duration, until time.Time) time.Time

func RoundTimeUp

func RoundTimeUp(ts time.Time, resolution time.Duration) time.Time

func TimeFromBytes

func TimeFromBytes(b []byte) time.Time

func TimeFromInt

func TimeFromInt(ts int64) time.Time

func TimeFromMillis

func TimeFromMillis(millis int64) time.Time

func TimeIntFromBytes

func TimeIntFromBytes(b []byte) int64

func Write

func Write(b []byte, d []byte) []byte

func WriteInt16

func WriteInt16(b []byte, i int) []byte

func WriteInt32

func WriteInt32(b []byte, i int) []byte

func WriteInt64

func WriteInt64(b []byte, i int) []byte

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

func NewFloatValue(e expr.Expr, ts time.Time, val float64) Sequence

NewFloatValue makes a single-value sequence from a simple expression, timestamp float value.

func NewSequence

func NewSequence(width int, numPeriods int) Sequence

NewSequence allocates a new Sequence that holds the given number of periods with accumulator states of the given width.

func NewValue

func NewValue(e expr.Expr, ts time.Time, params expr.Params, metadata goexpr.Params) Sequence

NewValue makes a single-value sequence from a simple expression, timestamp, params and metadata.

func ReadSequence

func ReadSequence(b []byte, l int) (Sequence, []byte)

func (Sequence) AsOf

func (seq Sequence) AsOf(width int, resolution time.Duration) time.Time

AsOf returns the oldest date represented by this Sequence.

func (Sequence) DataLength

func (seq Sequence) DataLength() int

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

func (seq Sequence) NumPeriods(width int) int

NumPeriods returns the number of periods in this Sequence assuming the given width.

func (Sequence) SetUntil

func (seq Sequence) SetUntil(t time.Time)

SetUntil sets the until time of this Sequence.

func (Sequence) String

func (seq Sequence) String(e expr.Expr, resolution time.Duration) string

String provides a string representation of this Sequence assuming that it holds data for the given Expr.

func (Sequence) SubMerge

func (seq Sequence) SubMerge(other Sequence, metadata goexpr.Params, resolution time.Duration, otherResolution time.Duration, ex expr.Expr, otherEx expr.Expr, submerge expr.SubMerge, asOf time.Time, until time.Time, strideSlice time.Duration) (result Sequence)

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) Until

func (seq Sequence) Until() time.Time

Until returns the most recent date represented by this Sequence.

func (Sequence) UntilInt

func (seq Sequence) UntilInt() int64

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

func (seq Sequence) ValueAt(period int, e expr.Expr) (val float64, found bool)

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

func (seq Sequence) ValueAtOffset(offset int, e expr.Expr) (val float64, found bool)

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

func NewTSParams(ts time.Time, params bytemap.ByteMap) TSParams

NewTSParams constructs a new TSParams using the given Time and ByteMap.

func (TSParams) String

func (tsp TSParams) String() string

func (TSParams) TimeAndParams

func (tsp TSParams) TimeAndParams() (time.Time, expr.Params)

TimeAndParams returns the Time and Params components of this TSParams.

func (TSParams) TimeInt

func (tsp TSParams) TimeInt() int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL