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
use crate::prelude::*;
#[cfg_attr(feature = "ser-de", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct CollectionList {
pub version: u32,
pub collections: Vec<Collection>,
}
impl CollectionList {
pub fn from_bytes(bytes: &[u8]) -> Result<CollectionList, Error> {
Ok(collections(bytes).map(|(_rem, collections)| collections)?)
}
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<CollectionList, Error> {
Self::from_bytes(&fs::read(path)?)
}
pub fn to_writer<W: Write>(&self, mut out: W) -> io::Result<()> {
self.wr(&mut out)
}
pub fn to_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
self.to_writer(BufWriter::new(File::create(path)?))
}
}
#[cfg_attr(feature = "ser-de", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Collection {
pub name: Option<String>,
pub beatmap_hashes: Vec<Option<String>>,
}
named!(collections<&[u8], CollectionList>, do_parse!(
version: int >>
collections: length_count!(int, do_parse!(
name: opt_string >>
beatmap_hashes: length_count!(int, opt_string) >>
(Collection { name, beatmap_hashes })
)) >>
(CollectionList { version, collections })
));
writer!(CollectionList [this,out] {
this.version.wr(out)?;
PrefixedList(&this.collections).wr(out)?;
});
writer!(Collection [this,out] {
this.name.wr(out)?;
PrefixedList(&this.beatmap_hashes).wr(out)?;
});