diff options
| author | mat <github@matdoes.dev> | 2022-06-23 15:12:17 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-23 15:12:17 -0500 |
| commit | 5ca49e680ed8519456dc9a9af84321d4b69dcbb3 (patch) | |
| tree | 0f727c3e862f60eb227db69c87946a0f629a397d /azalea-nbt/src | |
| parent | c7b0c51274b5d8548c8a2f829b75dfbec4038be2 (diff) | |
| download | azalea-drasl-5ca49e680ed8519456dc9a9af84321d4b69dcbb3.tar.xz | |
azalea-buf
Diffstat (limited to 'azalea-nbt/src')
| -rwxr-xr-x | azalea-nbt/src/decode.rs | 10 | ||||
| -rwxr-xr-x | azalea-nbt/src/encode.rs | 7 | ||||
| -rwxr-xr-x | azalea-nbt/src/lib.rs | 33 |
3 files changed, 50 insertions, 0 deletions
diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index 7f2ca754..73cd613e 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -136,3 +136,13 @@ impl Tag { Tag::read(&mut gz) } } + +impl McBufReadable for Tag { + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + match Tag::read(self) { + Ok(r) => Ok(r), + // Err(e) => Err(e.to_string()), + Err(e) => Err(e.to_string()).unwrap(), + } + } +} diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs index fb5585b3..17d20270 100755 --- a/azalea-nbt/src/encode.rs +++ b/azalea-nbt/src/encode.rs @@ -217,3 +217,10 @@ impl Tag { self.write(&mut encoder) } } + +impl McBufWritable for Tag { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + self.write(buf) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string())) + } +} diff --git a/azalea-nbt/src/lib.rs b/azalea-nbt/src/lib.rs index d14fd929..8cca1f2b 100755 --- a/azalea-nbt/src/lib.rs +++ b/azalea-nbt/src/lib.rs @@ -5,3 +5,36 @@ mod tag; pub use error::Error; pub use tag::Tag; + +#[cfg(test)] +mod tests { + use super::*; + use std::{collections::HashMap, io::Cursor}; + + #[test] + fn mcbuf_nbt() { + let mut buf = Vec::new(); + buf.write_nbt(&Tag::Compound(HashMap::from_iter(vec![( + "hello world".to_string(), + Tag::Compound(HashMap::from_iter(vec![( + "name".to_string(), + Tag::String("Bananrama".to_string()), + )])), + )]))) + .unwrap(); + + let mut buf = Cursor::new(buf); + + let result = buf.read_nbt().unwrap(); + assert_eq!( + result, + Tag::Compound(HashMap::from_iter(vec![( + "hello world".to_string(), + Tag::Compound(HashMap::from_iter(vec![( + "name".to_string(), + Tag::String("Bananrama".to_string()), + )])), + )])) + ); + } +} |
