重写又一遍(

This commit is contained in:
shenjack 2023-08-04 00:21:50 +08:00
parent fd9a9168ea
commit 42055ae6a9
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 16 additions and 6 deletions

View File

@ -3,3 +3,7 @@
nbt解析器 by shenjack nbt解析器 by shenjack
writen in rust! writen in rust!
感谢 @神楽坂柚咲/伊欧/langyo
在编写过程中的帮助(

View File

@ -1,5 +1,7 @@
use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::{Cursor, Read, Seek, SeekFrom}; use std::io::{Cursor, Read, Seek, SeekFrom};
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
/// NBT 里除了字符串的长度量都是 i32 /// NBT 里除了字符串的长度量都是 i32
@ -16,7 +18,7 @@ pub type Reader<'a> = Cursor<&'a [u8]>;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum NbtItem<T: NbtListTrait> { pub enum NbtItem<T: NbtListTrait> {
Value(NbtValue), Value(NbtValue),
Array(NbtList<T>), Array(NbtList),
} }
/// 一个 NBT list 的基本素养 /// 一个 NBT list 的基本素养
@ -40,12 +42,16 @@ pub trait NbtListTrait {
} }
/// 通过范型实现的 NBT List (其实包括了 NbtCompound) /// 通过范型实现的 NBT List (其实包括了 NbtCompound)
#[derive(Debug, Clone)] // #[derive(Debug, Clone)]
pub struct NbtList<T: NbtListTrait> { // pub struct NbtList<T: NbtListTrait> {
/// 内容 // /// 内容
pub value: T, // pub value: T,
// }
pub enum NbtList {
BoolArray(Rc<RefCell<Vec<bool>>>)
} }
#[allow(unused)] #[allow(unused)]
impl<T> NbtList<T> impl<T> NbtList<T>
where where
@ -168,7 +174,7 @@ where
[0x07] => { [0x07] => {
for _ in 0..len { for _ in 0..len {
for _ in 0..len { for _ in 0..len {
vec.push(NbtItem::Array(NbtList::<Vec<bool>>::from_reader(value))); vec.push(NbtItem::Array( todo!() ));
} }
} }
} }