imessage_database/error/
typedstream.rs

1/*!
2 Errors that can happen when parsing `typedstream` data. This module is for the new `typedstream` deserializer.
3*/
4
5use std::{
6    array::TryFromSliceError,
7    fmt::{Display, Formatter, Result},
8    str::Utf8Error,
9};
10
11/// Errors that can happen when parsing `typedstream` data
12#[derive(Debug)]
13pub enum TypedStreamError {
14    OutOfBounds(usize, usize),
15    InvalidHeader,
16    SliceError(TryFromSliceError),
17    StringParseError(Utf8Error),
18    InvalidArray,
19    InvalidPointer(u8),
20}
21
22impl Display for TypedStreamError {
23    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
24        match self {
25            TypedStreamError::OutOfBounds(idx, len) => {
26                write!(fmt, "Index {idx:x} is outside of range {len:x}!")
27            }
28            TypedStreamError::InvalidHeader => write!(fmt, "Invalid typedstream header!"),
29            TypedStreamError::SliceError(why) => {
30                write!(fmt, "Unable to slice source stream: {why}")
31            }
32            TypedStreamError::StringParseError(why) => write!(fmt, "Failed to parse string: {why}"),
33            TypedStreamError::InvalidArray => write!(fmt, "Failed to parse array data"),
34            TypedStreamError::InvalidPointer(why) => write!(fmt, "Failed to parse pointer: {why}"),
35        }
36    }
37}