#[non_exhaustive]pub enum DecodeError {
Show 13 variants
InvalidData {
kind: InvalidDataKind,
},
UnexpectedEndOfInput,
TrailingData {
offset: u64,
},
OutputTooSmall {
written: usize,
},
ChecksumMismatch {
expected: u32,
computed: u32,
},
ContentSizeMismatch {
declared: u64,
decoded: u64,
},
DictionaryUnsupported {
id: u32,
},
DictionaryMismatch {
expected: Option<DictionaryId>,
frame: DictionaryId,
},
WindowLimitExceeded {
window_size: u64,
limit: u64,
},
InputLimitExceeded {
limit: u64,
},
OutputLimitExceeded {
limit: u64,
},
AllocationFailed,
InvalidState,
}Expand description
A decompression failure.
One-shot methods return it directly; sessions wrap it in
super::DecodeFailure together with the progress of the failing call.
The std::io adapters wrap it in std::io::Error (with std), from
which get_ref and downcast_ref::<DecodeError>() recover it.
§Examples
use mzstd::{DecodeError, Decompressor, InvalidDataKind};
let mut decoder = Decompressor::default();
assert!(matches!(
decoder.decompress(b"not zstd"),
Err(DecodeError::InvalidData { kind: InvalidDataKind::Magic })
));
assert!(matches!(
decoder.decompress(&[0x28, 0xb5, 0x2f, 0xfd]),
Err(DecodeError::UnexpectedEndOfInput)
));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidData
The input violates the Zstandard format.
Fields
kind: InvalidDataKindThe malformed structure.
UnexpectedEndOfInput
The input ended inside a frame, or before any frame.
TrailingData
Bytes followed the frame of a super::FrameMode::Single operation.
OutputTooSmall
The caller’s output slice is full.
ChecksumMismatch
The frame’s content checksum does not match its output.
Fields
ContentSizeMismatch
The frame regenerated a different size than its header declares.
Fields
DictionaryUnsupported
The frame names a dictionary, and the operation has none.
Decode such frames with the dictionary they were compressed with,
through the *_with_dictionary methods of
Decompressor.
DictionaryMismatch
The frame names a dictionary ID other than the one the operation’s dictionary declares.
A frame that names no dictionary decodes with any dictionary. A raw-content dictionary declares no ID, so it never matches a frame that names one, as in the reference decoder.
§Examples
use mzstd::dictionary::DecodeDictionary;
use mzstd::{DecodeError, Decompressor};
// A frame naming dictionary 7, with an empty last raw block.
let frame = [0x28, 0xb5, 0x2f, 0xfd, 0x21, 0x07, 0x00, 0x01, 0x00, 0x00];
let raw = DecodeDictionary::try_from(&b"raw content"[..])?;
let error = Decompressor::default()
.decompress_with_dictionary(&raw, &frame)
.unwrap_err();
assert!(matches!(
error,
DecodeError::DictionaryMismatch { expected: None, frame } if u32::from(frame) == 7
));
assert_eq!(
error.to_string(),
"frame requires dictionary 7, but the dictionary declares no ID"
);Fields
expected: Option<DictionaryId>The ID the operation’s dictionary declares, if any.
frame: DictionaryIdThe frame’s Dictionary_ID.
WindowLimitExceeded
The frame’s window exceeds the configured limit.
InputLimitExceeded
The compressed input budget is exhausted.
OutputLimitExceeded
The decompressed output budget is exhausted.
AllocationFailed
A heap allocation failed.
InvalidState
The call violates the session contract, or the session already failed.
Trait Implementations§
Source§impl Debug for DecodeError
impl Debug for DecodeError
Source§impl Display for DecodeError
impl Display for DecodeError
Source§impl Error for DecodeError
impl Error for DecodeError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<DecodeError> for Error
Available on non-crate feature no_std only.
impl From<DecodeError> for Error
no_std only.Source§fn from(error: DecodeError) -> Self
fn from(error: DecodeError) -> Self
Maps format errors to InvalidData, truncation to UnexpectedEof,
contract violations to InvalidInput, allocation failure to
OutOfMemory and exhausted limits to Other.