keyformat

package
v0.2012.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomFormat

type CustomFormat interface {
	// Size returns the size of the encoded element.
	Size() int

	// MarshalBinary encodes the passed value into its binary representation.
	MarshalBinary(v interface{}) ([]byte, error)

	// UnmarshalBinary decodes the passed value from its binary representation.
	UnmarshalBinary(v interface{}, data []byte) error
}

CustomFormat specifies a custom encoding format for a key element.

func H

func H(inner interface{}) CustomFormat

H wraps a key element to signal that the element should be hashed after regular encoding.

type KeyFormat

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

KeyFormat is a key formatting helper to be used together with key-value backends for constructing keys.

func New

func New(prefix byte, layout ...interface{}) *KeyFormat

New constructs a new key format.

func (*KeyFormat) Decode

func (k *KeyFormat) Decode(data []byte, values ...interface{}) bool

Decode decodes a key into its individual values.

Returns false and doesn't modify the passed values if the key prefix doesn't match.

func (*KeyFormat) Encode

func (k *KeyFormat) Encode(values ...interface{}) []byte

Encode encodes values into a key.

You can pass either the same amount of values as specified in the layout or less. In case less values are specified this will generate a shorter key containing only the specified values.

In case no values are specified this will only output the key prefix.

func (*KeyFormat) Size

func (k *KeyFormat) Size() int

Size returns the minimum size in bytes of the resulting key.

type PreHashed

type PreHashed hash.Hash

PreHashed represents a pre-hashed value that will be encoded without additional hashing when used together with a hashed format.

func (*PreHashed) Equal

func (ph *PreHashed) Equal(cmp *PreHashed) bool

Equal compares vs another hash for equality.

func (*PreHashed) MarshalBinary

func (ph *PreHashed) MarshalBinary() ([]byte, error)

MarshalBinary encodes a hash into binary form.

func (PreHashed) String

func (ph PreHashed) String() string

String returns the string representation of a hash.

func (*PreHashed) UnmarshalBinary

func (ph *PreHashed) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a binary marshaled hash.

Jump to

Keyboard shortcuts

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