mirror of
https://github.com/azalea-rs/simdnbt.git
synced 2025-08-02 15:36:03 +00:00
Release 0.3.0
simdnbt@0.3.0 simdnbt-derive@0.3.0 Generated by cargo-workspaces
This commit is contained in:
parent
049b604498
commit
d427ea3f55
6 changed files with 57 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "simdnbt-derive"
|
name = "simdnbt-derive"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Derive macros for simdnbt"
|
description = "Derive macros for simdnbt"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "simdnbt"
|
name = "simdnbt"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "an unnecessarily fast nbt decoder"
|
description = "an unnecessarily fast nbt decoder"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -12,7 +12,7 @@ repository = "https://github.com/mat-1/simdnbt"
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.5.0"
|
||||||
flate2 = "^1.0.28"
|
flate2 = "^1.0.28"
|
||||||
residua-mutf8 = "2.0.0"
|
residua-mutf8 = "2.0.0"
|
||||||
simdnbt-derive = { version = "0.2.0", path = "../simdnbt-derive", optional = true }
|
simdnbt-derive = { version = "0.3.0", path = "../simdnbt-derive", optional = true }
|
||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use byteorder::{ReadBytesExt, BE};
|
use byteorder::ReadBytesExt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
read_int_array, read_long_array, read_string, read_with_u32_length, unchecked_extend,
|
read_string, unchecked_extend, unchecked_push, unchecked_write_string, write_string,
|
||||||
unchecked_push, unchecked_write_string, write_string, BYTE_ARRAY_ID, BYTE_ID, COMPOUND_ID,
|
END_ID, MAX_DEPTH,
|
||||||
DOUBLE_ID, END_ID, FLOAT_ID, INT_ARRAY_ID, INT_ID, LIST_ID, LONG_ARRAY_ID, LONG_ID,
|
|
||||||
MAX_DEPTH, SHORT_ID, STRING_ID,
|
|
||||||
},
|
},
|
||||||
Error, Mutf8Str,
|
Error, Mutf8Str,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +13,7 @@ use crate::{
|
||||||
use super::{list::NbtList, NbtTag};
|
use super::{list::NbtList, NbtTag};
|
||||||
|
|
||||||
/// A list of named tags. The order of the tags is preserved.
|
/// A list of named tags. The order of the tags is preserved.
|
||||||
#[derive(Debug, Default, PartialEq)]
|
#[derive(Debug, Default, PartialEq, Clone)]
|
||||||
pub struct NbtCompound<'a> {
|
pub struct NbtCompound<'a> {
|
||||||
values: Vec<(&'a Mutf8Str, NbtTag<'a>)>,
|
values: Vec<(&'a Mutf8Str, NbtTag<'a>)>,
|
||||||
}
|
}
|
||||||
|
@ -41,44 +39,7 @@ impl<'a> NbtCompound<'a> {
|
||||||
}
|
}
|
||||||
let tag_name = read_string(data)?;
|
let tag_name = read_string(data)?;
|
||||||
|
|
||||||
match tag_type {
|
values.push((tag_name, NbtTag::read_with_type(data, tag_type, depth)?));
|
||||||
BYTE_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Byte(data.read_i8().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
SHORT_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Short(data.read_i16::<BE>().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
INT_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Int(data.read_i32::<BE>().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
LONG_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Long(data.read_i64::<BE>().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
FLOAT_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Float(data.read_f32::<BE>().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
DOUBLE_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Double(data.read_f64::<BE>().map_err(|_| Error::UnexpectedEof)?),
|
|
||||||
)),
|
|
||||||
BYTE_ARRAY_ID => {
|
|
||||||
values.push((tag_name, NbtTag::ByteArray(read_with_u32_length(data, 1)?)))
|
|
||||||
}
|
|
||||||
STRING_ID => values.push((tag_name, NbtTag::String(read_string(data)?))),
|
|
||||||
LIST_ID => values.push((tag_name, NbtTag::List(NbtList::read(data, depth + 1)?))),
|
|
||||||
COMPOUND_ID => values.push((
|
|
||||||
tag_name,
|
|
||||||
NbtTag::Compound(NbtCompound::read_with_depth(data, depth + 1)?),
|
|
||||||
)),
|
|
||||||
INT_ARRAY_ID => values.push((tag_name, NbtTag::IntArray(read_int_array(data)?))),
|
|
||||||
LONG_ARRAY_ID => values.push((tag_name, NbtTag::LongArray(read_long_array(data)?))),
|
|
||||||
_ => return Err(Error::UnknownTagId(tag_type)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(Self { values })
|
Ok(Self { values })
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ use super::{read_u32, NbtCompound, MAX_DEPTH};
|
||||||
|
|
||||||
/// A list of NBT tags of a single type.
|
/// A list of NBT tags of a single type.
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Default, PartialEq)]
|
#[derive(Debug, Default, PartialEq, Clone)]
|
||||||
pub enum NbtList<'a> {
|
pub enum NbtList<'a> {
|
||||||
#[default]
|
#[default]
|
||||||
Empty = END_ID,
|
Empty = END_ID,
|
||||||
|
|
|
@ -5,13 +5,13 @@ mod list;
|
||||||
|
|
||||||
use std::{io::Cursor, ops::Deref};
|
use std::{io::Cursor, ops::Deref};
|
||||||
|
|
||||||
use byteorder::ReadBytesExt;
|
use byteorder::{ReadBytesExt, BE};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
read_string, read_u32, write_string, BYTE_ARRAY_ID, BYTE_ID, COMPOUND_ID, DOUBLE_ID,
|
read_int_array, read_long_array, read_string, read_u32, read_with_u32_length, write_string,
|
||||||
END_ID, FLOAT_ID, INT_ARRAY_ID, INT_ID, LIST_ID, LONG_ARRAY_ID, LONG_ID, MAX_DEPTH,
|
BYTE_ARRAY_ID, BYTE_ID, COMPOUND_ID, DOUBLE_ID, END_ID, FLOAT_ID, INT_ARRAY_ID, INT_ID,
|
||||||
SHORT_ID, STRING_ID,
|
LIST_ID, LONG_ARRAY_ID, LONG_ID, MAX_DEPTH, SHORT_ID, STRING_ID,
|
||||||
},
|
},
|
||||||
raw_list::RawList,
|
raw_list::RawList,
|
||||||
Error, Mutf8Str,
|
Error, Mutf8Str,
|
||||||
|
@ -102,7 +102,7 @@ impl<'a> BaseNbt<'a> {
|
||||||
|
|
||||||
/// A single NBT tag.
|
/// A single NBT tag.
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum NbtTag<'a> {
|
pub enum NbtTag<'a> {
|
||||||
Byte(i8) = BYTE_ID,
|
Byte(i8) = BYTE_ID,
|
||||||
Short(i16) = SHORT_ID,
|
Short(i16) = SHORT_ID,
|
||||||
|
@ -128,6 +128,48 @@ impl<'a> NbtTag<'a> {
|
||||||
unsafe { *<*const _>::from(self).cast::<u8>() }
|
unsafe { *<*const _>::from(self).cast::<u8>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_with_type(
|
||||||
|
data: &mut Cursor<&'a [u8]>,
|
||||||
|
tag_type: u8,
|
||||||
|
depth: usize,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
match tag_type {
|
||||||
|
BYTE_ID => Ok(NbtTag::Byte(
|
||||||
|
data.read_i8().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
SHORT_ID => Ok(NbtTag::Short(
|
||||||
|
data.read_i16::<BE>().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
INT_ID => Ok(NbtTag::Int(
|
||||||
|
data.read_i32::<BE>().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
LONG_ID => Ok(NbtTag::Long(
|
||||||
|
data.read_i64::<BE>().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
FLOAT_ID => Ok(NbtTag::Float(
|
||||||
|
data.read_f32::<BE>().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
DOUBLE_ID => Ok(NbtTag::Double(
|
||||||
|
data.read_f64::<BE>().map_err(|_| Error::UnexpectedEof)?,
|
||||||
|
)),
|
||||||
|
BYTE_ARRAY_ID => Ok(NbtTag::ByteArray(read_with_u32_length(data, 1)?)),
|
||||||
|
STRING_ID => Ok(NbtTag::String(read_string(data)?)),
|
||||||
|
LIST_ID => Ok(NbtTag::List(NbtList::read(data, depth + 1)?)),
|
||||||
|
COMPOUND_ID => Ok(NbtTag::Compound(NbtCompound::read_with_depth(
|
||||||
|
data,
|
||||||
|
depth + 1,
|
||||||
|
)?)),
|
||||||
|
INT_ARRAY_ID => Ok(NbtTag::IntArray(read_int_array(data)?)),
|
||||||
|
LONG_ARRAY_ID => Ok(NbtTag::LongArray(read_long_array(data)?)),
|
||||||
|
_ => Err(Error::UnknownTagId(tag_type)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read(data: &mut Cursor<&'a [u8]>) -> Result<Self, Error> {
|
||||||
|
let tag_type = data.read_u8().map_err(|_| Error::UnexpectedEof)?;
|
||||||
|
Self::read_with_type(data, tag_type, 0)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn byte(&self) -> Option<i8> {
|
pub fn byte(&self) -> Option<i8> {
|
||||||
match self {
|
match self {
|
||||||
NbtTag::Byte(byte) => Some(*byte),
|
NbtTag::Byte(byte) => Some(*byte),
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::swap_endianness::{swap_endianness, swap_endianness_as_u8, SwappableNu
|
||||||
|
|
||||||
/// A list of numbers that's kept as big-endian in memory.
|
/// A list of numbers that's kept as big-endian in memory.
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct RawList<'a, T> {
|
pub struct RawList<'a, T> {
|
||||||
data: &'a [u8],
|
data: &'a [u8],
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue