bottledlightning

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XMetaValue0 xMetaValue = iota
	XMetaValue1
	XMetaValue2
	XMetaValue3
	XMetaValue4
	XMetaValue5
	XMetaValue6
	XMetaValue7
	XMetaValue8
	XMetaValue9
	XMetaValueA
	XMetaValueB
	XMetaValueC
	XMetaValueD
	XMetaValueE
	XMetaValueF
)

Extended metadata values XMetaValue[0, F] can be assigned arbitrary meaning attached to records transmitted and received by Encoder.EncodeX and Decoder.DecodeX.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Inspired by encoding/gob.Decoder from the Go standard library, a Decoder specialises in the receipt of LMDB key-value records transmitted by an Encoder counterpart. It is safe for concurrent use by multiple goroutines.

func NewDecoder

func NewDecoder(reader io.Reader, hasher hash.Hash32) (d *Decoder)

NewDecoder returns a new Decoder that will receive from the io.Reader, and optionally verify the checksum of every record if the hash.Hash32 is not nil.

func (*Decoder) Decode

func (d *Decoder) Decode() (key, val []byte, e error)

Decode receives the next record from the input stream and returns two byte slices containing the key and value, respectively.

At the end of the stream, Decode returns a wrapped io.EOF. See errors.Is for more information on detecting wrapped errors.

func (*Decoder) DecodeX added in v0.2.0

func (d *Decoder) DecodeX() (key, val []byte, xmv byte, e error)

DecodeX is a variant of Decode that also interprets extended metadata.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder is modelled after encoding/gob.Encoder from the Go standard library, but specialises in the transmission of LMDB key-value records.

An LMDB record, consisting of a key no more than 511 bytes long, and a value of maximum size 4 GiB, is encoded as follows:

  • 2 bytes to represent the key length k in number of bytes,
  • 1 <= x <= 4 bytes to represent the value length v in number of bytes,
  • k bytes to hold the uninterpreted key,
  • v bytes to hold the uninterpreted value, and
  • 4 bytes to hold an optional 32-bit checksum of the record.

This incurs an overhead of 3 to 10 bytes per record, and leaves the first seven bits free to carry the following metadata:

  • 2 bits to encode the value of x (from the second bullet point above),
  • 1 bit to indicate the presence of a trailing 32-bit checksum, and
  • 4 bits for extended metadata---see defined constants.

Encoders are safe for concurrent use by multiple goroutines.

func NewEncoder

func NewEncoder(writer io.Writer, hasher hash.Hash32) (n *Encoder)

NewEncoder returns a new encoder that will transmit on the io.Writer, and optionally append a 32-bit checksum to every record if the hash.Hash32 is not nil.

func (*Encoder) Encode

func (n *Encoder) Encode(key, val []byte) error

Encode transmits a key-value record.

func (*Encoder) EncodeX added in v0.2.0

func (n *Encoder) EncodeX(key, val []byte, xmv xMetaValue) error

EncodeX transmits a key-value record with extended metadata.

Jump to

Keyboard shortcuts

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