maili_protocol/compression/
types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Compression types.

use crate::BrotliLevel;
use alloc::borrow::Borrow;

/// The result from compressing data.
pub type CompressorResult<T> = Result<T, CompressorError>;

/// An error returned by the compressor.
#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
pub enum CompressorError {
    /// Thrown when the compressor is full.
    #[error("compressor is full")]
    Full,
    /// Brotli compression failed.
    #[error("brotli compression failed")]
    Brotli,
}

/// The type of compressor to use.
///
/// See: <https://github.com/ethereum-optimism/optimism/blob/042433b89ce38ccc15456e9673829f6783bb97ac/op-batcher/compressor/compressors.go#L20>
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompressorType {
    /// The ratio compression.
    Ratio,
    /// The shadow compression.
    Shadow,
}

/// The compression algorithm type.
///
/// See:
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompressionAlgo {
    /// The fastest brotli compression level.
    Brotli9,
    /// The default brotli compression level.
    Brotli10,
    /// The best brotli compression level.
    Brotli11,
    /// The zlib compression.
    Zlib,
}

impl<A: Borrow<CompressionAlgo>> From<A> for BrotliLevel {
    fn from(algo: A) -> Self {
        match algo.borrow() {
            CompressionAlgo::Brotli9 => Self::Brotli9,
            CompressionAlgo::Brotli11 => Self::Brotli11,
            _ => Self::Brotli10,
        }
    }
}