Compare commits

..

2 Commits

Author SHA1 Message Date
8d7d802c45
aaa 2023-08-05 11:28:52 +08:00
8e05b2cd69
add more From 2023-08-05 11:28:39 +08:00
2 changed files with 17 additions and 2 deletions

View File

@ -71,6 +71,16 @@ impl NbtItem {
} }
} }
impl From<NbtValue> for NbtItem {
#[inline]
fn from(value: NbtValue) -> Self { Self::Value(value) }
}
impl From<NbtList> for NbtItem {
#[inline]
fn from(value: NbtList) -> Self { Self::Array(value) }
}
impl From<Vec<NbtItem>> for NbtList { impl From<Vec<NbtItem>> for NbtList {
#[inline] #[inline]
fn from(value: Vec<NbtItem>) -> Self { Self::List(Rc::new(RefCell::new(value))) } fn from(value: Vec<NbtItem>) -> Self { Self::List(Rc::new(RefCell::new(value))) }

View File

@ -14,9 +14,9 @@ use std::rc::Rc;
/// (0x0C) Vec<i64> /// (0x0C) Vec<i64>
pub mod read { pub mod read {
use crate::data::{NbtItem, NbtLength, NbtList, NbtValue, Reader}; use crate::data::{NbtItem, NbtLength, NbtList, NbtValue, Reader};
use std::cell::RefCell;
use std::io::Read; use std::io::Read;
use std::rc::Rc; use std::collections::HashMap;
use std::sync::Arc;
/// 直接读取长度和值 不带名称 /// 直接读取长度和值 不带名称
/// 反正名字都在外面读过 /// 反正名字都在外面读过
@ -62,6 +62,7 @@ pub mod read {
} }
/// 直接读取长度和值 不带名称 /// 直接读取长度和值 不带名称
/// 主要是为了可以直接递归 (
pub fn read_nbt_list(value: &mut Reader) -> Vec<NbtItem> { pub fn read_nbt_list(value: &mut Reader) -> Vec<NbtItem> {
// 读取长度 // 读取长度
let mut buff = [0_u8; 4]; let mut buff = [0_u8; 4];
@ -73,6 +74,7 @@ pub mod read {
_ = value.read(&mut type_buff).unwrap(); _ = value.read(&mut type_buff).unwrap();
match type_buff { match type_buff {
[0x00] => { [0x00] => {
// End
todo!() todo!()
} }
[0x01] => { [0x01] => {
@ -128,6 +130,9 @@ pub mod read {
[0x0A] => { [0x0A] => {
// Compound // Compound
// 他甚至不告诉你有多少个元素,要命 // 他甚至不告诉你有多少个元素,要命
for _ in 0..len {
vec.push(NbtItem::Array(NbtList::from(from_compound(value))));
}
} }
[0x0B] => { [0x0B] => {
// IntArray // IntArray