header

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinHeaderSize is the minimum header size when no extra blocks are present
	MinHeaderSize = 24
	// PreAllocSize is the number of bytes pre-allocated to fit a header
	// with extensions. Larger headers will trigger an additional heap alloc.
	PreAllocSize = 64
	// BlockSize is the number of bytes per extra block
	BlockSize = 8
)
View Source
const (
	VersionOffset      = 16
	FlagsOffset        = 17
	NumExtraOffsetHigh = 22 // uint16 high byte
	NumExtraOffsetLow  = 23 // uint16 low byte

)

Variables

View Source
var (
	ErrTooShort = errors.New("value too short to contain a header")
	ErrVersion  = errors.New("unsupported header version or not a header")
)

Functions

func PutBasic

func PutBasic(b []byte, ts Timestamp, txnid TxnID, flags Flags)

PutBasic creates a basic header in the provided slice. The slice must have a length of at least MinHeaderSize.

func Skip

func Skip(val []byte) (value []byte, err error)

Skip skips over the header and returns the remaining application value.

Types

type Flags

type Flags uint8
const (
	// FlagDeleted indicates that this entry has been deleted
	FlagDeleted Flags = 1

	// NoFlags can be used when no flags are needed, for readability
	NoFlags Flags = 0

	// FlagSyncMask is the mask of flags allowed to sync to/from a snapshot,
	// others will be cleared.
	FlagSyncMask = FlagDeleted
)

func (Flags) IsDeleted

func (f Flags) IsDeleted() bool

func (Flags) Masked

func (f Flags) Masked() Flags
type Header struct {
	Timestamp Timestamp // time of last change
	TxnID     TxnID     // lmdb Go lib uses uint64 and uintptr
	Version   int       // header version (currently always 0)
	Flags     Flags     // header flags
	NumExtra  int       // extra number of 8-byte blocks (set automatically in .Bytes())
	Extra     []byte    // bytes in extra block
}

Header describes the header of a native schema value

func Parse

func Parse(val []byte) (header Header, value []byte, err error)

Parse parses a value with header and returns the remaining application value.

func (Header) Bytes

func (h Header) Bytes() []byte

func (Header) MarshalBinary

func (h Header) MarshalBinary() (data []byte, err error)

type Timestamp

type Timestamp uint64

Timestamp is the number of nanoseconds since the UNIX epoch, which is how we write it to the header.

func ParseTimestamp

func ParseTimestamp(val []byte) (ts Timestamp, err error)

ParseTimestamp parses a timestamp from the first 8 bytes of the value

func TimestampFromTime

func TimestampFromTime(t time.Time) Timestamp

TimestampFromTime creates a Timestamp from a Time

func (Timestamp) Time

func (ts Timestamp) Time() time.Time

Time converts a Timestamp into Time

type TxnID

type TxnID uint64

TxnID is the LMDB transaction ID. The Go lmdb library inconsistently uses int64 and uintptr for this in different places.

Jump to

Keyboard shortcuts

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