aboutsummaryrefslogtreecommitdiff
path: root/azalea-nbt/src/lib.rs
blob: fe0c34cbb50c64047d4a7530987f431f08da4075 (plain)
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
#![doc = include_str!("../README.md")]
#![feature(min_specialization)]

mod decode;
mod encode;
mod error;
mod tag;

pub use error::Error;
pub use tag::{Nbt, NbtCompound, NbtList};

#[cfg(test)]
mod tests {
    use std::io::Cursor;

    use crate::tag::NbtCompound;

    use super::*;
    use azalea_buf::{McBufReadable, McBufWritable};

    #[test]
    fn mcbuf_nbt() {
        let mut buf = Vec::new();
        let tag = Nbt::Compound(NbtCompound::from_iter(vec![(
            "hello world".into(),
            Nbt::Compound(NbtCompound::from_iter(vec![(
                "name".into(),
                Nbt::String("Bananrama".into()),
            )])),
        )]));
        tag.write_into(&mut buf).unwrap();

        let mut buf = Cursor::new(&buf[..]);

        let result = Nbt::read_from(&mut buf).unwrap();
        assert_eq!(
            result,
            Nbt::Compound(NbtCompound::from_iter(vec![(
                "hello world".into(),
                Nbt::Compound(NbtCompound::from_iter(vec![(
                    "name".into(),
                    Nbt::String("Bananrama".into()),
                )])),
            )]))
        );
    }
}