diff --git a/src/data.rs b/src/data.rs index ee98eec..0b091a0 100644 --- a/src/data.rs +++ b/src/data.rs @@ -25,7 +25,7 @@ pub trait NbtListTrait { /// 输出类型标识符 /// 类型标识符 /// (0x07) Vec - /// (0x09) Vec + /// (0x09) Vec /// (0x0A) Compound /// (0x0B) Vec /// (0x0C) Vec @@ -94,6 +94,35 @@ where fn get_name(&self, name: &str) -> Option { self.get(name).cloned() } } +impl NbtListTrait for Vec> +where + T: Clone + NbtListTrait, +{ + type ValueType = NbtItem; + #[inline] + fn type_tag() -> u8 { 0x09 } + #[inline] + fn len(&self) -> usize { self.len() } + #[inline] + fn get_index(&self, index: usize) -> Option { self.get(index).cloned() } + #[inline] + fn get_name(&self, _: &str) -> Option { None } +} + +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()); + } + Self { value: vec } + } +} + impl NbtList> { /// 直接读取长度和值 不带名称 pub fn from_reader(value: &mut Reader) -> Self { @@ -108,6 +137,20 @@ impl NbtList> { } } +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()); + } + Self { value: vec } + } +} + /// 基本 NBT 数据类型 #[allow(unused)] #[derive(Debug, Clone)]