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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pub mod blend;
pub mod dna;
pub mod field;
pub mod primitive;
use nom::{
error::{ErrorKind, ParseError},
number::Endianness as NomEndianness,
IResult,
};
use std::io;
type Result<'a, T> = IResult<&'a [u8], T, BlendParseError>;
#[derive(Debug, Copy, Clone)]
pub enum PointerSize {
Bits32,
Bits64,
}
impl PointerSize {
pub fn bytes_num(self) -> usize {
match self {
PointerSize::Bits32 => 4,
PointerSize::Bits64 => 8,
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum Endianness {
Little,
Big,
}
impl From<NomEndianness> for Endianness {
fn from(e: NomEndianness) -> Endianness {
match e {
NomEndianness::Little => Endianness::Little,
NomEndianness::Big => Endianness::Big,
}
}
}
#[derive(Debug)]
pub enum BlendParseError {
NomError {
kind: ErrorKind,
other: Option<Box<BlendParseError>>,
},
IoError(io::Error),
NotEnoughData,
UnknownBlockCode,
UnsupportedCountOnPrincipalBlock,
InvalidMemoryAddress,
NoDnaBlockFound,
CompressedFileNotSupported,
}
impl ParseError<&[u8]> for BlendParseError {
fn from_error_kind(_input: &[u8], kind: ErrorKind) -> Self {
BlendParseError::NomError { kind, other: None }
}
fn append(_input: &[u8], kind: ErrorKind, other: Self) -> Self {
BlendParseError::NomError {
kind,
other: Some(Box::new(other)),
}
}
}