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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
pub mod archive;
pub mod reader;
pub mod writer;
pub mod header;
pub mod index;
pub mod index_set;
pub use reader::XP3Reader;
pub use writer::XP3Writer;
use std::{error::Error, io};
use self::{header::XP3Header, index_set::XP3IndexSet};
pub const XP3_MAGIC: [u8; 10] = [ 0x58_u8, 0x50, 0x33, 0x0D, 0x0A, 0x20, 0x0A, 0x1A, 0x8B, 0x67 ];
pub const XP3_CURRENT_VER_IDENTIFIER: u64 = 0x17;
pub const XP3_VERSION_IDENTIFIER: u8 = 128;
pub const XP3_INDEX_CONTINUE: u8 = 0x80;
pub const XP3_INDEX_FILE_IDENTIFIER: u32 = 1701603654;
pub const XP3_INDEX_INFO_IDENTIFIER: u32 = 1868983913;
pub const XP3_INDEX_SEGM_IDENTIFIER: u32 = 1835492723;
pub const XP3_INDEX_ADLR_IDENTIFIER: u32 = 1919706209;
pub const XP3_INDEX_TIME_IDENTIFIER: u32 = 1701669236;
#[derive(Debug)]
pub struct XP3Error {
kind: XP3ErrorKind,
error: Option<Box<dyn Error>>
}
impl XP3Error {
pub fn new(kind: XP3ErrorKind, error: Option<Box<dyn Error>>) -> Self {
Self {
kind, error
}
}
pub fn kind(&self) -> &XP3ErrorKind {
&self.kind
}
pub fn error(&self) -> &Option<Box<dyn Error>> {
&self.error
}
}
impl From<io::Error> for XP3Error {
fn from(err: io::Error) -> Self {
XP3Error::new(XP3ErrorKind::Io(err), None)
}
}
#[derive(Debug)]
pub enum XP3ErrorKind {
Io(io::Error),
InvalidFile,
InvalidHeader,
InvalidFileIndexHeader,
InvalidFileIndex,
InvalidFileIndexFlag,
FileNotFound
}
#[derive(Debug)]
pub struct VirtualXP3 {
header: XP3Header,
index_set: XP3IndexSet
}
impl VirtualXP3 {
pub fn new(
header: XP3Header,
index_set: XP3IndexSet
) -> Self {
Self {
header,
index_set
}
}
pub fn header(&self) -> XP3Header {
self.header
}
pub fn set_header(&mut self, header: XP3Header) {
self.header = header;
}
pub fn index_set(&self) -> &XP3IndexSet {
&self.index_set
}
pub fn set_index_set(&mut self, index_set: XP3IndexSet) {
self.index_set = index_set;
}
}