encoding

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package encoding holds the byte-level integer codecs aki uses on disk and on the WAL (spec 2064 doc 02 §5, doc 04 §3). Everything multi-byte in the file format is little-endian so that the common amd64/arm64 case is a plain load; variable-length integers use unsigned LEB128, and signed values are mapped to unsigned with zigzag so small magnitudes of either sign stay short.

The functions here are intentionally allocation-free and append-based so the pager and WAL writer can build records into a reused buffer.

Index

Constants

This section is empty.

Variables

View Source
var ErrOverflow = errors.New("aki/encoding: varint overflows 64 bits")

ErrOverflow is returned when a varint is longer than 10 bytes, which cannot fit a 64-bit value and signals corruption.

View Source
var ErrTruncated = errors.New("aki/encoding: truncated input")

ErrTruncated is returned by the decoders when the input ends mid-value.

Functions

func AppendF64

func AppendF64(dst []byte, v float64) []byte

AppendF64 appends a float64 as little-endian IEEE-754 bits, used by sorted-set scores and the geo commands (spec 2064 doc 11, doc 13).

func AppendU16

func AppendU16(dst []byte, v uint16) []byte

AppendU16, AppendU32, AppendU64 append fixed-width little-endian integers.

func AppendU32

func AppendU32(dst []byte, v uint32) []byte

func AppendU32BE

func AppendU32BE(dst []byte, v uint32) []byte

AppendU32BE, AppendU64BE append fixed-width big-endian integers. RDB length fields use big-endian for their 32-bit and 64-bit forms (spec 2064 doc 17).

func AppendU64

func AppendU64(dst []byte, v uint64) []byte

func AppendU64BE

func AppendU64BE(dst []byte, v uint64) []byte

func AppendUvarint

func AppendUvarint(dst []byte, v uint64) []byte

AppendUvarint appends the unsigned LEB128 encoding of v to dst.

func AppendVarint

func AppendVarint(dst []byte, v int64) []byte

AppendVarint appends the zigzag+LEB128 encoding of a signed v to dst.

func F64

func F64(b []byte) float64

F64 reads a little-endian IEEE-754 float64 from b.

func PutU16

func PutU16(b []byte, v uint16)

PutU16, PutU32, PutU64 write fixed-width little-endian integers into b, which must be large enough. They wrap binary.LittleEndian so call sites read in aki's vocabulary rather than the standard library's.

func PutU32

func PutU32(b []byte, v uint32)

func PutU64

func PutU64(b []byte, v uint64)

func U16

func U16(b []byte) uint16

U16, U32, U64 read fixed-width little-endian integers from b.

func U32

func U32(b []byte) uint32

func U32BE

func U32BE(b []byte) uint32

U32BE, U64BE read fixed-width big-endian integers from b.

func U64

func U64(b []byte) uint64

func U64BE

func U64BE(b []byte) uint64

func Unzigzag

func Unzigzag(u uint64) int64

Unzigzag is the inverse of Zigzag.

func Uvarint

func Uvarint(src []byte) (uint64, int, error)

Uvarint decodes an unsigned LEB128 value from the front of src and returns it with the number of bytes consumed.

func Varint

func Varint(src []byte) (int64, int, error)

Varint decodes a zigzag+LEB128 signed value from the front of src.

func Zigzag

func Zigzag(v int64) uint64

Zigzag maps a signed integer to an unsigned one so that small magnitudes of either sign encode to short varints: 0,-1,1,-2,2 -> 0,1,2,3,4.

Types

This section is empty.

Jump to

Keyboard shortcuts

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