entry

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxHeaderSize = 1 + binary.MaxVarintLen64*2 + binary.MaxVarintLen32*2

MaxHeaderSize | 31 B | +------+------+----------+--------+----------+---------+---------+ | type | ttl | txn_id | key_sz | value_sz | key | value | +------+------+----------+--------+----------+---------+---------+ | 1 B | 10 B | 10 B | 5 B | 5 B | unfixed | unfixed | +------+------+----------+--------+----------+---------+---------+

Variables

View Source
var (
	ErrNilKey             = errors.New("key is nil")
	ErrNilRawData         = errors.New("raw data bytes is nil")
	ErrInvalidEntryType   = errors.New("entry type is invalid")
	ErrRedundantEntryType = errors.New("redundant entry type")
	ErrExpired            = errors.New("entry is expired")
)

Functions

func CheckEntryType

func CheckEntryType(t EType) error

func IsExpired

func IsExpired(ttl int64) bool

IsExpired if ttl is 0, represents of persistent only if ttl > 0, entry has live time

func LeftTTl

func LeftTTl(ttl int64) time.Duration

func MarshalEntry

func MarshalEntry(entry Entry) ([]byte, error)

func MarshalHeader

func MarshalHeader(header Header) ([]byte, int, error)

func NewTTL

func NewTTL(ttl time.Duration) int64

func Validate

func Validate(entry Entry) error

Validate validates the given entry if is a valid data entry

Types

type BinaryEntry

type BinaryEntry struct{}

BinaryEntry Binary data format

func (BinaryEntry) MarshalEntry

func (d BinaryEntry) MarshalEntry(entry Entry) ([]byte, error)

func (BinaryEntry) MarshalHeader

func (d BinaryEntry) MarshalHeader(header Header) ([]byte, int, error)

func (BinaryEntry) UnMarshalEntry

func (d BinaryEntry) UnMarshalEntry(bytes []byte) (Entry, error)

func (BinaryEntry) UnMarshalHeader

func (d BinaryEntry) UnMarshalHeader(raws []byte) (Header, int, error)

type EType

type EType = byte
const (
	DataEntryType EType = 1 + iota

	DeletedEntryType

	TxnCommitEntryType

	TxnRollBackEntryType
)

type Entry

type Entry struct {
	Type  EType
	Key   []byte
	Value []byte

	TTL  int64
	TxId int64
}

Entry represents a data entry in data file

func UnMarshalEntry

func UnMarshalEntry(rawdata []byte) (Entry, error)
type Header struct {
	Type EType
	TTL  int64
	TxId int64
	Ksz  uint32
	Vsz  uint32
}

Header represents a header of data entry

func UnMarshalHeader

func UnMarshalHeader(rawdata []byte) (Header, int, error)

type HeaderMarshaler

type HeaderMarshaler interface {
	MarshalHeader(entry Header) ([]byte, int, error)
}

type HeaderUnmarshaler

type HeaderUnmarshaler interface {
	UnMarshalHeader(raws []byte) (Header, int, error)
}

type Marshaler

type Marshaler interface {
	MarshalEntry(entry Entry) ([]byte, error)
}

type UnMarshaler

type UnMarshaler interface {
	UnMarshalEntry(raws []byte) (Entry, error)
}

Jump to

Keyboard shortcuts

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