azalea_nbt/
lib.rs

1#![doc = include_str!("../README.md")]
2#![feature(min_specialization)]
3
4mod decode;
5mod encode;
6mod error;
7mod tag;
8
9pub use error::Error;
10pub use tag::*;
11
12#[cfg(test)]
13mod tests {
14    use std::io::Cursor;
15
16    use crate::tag::NbtCompound;
17
18    use super::*;
19    use azalea_buf::{McBufReadable, McBufWritable};
20
21    #[test]
22    fn mcbuf_nbt() {
23        let mut buf = Vec::new();
24        let tag = Nbt::Compound(NbtCompound::from_iter(vec![(
25            "hello world".into(),
26            Nbt::Compound(NbtCompound::from_iter(vec![(
27                "name".into(),
28                Nbt::String("Bananrama".into()),
29            )])),
30        )]));
31        tag.write_into(&mut buf).unwrap();
32
33        let mut buf = Cursor::new(&buf[..]);
34
35        let result = Nbt::read_from(&mut buf).unwrap();
36        assert_eq!(
37            result,
38            Nbt::Compound(NbtCompound::from_iter(vec![(
39                "hello world".into(),
40                Nbt::Compound(NbtCompound::from_iter(vec![(
41                    "name".into(),
42                    Nbt::String("Bananrama".into()),
43                )])),
44            )]))
45        );
46    }
47}