keyformat

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastPrefixFormatter added in v1.0.1

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

Prefixes a single byte before a 32 byte hash.

func NewFastPrefixFormatter added in v1.0.1

func NewFastPrefixFormatter(prefix byte, length int) *FastPrefixFormatter

func (*FastPrefixFormatter) Key added in v1.0.1

func (f *FastPrefixFormatter) Key(bz []byte) []byte

func (*FastPrefixFormatter) KeyInt64 added in v1.0.1

func (f *FastPrefixFormatter) KeyInt64(bz int64) []byte

func (*FastPrefixFormatter) Length added in v1.0.1

func (f *FastPrefixFormatter) Length() int

func (*FastPrefixFormatter) Prefix added in v1.0.1

func (f *FastPrefixFormatter) Prefix() []byte

func (*FastPrefixFormatter) Scan added in v1.0.1

func (f *FastPrefixFormatter) Scan(key []byte, a interface{})

type KeyFormat

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

Provides a fixed-width lexicographically sortable []byte key format

func NewKeyFormat

func NewKeyFormat(prefix byte, layout ...int) *KeyFormat

Create a []byte key format based on a single byte prefix and fixed width key segments each of whose length is specified by by the corresponding element of layout.

For example, to store keys that could index some objects by a version number and their SHA256 hash using the form: 'c<version uint64><hash [32]byte>' then you would define the KeyFormat with:

var keyFormat = NewKeyFormat('c', 8, 32)

Then you can create a key with:

func ObjectKey(version uint64, objectBytes []byte) []byte {
	hasher := sha256.New()
	hasher.Sum(nil)
	return keyFormat.Key(version, hasher.Sum(nil))
}

If the last term of the layout is 0 it is unbounded, and will accept any length.

NewKeyFormat panics if any other term than the last is 0.

func (*KeyFormat) Key

func (kf *KeyFormat) Key(args ...interface{}) []byte

Format the args passed into the key format - will panic if the arguments passed do not match the length of the segment to which they correspond. When called with no arguments returns the raw prefix (useful as a start element of the entire keys space when sorted lexicographically).

func (*KeyFormat) KeyBytes

func (kf *KeyFormat) KeyBytes(segments ...[]byte) []byte

Format the byte segments into the key format - will panic if the segment lengths do not match the layout.

func (*KeyFormat) Length added in v1.0.0

func (kf *KeyFormat) Length() int

Length of the key format.

func (*KeyFormat) Prefix

func (kf *KeyFormat) Prefix() string

Return the prefix as a string.

func (*KeyFormat) Scan

func (kf *KeyFormat) Scan(key []byte, args ...interface{})

Extracts the segments into the values pointed to by each of args. Each arg must be a pointer to int64, uint64, or []byte, and the width of the args must match layout.

func (*KeyFormat) ScanBytes

func (kf *KeyFormat) ScanBytes(key []byte) [][]byte

Reads out the bytes associated with each segment of the key format from key.

Jump to

Keyboard shortcuts

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