Skip to main content

DecodeError

Enum DecodeError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidData

The input violates the Zstandard format.

Fields

§kind: InvalidDataKind

The malformed structure.

§

UnexpectedEndOfInput

The input ended inside a frame, or before any frame.

§

TrailingData

Bytes followed the frame of a super::FrameMode::Single operation.

Fields

§offset: u64

Offset of the first byte after the frame.

§

OutputTooSmall

The caller’s output slice is full.

Fields

§written: usize

Bytes written before the slice filled.

§

ChecksumMismatch

The frame’s content checksum does not match its output.

Fields

§expected: u32

The checksum stored in the frame.

§computed: u32

The low 32 bits of the XXH64 of the decoded content.

§

ContentSizeMismatch

The frame regenerated a different size than its header declares.

Fields

§declared: u64

Frame_Content_Size from the header.

§decoded: u64

Bytes regenerated, or a lower bound once it exceeds declared.

§

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.

Fields

§id: u32

The frame’s Dictionary_ID.

§

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: DictionaryId

The frame’s Dictionary_ID.

§

WindowLimitExceeded

The frame’s window exceeds the configured limit.

Fields

§window_size: u64

The window the frame declares.

§limit: u64

The configured limit.

§

InputLimitExceeded

The compressed input budget is exhausted.

Fields

§limit: u64

The configured budget.

§

OutputLimitExceeded

The decompressed output budget is exhausted.

Fields

§limit: u64

The configured budget.

§

AllocationFailed

A heap allocation failed.

§

InvalidState

The call violates the session contract, or the session already failed.

Trait Implementations§

Source§

impl Debug for DecodeError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DecodeError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for DecodeError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecodeError> for Error

Available on non-crate feature no_std only.
Source§

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.

Source§

impl From<DecodeFailure> for DecodeError

Source§

fn from(failure: DecodeFailure) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidDataKind> for DecodeError

Source§

fn from(kind: InvalidDataKind) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.