From 32099a201b8d66847e0ca527b9d71a01c40a5787 Mon Sep 17 00:00:00 2001 From: shenjack-mac <3695888@qq.com> Date: Thu, 3 Aug 2023 12:25:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A5=E5=8A=9B=EF=BC=88=E8=BF=98=E5=9C=A8?= =?UTF-8?q?=E5=86=99=20NbtList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/data.rs b/src/data.rs index 9cdeabd..8a19b88 100644 --- a/src/data.rs +++ b/src/data.rs @@ -114,14 +114,34 @@ where fn get_name(&self, _: &str) -> Option { None } } +/// NbtList +/// 来力 +impl NbtList>> +where + T: NbtListTrait + Clone, +{ + /// 直接读取长度和值 不带名称 + pub fn from_reader(value: &mut Reader) -> Self { + // 读取长度 + 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); + todo!() + } +} + /// ByteArray +#[allow(unused)] impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { + // 读取长度 let mut buff = [0_u8; 4]; _ = value.read(&mut buff).unwrap(); let len = NbtLength::from_be_bytes(buff); let mut vec = Vec::with_capacity(len as usize); + // 读取内容 for _ in 0..len { vec.push(NbtValue::from_bool(value).as_bool().unwrap()); } @@ -130,13 +150,16 @@ impl NbtList> { } /// IntArray +#[allow(unused)] impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { + // 读取长度 let mut buff = [0_u8; 4]; _ = value.read(&mut buff).unwrap(); let len = NbtLength::from_be_bytes(buff); let mut vec = Vec::with_capacity(len as usize); + // 读取内容 for _ in 0..len { vec.push(NbtValue::from_i32(value).as_i32().unwrap()); } @@ -145,13 +168,16 @@ impl NbtList> { } /// LongArray +#[allow(unused)] impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { + // 读取长度 let mut buff = [0_u8; 4]; _ = value.read(&mut buff).unwrap(); let len = NbtLength::from_be_bytes(buff); let mut vec = Vec::with_capacity(len as usize); + // 读取内容 for _ in 0..len { vec.push(NbtValue::from_i64(value).as_i64().unwrap()); }