mirror of
https://github.com/azalea-rs/simdnbt.git
synced 2025-08-02 15:36:03 +00:00
add NbtTag::read_optional
This commit is contained in:
parent
00c6ad1b41
commit
922701104a
4 changed files with 22 additions and 1 deletions
|
@ -23,6 +23,8 @@ fastnbt = "2.4.4"
|
||||||
azalea-nbt = { git = "https://github.com/azalea-rs/azalea", rev = "84e036ce3752ecf57904b0f5aff1f33d43e95a32" }
|
azalea-nbt = { git = "https://github.com/azalea-rs/azalea", rev = "84e036ce3752ecf57904b0f5aff1f33d43e95a32" }
|
||||||
hematite-nbt = { version = "0.5.2", default-features = false }
|
hematite-nbt = { version = "0.5.2", default-features = false }
|
||||||
|
|
||||||
|
tikv-jemallocator = "0.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["derive"]
|
default = ["derive"]
|
||||||
derive = ["dep:simdnbt-derive"]
|
derive = ["dep:simdnbt-derive"]
|
||||||
|
|
|
@ -46,8 +46,11 @@ fn bench_file(filename: &str, c: &mut Criterion) {
|
||||||
group.finish();
|
group.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||||
|
|
||||||
fn bench(c: &mut Criterion) {
|
fn bench(c: &mut Criterion) {
|
||||||
// bench_file("bigtest.nbt", c);
|
bench_file("bigtest.nbt", c);
|
||||||
// bench_file("simple_player.dat", c);
|
// bench_file("simple_player.dat", c);
|
||||||
bench_file("complex_player.dat", c);
|
bench_file("complex_player.dat", c);
|
||||||
// bench_file("level.dat", c);
|
// bench_file("level.dat", c);
|
||||||
|
|
|
@ -170,6 +170,14 @@ impl<'a> NbtTag<'a> {
|
||||||
Self::read_with_type(data, tag_type, 0)
|
Self::read_with_type(data, tag_type, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_optional(data: &mut Cursor<&'a [u8]>) -> Result<Option<Self>, Error> {
|
||||||
|
let tag_type = data.read_u8().map_err(|_| Error::UnexpectedEof)?;
|
||||||
|
if tag_type == END_ID {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
Ok(Some(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),
|
||||||
|
|
|
@ -264,6 +264,14 @@ impl NbtTag {
|
||||||
Self::read_with_type(data, tag_type, 0)
|
Self::read_with_type(data, tag_type, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_optional(data: &mut Cursor<&[u8]>) -> Result<Option<Self>, Error> {
|
||||||
|
let tag_type = data.read_u8().map_err(|_| Error::UnexpectedEof)?;
|
||||||
|
if tag_type == END_ID {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
Ok(Some(Self::read_with_type(data, tag_type, 0)?))
|
||||||
|
}
|
||||||
|
|
||||||
/// Write to the data without checking that there's enough space in it.
|
/// Write to the data without checking that there's enough space in it.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
Loading…
Add table
Reference in a new issue