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 ¶
- Variables
- func AppendF64(dst []byte, v float64) []byte
- func AppendU16(dst []byte, v uint16) []byte
- func AppendU32(dst []byte, v uint32) []byte
- func AppendU32BE(dst []byte, v uint32) []byte
- func AppendU64(dst []byte, v uint64) []byte
- func AppendU64BE(dst []byte, v uint64) []byte
- func AppendUvarint(dst []byte, v uint64) []byte
- func AppendVarint(dst []byte, v int64) []byte
- func F64(b []byte) float64
- func PutU16(b []byte, v uint16)
- func PutU32(b []byte, v uint32)
- func PutU64(b []byte, v uint64)
- func U16(b []byte) uint16
- func U32(b []byte) uint32
- func U32BE(b []byte) uint32
- func U64(b []byte) uint64
- func U64BE(b []byte) uint64
- func Unzigzag(u uint64) int64
- func Uvarint(src []byte) (uint64, int, error)
- func Varint(src []byte) (int64, int, error)
- func Zigzag(v int64) uint64
Constants ¶
This section is empty.
Variables ¶
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.
var ErrTruncated = errors.New("aki/encoding: truncated input")
ErrTruncated is returned by the decoders when the input ends mid-value.
Functions ¶
func AppendF64 ¶
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 AppendU32BE ¶
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 AppendU64BE ¶
func AppendUvarint ¶
AppendUvarint appends the unsigned LEB128 encoding of v to dst.
func AppendVarint ¶
AppendVarint appends the zigzag+LEB128 encoding of a signed v to dst.
func PutU16 ¶
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 Uvarint ¶
Uvarint decodes an unsigned LEB128 value from the front of src and returns it with the number of bytes consumed.
Types ¶
This section is empty.