Skip to content

Commit

Permalink
compression: derive Error for deflate::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Aug 10, 2024
1 parent 39979e7 commit 9c00bf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ criterion = { workspace = true }
hash = { workspace = true }
log = { workspace = true }
sl-std = { workspace = true }
error-derive = { workspace = true }

[[bench]]
name = "brotli"
Expand Down
24 changes: 17 additions & 7 deletions crates/compression/src/deflate.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
use crate::huffman::HuffmanTree;

use error_derive::Error;
use sl_std::bitreader::{self, BitReader};

use std::cmp::{min, Ordering};

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Error)]
pub enum Error {
#[msg = "invalid compression scheme"]
InvalidCompressionScheme,

#[msg = "reserved compression scheme"]
ReservedCompressionScheme,

#[msg = "unexpected end of file"]
UnexpectedEOF,

#[msg = "symbol not found"]
SymbolNotFound,

#[msg = "run length encoding leading repeat value"]
RLELeadingRepeatValue,

#[msg = "run length encoding exceeds expected value"]
RLEExceedsExpectedLength,

#[msg = "invalid uncompressed block length"]
InvalidUncompressedBlockLength,
BitReader(bitreader::Error),
}

impl From<bitreader::Error> for Error {
fn from(value: bitreader::Error) -> Self {
Self::BitReader(value)
}
#[msg = "failed to read bits"]
BitReader(bitreader::Error),
}

#[derive(Clone, Copy, Debug)]
Expand Down

0 comments on commit 9c00bf0

Please sign in to comment.