From fd9a9168eaf858085ad6ca780f813144f5f0fffb Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 4 Aug 2023 00:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=B2=A1=E5=AE=8C=E5=85=A8=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- src/data.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 412abc3..9bab3f8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # nbt-rust -nbt解析器 by shenjack -writen in rust! \ No newline at end of file +nbt解析器 by shenjack + +writen in rust! diff --git a/src/data.rs b/src/data.rs index 8a19b88..f8fafbd 100644 --- a/src/data.rs +++ b/src/data.rs @@ -116,6 +116,7 @@ where /// NbtList /// 来力 +#[allow(unused)] impl NbtList>> where T: NbtListTrait + Clone, @@ -126,7 +127,52 @@ where let mut buff = [0_u8; 4]; _ = value.read(&mut buff).unwrap(); let len = NbtLength::from_be_bytes(buff); - let mut vec: Vec = Vec::with_capacity(len as usize); + let mut vec: Vec> = Vec::with_capacity(len as usize); + // 先读取 type + let mut type_buff = [0_u8; 1]; + _ = value.read(&mut type_buff).unwrap(); + match type_buff { + [0x00] => { + todo!() + } + [0x01] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_bool(value))); + } + } + [0x02] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_i16(value))); + } + } + [0x03] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_i32(value))); + } + } + [0x04] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_i64(value))); + } + } + [0x05] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_f32(value))); + } + } + [0x06] => { + for _ in 0..len { + vec.push(NbtItem::Value(NbtValue::from_f64(value))); + } + } + [0x07] => { + for _ in 0..len { + for _ in 0..len { + vec.push(NbtItem::Array(NbtList::>::from_reader(value))); + } + } + } + } todo!() } }