codable

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package codable provides types that implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler and functions that help to encode and decode primitives. The Prometheus storage backend uses them to persist objects to files and to save objects in LevelDB.

The encodings used in this package are designed in a way that objects can be unmarshaled from a continuous byte stream, i.e. the information when to stop reading is determined by the format. No separate termination information is needed.

Strings are encoded as the length of their bytes as a varint followed by their bytes.

Slices are encoded as their length as a varint followed by their elements.

Maps are encoded as the number of mappings as a varint, followed by the mappings, each of which consists of the key followed by the value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeUint64

func DecodeUint64(r io.Reader) (uint64, error)

DecodeUint64 reads an uint64 from an io.Reader in big-endian byte-order. This is a GC-friendly implementation that takes the required staging buffer from a buffer pool.

func EncodeUint64

func EncodeUint64(w io.Writer, u uint64) error

EncodeUint64 writes an uint64 to an io.Writer in big-endian byte-order. This is a GC-friendly implementation that takes the required staging buffer from a buffer pool.

func EncodeUvarint

func EncodeUvarint(w io.Writer, i uint64) (int, error)

EncodeUvarint encodes an uint64 as a varint and writes it to an io.Writer. It returns the number of bytes written. This is a GC-friendly implementation that takes the required staging buffer from a buffer pool.

func EncodeVarint

func EncodeVarint(w io.Writer, i int64) (int, error)

EncodeVarint encodes an int64 as a varint and writes it to an io.Writer. It returns the number of bytes written. This is a GC-friendly implementation that takes the required staging buffer from a buffer pool.

Types

type Fingerprint

type Fingerprint model.Fingerprint

A Fingerprint is a model.Fingerprint that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. The implementation depends on model.Fingerprint to be convertible to uint64. It encodes the fingerprint as a big-endian uint64.

func (Fingerprint) MarshalBinary

func (fp Fingerprint) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Fingerprint) UnmarshalBinary

func (fp *Fingerprint) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type FingerprintSet

type FingerprintSet map[model.Fingerprint]struct{}

FingerprintSet is a map[model.Fingerprint]struct{} that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Its binary form is identical to that of Fingerprints.

func (FingerprintSet) MarshalBinary

func (fps FingerprintSet) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*FingerprintSet) UnmarshalBinary

func (fps *FingerprintSet) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Fingerprints

type Fingerprints model.Fingerprints

Fingerprints is a model.Fingerprints that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Its binary form is identical to that of FingerprintSet.

func (Fingerprints) MarshalBinary

func (fps Fingerprints) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Fingerprints) UnmarshalBinary

func (fps *Fingerprints) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type LabelName

type LabelName model.LabelName

LabelName is a model.LabelName that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func (LabelName) MarshalBinary

func (l LabelName) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*LabelName) UnmarshalBinary

func (l *LabelName) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type LabelPair

type LabelPair model.LabelPair

LabelPair is a model.LabelPair that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func (LabelPair) MarshalBinary

func (lp LabelPair) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*LabelPair) UnmarshalBinary

func (lp *LabelPair) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type LabelValueSet

type LabelValueSet map[model.LabelValue]struct{}

LabelValueSet is a map[model.LabelValue]struct{} that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Its binary form is identical to that of LabelValues.

func (LabelValueSet) MarshalBinary

func (vs LabelValueSet) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*LabelValueSet) UnmarshalBinary

func (vs *LabelValueSet) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type LabelValues

type LabelValues model.LabelValues

LabelValues is a model.LabelValues that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Its binary form is identical to that of LabelValueSet.

func (LabelValues) MarshalBinary

func (vs LabelValues) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*LabelValues) UnmarshalBinary

func (vs *LabelValues) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Metric

type Metric model.Metric

A Metric is a model.Metric that implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func (Metric) MarshalBinary

func (m Metric) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Metric) UnmarshalBinary

func (m *Metric) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler. It can be used with the zero value of Metric.

func (*Metric) UnmarshalFromReader

func (m *Metric) UnmarshalFromReader(r byteReader) error

UnmarshalFromReader unmarshals a Metric from a reader that implements both, io.Reader and io.ByteReader. It can be used with the zero value of Metric.

type TimeRange

type TimeRange struct {
	First, Last model.Time
}

TimeRange is used to define a time range and implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func (TimeRange) MarshalBinary

func (tr TimeRange) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*TimeRange) UnmarshalBinary

func (tr *TimeRange) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

Jump to

Keyboard shortcuts

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