1pub mod reader;
2pub mod unpack;
3pub mod writer;
4
5use std::collections::HashMap;
6
7use uuid::Uuid;
8
9#[derive(Clone, Debug, PartialEq)]
10pub struct Package {
11 pub assets: HashMap<Uuid, PackageAsset>,
12}
13
14impl Package {
15 pub fn new() -> Self {
16 Package {
17 assets: HashMap::new(),
18 }
19 }
20}
21
22impl Default for Package {
23 fn default() -> Self {
24 Self::new()
25 }
26}
27
28#[derive(Clone, Debug, PartialEq)]
29pub struct PackageAsset {
30 pub pathname: String,
31 pub preview: Option<Vec<u8>>,
32 pub meta: Option<Vec<u8>>,
33 pub data: Option<Vec<u8>>,
34}
35
36impl PackageAsset {
37 pub fn new(pathname: String) -> Self {
38 PackageAsset {
39 pathname,
40 preview: None,
41 meta: None,
42 data: None,
43 }
44 }
45}
46
47#[derive(Debug, Default)]
48pub struct PackageAssetBuilder {
49 pub pathname: Option<String>,
50 pub preview: Option<Vec<u8>>,
51 pub meta: Option<Vec<u8>>,
52 pub data: Option<Vec<u8>>,
53}
54
55impl PackageAssetBuilder {
56 pub fn with_pathname(mut self, pathname: String) -> PackageAssetBuilder {
57 self.pathname = Some(pathname);
58 self
59 }
60
61 pub fn with_preview(mut self, preview: Vec<u8>) -> PackageAssetBuilder {
62 self.preview = Some(preview);
63 self
64 }
65
66 pub fn with_meta(mut self, meta: Vec<u8>) -> PackageAssetBuilder {
67 self.meta = Some(meta);
68 self
69 }
70
71 pub fn with_data(mut self, data: Vec<u8>) -> PackageAssetBuilder {
72 self.data = Some(data);
73 self
74 }
75
76 pub fn build(self) -> PackageAsset {
77 PackageAsset {
78 pathname: self.pathname.expect("Asset has a required path"),
79 preview: self.preview,
80 meta: self.meta,
81 data: self.data,
82 }
83 }
84}
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 #[test]
91 fn create_package() {
92 let package_from_internal = Package {
93 assets: HashMap::new(),
94 };
95 let package = Package::new();
96
97 assert_eq!(package_from_internal, package);
98 }
99
100 #[test]
101 fn create_package_asset() {
102 let packageasset_from_internal = PackageAsset {
103 pathname: String::from("Assets/TestMaterial.mat"),
104 preview: None,
105 meta: None,
106 data: None,
107 };
108 let packageasset = PackageAsset::new(String::from("Assets/TestMaterial.mat"));
109
110 assert_eq!(packageasset_from_internal, packageasset);
111 }
112}