imessage_database/error/
typedstream.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
/*!
 Errors that can happen when parsing `typedstream` data. This module is for the new `typedstream` deserializer.
*/

use std::{
    array::TryFromSliceError,
    fmt::{Display, Formatter, Result}, str::Utf8Error,
};

/// Errors that can happen when parsing `typedstream` data
#[derive(Debug)]
pub enum TypedStreamError {
    OutOfBounds(usize, usize),
    InvalidHeader,
    SliceError(TryFromSliceError),
    StringParseError(Utf8Error),
    InvalidArray,
    InvalidPointer(u8),
}

impl Display for TypedStreamError {
    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
        match self {
            TypedStreamError::OutOfBounds(idx, len) => {
                write!(fmt, "Index {idx:x} is outside of range {len:x}!")
            }
            TypedStreamError::InvalidHeader => write!(fmt, "Invalid typedstream header!"),
            TypedStreamError::SliceError(why) => {
                write!(fmt, "Unable to slice source stream: {why}")
            }
            TypedStreamError::StringParseError(why) => write!(fmt, "Failed to parse string: {why}"),
            TypedStreamError::InvalidArray => write!(fmt, "Failed to parse array data"),
            TypedStreamError::InvalidPointer(why) => write!(fmt, "Failed to parse pointer: {why}"),
        }
    }
}