实现了NBT版本枚举和读取方法
This commit is contained in:
parent
88a2092e67
commit
65e7bfb186
@ -3,6 +3,26 @@ pub enum Endian {
|
|||||||
Little,
|
Little,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 后面也许会实现的
|
||||||
|
///
|
||||||
|
/// 不同版本的 Nbt 数据细节不同
|
||||||
|
/// 老要命了
|
||||||
|
///
|
||||||
|
/// - `Java`
|
||||||
|
/// Java 版除了 1.20.2+(协议号) 及以后的网络 NBT 格式
|
||||||
|
/// - `JavaNetAfter1_20_2`
|
||||||
|
/// 1.20.2+(协议号 >= 764) 及以后的网络 NBT 格式
|
||||||
|
/// - `BedrockDisk`
|
||||||
|
/// 基岩版 实际用于存储的 NBT 格式
|
||||||
|
/// - `BedrockNetVarInt`
|
||||||
|
/// 基岩版 网络 NBT 格式
|
||||||
|
pub enum NbtVersion {
|
||||||
|
Java,
|
||||||
|
JavaNetAfter1_20_2,
|
||||||
|
BedrockDisk,
|
||||||
|
BedrockNetVarInt,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
@ -41,7 +61,6 @@ impl NbtReader<'_> {
|
|||||||
NbtReader {
|
NbtReader {
|
||||||
data,
|
data,
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
// endian: Endian::Big,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// 向后滚动
|
/// 向后滚动
|
||||||
@ -301,19 +320,15 @@ impl NbtReader<'_> {
|
|||||||
/// 读取一个 NBT byte array
|
/// 读取一个 NBT byte array
|
||||||
pub fn read_nbt_i8_array(&mut self) -> Vec<i8> {
|
pub fn read_nbt_i8_array(&mut self) -> Vec<i8> {
|
||||||
let len = self.read_i32() as usize;
|
let len = self.read_i32() as usize;
|
||||||
let value = unsafe {
|
let value = unsafe { self.read_i8_array_unchecked(len) };
|
||||||
self.read_i8_array_unchecked(len)
|
|
||||||
};
|
|
||||||
self.cursor += len;
|
self.cursor += len;
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 读取一个 NBT int array
|
/// 读取一个 NBT int array
|
||||||
pub fn read_nbt_i32_array(&mut self) -> Vec<i32> {
|
pub fn read_nbt_i32_array(&mut self) -> Vec<i32> {
|
||||||
let len = self.read_i32() as usize;
|
let len = self.read_i32() as usize;
|
||||||
let value = unsafe {
|
let value = unsafe { self.read_i32_array_unchecked(len) };
|
||||||
self.read_i32_array_unchecked(len)
|
|
||||||
};
|
|
||||||
self.cursor += len * 4;
|
self.cursor += len * 4;
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
@ -321,9 +336,7 @@ impl NbtReader<'_> {
|
|||||||
/// 读取一个 NBT long array
|
/// 读取一个 NBT long array
|
||||||
pub fn read_nbt_i64_array(&mut self) -> Vec<i64> {
|
pub fn read_nbt_i64_array(&mut self) -> Vec<i64> {
|
||||||
let len = self.read_i32() as usize;
|
let len = self.read_i32() as usize;
|
||||||
let value = unsafe {
|
let value = unsafe { self.read_i64_array_unchecked(len) };
|
||||||
self.read_i64_array_unchecked(len)
|
|
||||||
};
|
|
||||||
self.cursor += len * 8;
|
self.cursor += len * 8;
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
@ -334,7 +347,6 @@ impl NbtReader<'_> {
|
|||||||
let value = self.read_string(len);
|
let value = self.read_string(len);
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -378,11 +390,9 @@ impl NbtValue {
|
|||||||
NbtValue::from_reader(reader)
|
NbtValue::from_reader(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inner_read(reader: &mut NbtReader) -> NbtValue {
|
fn inner_read(reader: &mut NbtReader) -> NbtValue { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_reader(mut reader: NbtReader) -> NbtValue {
|
pub fn from_reader(mut reader: NbtReader) -> NbtValue {
|
||||||
// 第一个 tag, 不可能是 0
|
// 第一个 tag, 不可能是 0
|
||||||
match reader.read_u8() {
|
match reader.read_u8() {
|
||||||
0 => unreachable!(),
|
0 => unreachable!(),
|
||||||
@ -395,8 +405,9 @@ impl NbtValue {
|
|||||||
7 => NbtValue::ByteArray(reader.read_nbt_i8_array()),
|
7 => NbtValue::ByteArray(reader.read_nbt_i8_array()),
|
||||||
8 => NbtValue::String(reader.read_nbt_string()),
|
8 => NbtValue::String(reader.read_nbt_string()),
|
||||||
|
|
||||||
|
11 => NbtValue::IntArray(reader.read_nbt_i32_array()),
|
||||||
_ => unimplemented!()
|
12 => NbtValue::LongArray(reader.read_nbt_i64_array()),
|
||||||
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user