Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Specifications describe how the implementation works today: ownership, APIs, data flow, state transitions, SIMD dispatch, errors and known gaps. To use the crate, read the guides instead; for checks and repository layout, see development.

Where to start

You want to understandRead, in order
How a compress call becomes bytesCompressor → the encoder for your quality (fast, greedy, high-quality) → Bit output
How a stream is decodedNative decompressor → Decoder SIMD → Owned decoder output
Why memory is reused between callsEncoder workspace → Uninitialized output
How one input is split across threadsParallel compression → Parallel streaming sessions
How containers and dictionaries workShared Brotli → Framed compressor → Framed decoder
How correctness is establishedDecoder verification → Fuzzing → Formal verification
Which features compile which codeCodec features → No standard library

Specifications share an outline: module and ownership boundaries, public surface, control and data flow with Mermaid diagrams, and error propagation. Most close with a list of known gaps.

Module map

graph TD
    Root[mbrotli public facade] --> Encode[compressor: compression feature]
    Root --> Decode[decompressor: decompression feature]
    Root --> Common[shared configuration, dictionary and I/O facades]
    Encode --> ECore[private compressor::core]
    Decode --> DCore[private decompressor::core]
    Encode --> Parallel[parallel API and private core: std]
    Parallel --> PStream[parallel sessions and task queue: core::stream]
    Parallel --> PIO[parallel reader and writer: io]
    PIO --> PStream
    Encode --> Framing[framed compressor: experimental, alloc]
    Framing --> FIO[framed writer and reader: std]
    Decode --> FDecode[framed decoder and private core: experimental, alloc]
    Framing --> Wire[codec-neutral framing types]
    FDecode --> Seek[framed seek reader and resource Read: std]
    FDecode --> Wire
    ECore --> Probe[private cache_probe: SIMD distance-cache filter for qualities 7-11]
    ECore --> Shared[private shared primitives]
    DCore --> Shared
    ECore --> SIMD[fearless_simd: selected backend]
    ECore --> Macro["fearless_simd_macros: #[simd] feature entries"]
    Macro --> SIMD
    DCore --> SIMD
    C[google-brotli-ffi] -. tests and benchmarks .-> Root
    CABI[mbrotli-ffi: C ABI crate] --> Root
    CABI --> CCore[private mbrotli_ffi::core]
    CCore --> CSessions[core::sessions: opaque owning handles and panic guard]

Public modules own ergonomic configuration and high-level errors. Private core modules own algorithms and state machines; implementation errors, SIMD types and FFI do not appear in public signatures. Each codec compiles independently.

Common boundaries

Feature gates and primitives that both codecs share.

SpecificationScope
Codec featuresCodec gates, shared types and isolated consumer checks.
No standard libraryAlloc-backed APIs, feature precedence and compile-time SIMD.
Shared primitivesCommon data, transforms, fixed boxed tables, the baseline SIMD level, prefetch and mask scans.
Uninitialized outputWrite-only destinations for sessions and one-shot calls, and the C ABI’s use of them.

Compression

From the public Compressor down to the three encoder cores and the bit writer.

SpecificationScope
CompressorPublic API, sessions, size-hint inference, I/O, dispatch and errors.
Encoder workspaceRetained output backing, reset, parked match-finder tables, accounting and backpressure.
Bit outputDestinations, command-prefix lookup, literal tables, direct Vec appends, bit operations and overflow.
Serial output identityShared scheduling, empty finalization and C compatibility.
Fast encoderQualities 0–1: fragments, direct encoding, entropy coding, prefix-code builders and SIMD scans.
Greedy encoderQualities 2–9: hash tables and their growth, SIMD range hashing, match scoring, distance-cache prefilter and meta-blocks.
High-quality encoderQualities 10–11: tree search, SIMD distance-cache and dictionary filters, command pricing and clustering.
Owned sessionsLifetime-free raw and framed sessions, reinit and input-free flush/finish.
Parallel compressionPlanning, encoder reconfiguration, caller-run tasks, staging and assembly.
Parallel streaming sessionsChunked input into queued segment tasks, ordered delivery, flush, queue closure and the blocking adapters.

Decompression

The native decoder, its performance paths and the framed container readers.

SpecificationScope
Native decompressorParsing, sessions, history, the single-exit command loop, dictionaries, budgets and I/O.
Owned decoder outputStored members, allocation transfer, linear slice history and read-ahead accounting.
Literal and stored-header decodingLiteral batches, per-context roots, byte-exact literal runs and stored-member recognition.
Decoder SIMDCommand-loop dispatch and bounded fixed-size history copies.
Decoder verificationC/RFC oracles, feature profiles and test limitations.
Framed decoderStructured containers, detection, events, dictionaries, validation, budgets and lending reader.
Framed seek readerFooter/directory indexing, lazy metadata, sparse dependency decoding and resource Read.

Extended formats

Large Window, shared dictionaries and the experimental framing container.

SpecificationScope
Shared BrotliLarge Window declarations and prepared prefix dictionaries.
Serialized dictionariesExperimental wire format, transforms and resource limits.
Custom encoding and continuationsStatic indexes, contexts and headerless stream offsets.
Framed compressorReusable owner, structured input, sessions, std adapters, metadata and wire compatibility.

Language bindings

SpecificationScope
C ABImbrotli-ffi: one-shot and session C functions, pointer validation, panic poisoning and status mapping.

Development tools

How the repository measures, tests, proves and publishes itself.

SpecificationScope
Implementation comparisonIsolated library comparisons, validation, provenance and charts.
FuzzingTarget inputs, oracles, campaigns, regression replay and the libFuzzer adapters.
Continuous integrationTriggers, checks, Miri and AddressSanitizer, fuzz campaigns, coverage gating and release publishing.
Documentation publishingSource staging, navigation, section pages, recipe execution, link validation and Pages deployment.
Formal verificationCharon/Aeneas translation to Lean 4, function specifications, round-trip theorems and the trusted base.