Skip to main content

Module format

Module format 

Source
Expand description

Binary format helpers shared across AOF and snapshot files.

Provides TLV-style encoding primitives, CRC32 checksums, and magic byte constants. All multi-byte integers are stored in little-endian.

Enums§

FormatError
Errors that can occur when reading or writing persistence formats.

Constants§

AOF_MAGIC
Magic bytes for the AOF file header.
FORMAT_VERSION
Current format version for both AOF and snapshot files.
MAX_FIELD_LEN
Maximum length we’ll allocate when reading a length-prefixed field. 512 MB is generous for any realistic key or value — a corrupt or malicious length prefix won’t cause a multi-gigabyte allocation.
SNAP_MAGIC
Magic bytes for the snapshot file header.

Functions§

crc32
Computes a CRC32 checksum over a byte slice.
read_bytes
Reads a length-prefixed byte vector: [len: u32][data].
read_f64
Reads an f64 in little-endian.
read_header
Reads and validates a file header. Returns an error if magic doesn’t match or version is unsupported. Returns the format version.
read_i64
Reads an i64 in little-endian.
read_u8
Reads a u8 from the reader.
read_u16
Reads a u16 in little-endian.
read_u32
Reads a u32 in little-endian.
verify_crc32
Verifies that data matches the expected CRC32 checksum.
verify_crc32_values
Verifies that two CRC32 values match.
write_bytes
Writes a length-prefixed byte slice: [len: u32][data].
write_f64
Writes an f64 in little-endian.
write_header
Writes a file header: magic bytes + version byte.
write_i64
Writes an i64 in little-endian.
write_u8
Writes a u8 to the writer.
write_u16
Writes a u16 in little-endian.
write_u32
Writes a u32 in little-endian.