http-compress 23.2.0

A high-performance async library for HTTP compression/decompression, supporting Brotli, Deflate, and Gzip algorithms. Provides both compression and decompression capabilities with optimized memory usage, ideal for HTTP clients/servers and network programming.
Documentation
use super::*;

/// A pooled slice wrapper backed by a reusable `Vec<T>` for Brotli allocator traits.
pub(crate) struct PooledSlice<T>(pub(crate) Vec<T>);

/// Zero-sized Brotli allocator backed by a thread-local typed buffer pool.
#[derive(Default)]
pub(crate) struct BrotliTlAlloc;

/// Thread-local typed buffer pools recycled across Brotli encode and decode calls.
#[derive(Default)]
pub(crate) struct BrotliBufferPool {
    /// Pooled `u8` slices.
    pub(crate) buf_u8: Vec<Vec<u8>>,
    /// Pooled `u16` slices.
    pub(crate) buf_u16: Vec<Vec<u16>>,
    /// Pooled `i32` slices.
    pub(crate) buf_i32: Vec<Vec<i32>>,
    /// Pooled `u32` slices.
    pub(crate) buf_u32: Vec<Vec<u32>>,
    /// Pooled `u64` slices.
    pub(crate) buf_u64: Vec<Vec<u64>>,
    /// Pooled `Command` slices.
    pub(crate) buf_command: Vec<Vec<Command>>,
    /// Pooled `floatX` slices.
    pub(crate) buf_float: Vec<Vec<floatX>>,
    /// Pooled `v8` slices.
    pub(crate) buf_v8: Vec<Vec<v8>>,
    /// Pooled `s16` slices.
    pub(crate) buf_s16: Vec<Vec<s16>>,
    /// Pooled `PDF` slices.
    pub(crate) buf_pdf: Vec<Vec<PDF>>,
    /// Pooled `StaticCommand` slices.
    pub(crate) buf_static_command: Vec<Vec<StaticCommand>>,
    /// Pooled `HistogramLiteral` slices.
    pub(crate) buf_hist_literal: Vec<Vec<HistogramLiteral>>,
    /// Pooled `HistogramCommand` slices.
    pub(crate) buf_hist_command: Vec<Vec<HistogramCommand>>,
    /// Pooled `HistogramDistance` slices.
    pub(crate) buf_hist_distance: Vec<Vec<HistogramDistance>>,
    /// Pooled `HistogramPair` slices.
    pub(crate) buf_hist_pair: Vec<Vec<HistogramPair>>,
    /// Pooled `ContextType` slices.
    pub(crate) buf_context_type: Vec<Vec<ContextType>>,
    /// Pooled `HuffmanTree` slices.
    pub(crate) buf_huffman_tree: Vec<Vec<HuffmanTree>>,
    /// Pooled `ZopfliNode` slices.
    pub(crate) buf_zopfli_node: Vec<Vec<ZopfliNode>>,
    /// Pooled `HuffmanCode` slices for decoding.
    pub(crate) buf_huffman_code: Vec<Vec<HuffmanCode>>,
}

/// RAII guard that destroys a `BrotliEncoderStateStruct` on drop so all buffers return to the pool.
pub(crate) struct BrotliEncoderGuard(pub(crate) BrotliEncoderStateStruct<BrotliTlAlloc>);