来力(还在写 NbtList

This commit is contained in:
shenjack-mac 2023-08-03 12:25:11 +08:00
parent 2986ecfb96
commit 32099a201b

View File

@ -114,14 +114,34 @@ where
fn get_name(&self, _: &str) -> Option<Self::ValueType> { None } fn get_name(&self, _: &str) -> Option<Self::ValueType> { None }
} }
/// NbtList
/// 来力
impl<T> NbtList<Vec<NbtItem<T>>>
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<T> = Vec::with_capacity(len as usize);
todo!()
}
}
/// ByteArray /// ByteArray
#[allow(unused)]
impl NbtList<Vec<bool>> { impl NbtList<Vec<bool>> {
/// 直接读取长度和值 不带名称 /// 直接读取长度和值 不带名称
pub fn from_reader(value: &mut Reader) -> Self { pub fn from_reader(value: &mut Reader) -> Self {
// 读取长度
let mut buff = [0_u8; 4]; let mut buff = [0_u8; 4];
_ = value.read(&mut buff).unwrap(); _ = value.read(&mut buff).unwrap();
let len = NbtLength::from_be_bytes(buff); let len = NbtLength::from_be_bytes(buff);
let mut vec = Vec::with_capacity(len as usize); let mut vec = Vec::with_capacity(len as usize);
// 读取内容
for _ in 0..len { for _ in 0..len {
vec.push(NbtValue::from_bool(value).as_bool().unwrap()); vec.push(NbtValue::from_bool(value).as_bool().unwrap());
} }
@ -130,13 +150,16 @@ impl NbtList<Vec<bool>> {
} }
/// IntArray /// IntArray
#[allow(unused)]
impl NbtList<Vec<i32>> { impl NbtList<Vec<i32>> {
/// 直接读取长度和值 不带名称 /// 直接读取长度和值 不带名称
pub fn from_reader(value: &mut Reader) -> Self { pub fn from_reader(value: &mut Reader) -> Self {
// 读取长度
let mut buff = [0_u8; 4]; let mut buff = [0_u8; 4];
_ = value.read(&mut buff).unwrap(); _ = value.read(&mut buff).unwrap();
let len = NbtLength::from_be_bytes(buff); let len = NbtLength::from_be_bytes(buff);
let mut vec = Vec::with_capacity(len as usize); let mut vec = Vec::with_capacity(len as usize);
// 读取内容
for _ in 0..len { for _ in 0..len {
vec.push(NbtValue::from_i32(value).as_i32().unwrap()); vec.push(NbtValue::from_i32(value).as_i32().unwrap());
} }
@ -145,13 +168,16 @@ impl NbtList<Vec<i32>> {
} }
/// LongArray /// LongArray
#[allow(unused)]
impl NbtList<Vec<i64>> { impl NbtList<Vec<i64>> {
/// 直接读取长度和值 不带名称 /// 直接读取长度和值 不带名称
pub fn from_reader(value: &mut Reader) -> Self { pub fn from_reader(value: &mut Reader) -> Self {
// 读取长度
let mut buff = [0_u8; 4]; let mut buff = [0_u8; 4];
_ = value.read(&mut buff).unwrap(); _ = value.read(&mut buff).unwrap();
let len = NbtLength::from_be_bytes(buff); let len = NbtLength::from_be_bytes(buff);
let mut vec = Vec::with_capacity(len as usize); let mut vec = Vec::with_capacity(len as usize);
// 读取内容
for _ in 0..len { for _ in 0..len {
vec.push(NbtValue::from_i64(value).as_i64().unwrap()); vec.push(NbtValue::from_i64(value).as_i64().unwrap());
} }