From b030b9de9345d7b1cfef205e5b9a1e2c7dc6025e Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 18 Dec 2021 20:33:16 -0600 Subject: nbt --- azalea-nbt/src/decode.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'azalea-nbt/src/decode.rs') diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index 704c8e2a..f3fbae54 100644 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -1,10 +1,12 @@ use crate::Error; use crate::Tag; use byteorder::{ReadBytesExt, BE}; +use flate2::read::{GzDecoder, ZlibDecoder}; use std::{collections::HashMap, io::Read}; impl Tag { fn read_known(stream: &mut impl Read, id: u8) -> Result { + println!("read_known: id={}", id); let tag = match id { // Signifies the end of a TAG_Compound. It is only ever used inside // a TAG_Compound, and is not named despite being in a TAG_Compound @@ -65,7 +67,9 @@ impl Tag { 10 => { let mut map = HashMap::new(); loop { + println!("compound loop"); let tag_id = stream.read_u8().unwrap_or(0); + println!("compound loop tag_id={}", tag_id); if tag_id == 0 { break; } @@ -108,4 +112,14 @@ impl Tag { // default to compound tag Tag::read_known(stream, 10) } + + pub fn read_zlib(stream: &mut impl Read) -> Result { + let mut gz = ZlibDecoder::new(stream); + Tag::read(&mut gz) + } + + pub fn read_gzip(stream: &mut impl Read) -> Result { + let mut gz = GzDecoder::new(stream); + Tag::read(&mut gz) + } } -- cgit v1.2.3