serialized

package
v0.0.0-...-f7bad0d Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any, PT PointerBinaryUnmarshaler[T]] struct {
	// contains filtered or unexported fields
}

Iterator is an iterator that unmarshal the value.

func NewIterator

func NewIterator[T any, PT PointerBinaryUnmarshaler[T]](base badgerutils.BadgerIterator) *Iterator[T, PT]

NewIterator creates a new serialized iterator.

func (*Iterator[T, PT]) Close

func (it *Iterator[T, PT]) Close()

Close closes the iterator.

func (*Iterator[T, PT]) Item

func (it *Iterator[T, PT]) Item() *badger.Item

Item returns the current item.

func (*Iterator[T, PT]) Key

func (it *Iterator[T, PT]) Key() []byte

Key returns the current key.

func (*Iterator[T, PT]) Next

func (it *Iterator[T, PT]) Next()

Key returns the current key.

func (*Iterator[T, PT]) Rewind

func (it *Iterator[T, PT]) Rewind()

Rewind rewinds the iterator.

func (*Iterator[T, PT]) Seek

func (it *Iterator[T, PT]) Seek(key []byte)

Seek seeks the key.

func (*Iterator[T, PT]) Valid

func (it *Iterator[T, PT]) Valid() bool

Valid returns if the iterator is valid.

func (*Iterator[T, PT]) Value

func (it *Iterator[T, PT]) Value() (value *T, err error)

Value returns the current value unmarshaled as T

type MetaBearer

type MetaBearer interface {
	MetaByte() byte
}

MetaBearer is an item that has meta byte.

type PointerBinaryUnmarshaler

type PointerBinaryUnmarshaler[T any] interface {
	encoding.BinaryUnmarshaler
	*T
}

PointerBinaryUnmarshaler is an interface that unmarshals a binary data.

type Store

type Store[T encoding.BinaryMarshaler, PT PointerBinaryUnmarshaler[T]] struct {
	// contains filtered or unexported fields
}

Store is a store that serializes all keys and values.

func Migrate

func Migrate[T, U encoding.BinaryMarshaler,
	PT PointerBinaryUnmarshaler[T],
	PU PointerBinaryUnmarshaler[U],
](
	src *Store[T, PT],
	convert func(*T, *badger.Item) (*U, error),
) (*Store[U, PU], error)

Migrate migrates a store from one type to another.

func New

New creates a new serialized store.

func (*Store[T, PT]) Delete

func (s *Store[T, PT]) Delete(key []byte) error

Delete deletes the key from the store.

func (*Store[T, PT]) Get

func (s *Store[T, PT]) Get(key []byte) (value *T, err error)

Get gets the value of the key from the store and unmarshal it.

func (*Store[T, PT]) GetWithItem

func (s *Store[T, PT]) GetWithItem(key []byte) (item *badger.Item, value *T, err error)

GetWithItem is similar to Get, but it also returns the badger.Item as well.

func (*Store[T, PT]) NewIterator

func (s *Store[T, PT]) NewIterator(opts badger.IteratorOptions) badgerutils.Iterator[*T]

NewIterator creates a new iterator.

func (*Store[T, PT]) Prefix

func (s *Store[T, PT]) Prefix() []byte

Prefix returns the prefix of the store.

func (*Store[T, PT]) Set

func (s *Store[T, PT]) Set(key []byte, value *T) error

Set marshals the value as binary and sets it to the key. If the value implements TemporaryItem, it will set the TTL. If the value implements MetaBearer, it will set the meta byte.

type TemporaryItem

type TemporaryItem interface {
	TTL() time.Duration
}

TemporaryItem is an item that has a TTL.

Jump to

Keyboard shortcuts

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