diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-11-19 22:07:38 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 22:07:38 -0600 |
| commit | 2c610826fc9f8e16897f52313faa8e0602d1dc3d (patch) | |
| tree | 5aad79ecab3b68511a10ebd7eba07af0bd8a5905 /azalea-buf/src | |
| parent | 84e036ce3752ecf57904b0f5aff1f33d43e95a32 (diff) | |
| download | azalea-drasl-2c610826fc9f8e16897f52313faa8e0602d1dc3d.tar.xz | |
Replace azalea-nbt with simdnbt (#111)
* delete azalea-nbt and replace with simdnbt
* use simdnbt from crates.io
* remove serde dependency on azalea-registry
Diffstat (limited to 'azalea-buf/src')
| -rwxr-xr-x | azalea-buf/src/read.rs | 33 | ||||
| -rwxr-xr-x | azalea-buf/src/write.rs | 24 |
2 files changed, 57 insertions, 0 deletions
diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs index 78db7357..d5c4d0a8 100755 --- a/azalea-buf/src/read.rs +++ b/azalea-buf/src/read.rs @@ -50,6 +50,18 @@ pub enum BufReadError { #[backtrace] source: serde_json::Error, }, + #[error("{source}")] + Nbt { + #[from] + #[backtrace] + source: simdnbt::Error, + }, + #[error("{source}")] + DeserializeNbt { + #[from] + #[backtrace] + source: simdnbt::DeserializeError, + }, } fn read_bytes<'a>(buf: &'a mut Cursor<&[u8]>, length: usize) -> Result<&'a [u8], BufReadError> { @@ -340,3 +352,24 @@ impl<T: McBufReadable, const N: usize> McBufReadable for [T; N] { }) } } + +impl McBufReadable for simdnbt::owned::NbtTag { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + Ok(simdnbt::owned::NbtTag::read(buf)?) + } +} + +impl McBufReadable for simdnbt::owned::NbtCompound { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + match simdnbt::owned::NbtTag::read(buf)? { + simdnbt::owned::NbtTag::Compound(compound) => Ok(compound), + _ => Err(BufReadError::Custom("Expected compound tag".to_string())), + } + } +} + +impl McBufReadable for simdnbt::owned::Nbt { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + Ok(simdnbt::owned::Nbt::read_unnamed(buf)?) + } +} diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs index f48bf2ec..03d40d79 100755 --- a/azalea-buf/src/write.rs +++ b/azalea-buf/src/write.rs @@ -257,3 +257,27 @@ impl<T: McBufWritable, const N: usize> McBufWritable for [T; N] { Ok(()) } } + +impl McBufWritable for simdnbt::owned::NbtTag { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut data = Vec::new(); + self.write(&mut data); + data.write_into(buf) + } +} + +impl McBufWritable for simdnbt::owned::NbtCompound { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut data = Vec::new(); + simdnbt::owned::NbtTag::Compound(self.clone()).write(&mut data); + data.write_into(buf) + } +} + +impl McBufWritable for simdnbt::owned::Nbt { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut data = Vec::new(); + self.write_unnamed(&mut data); + data.write_into(buf) + } +} |
