diff options
| author | mat <github@matdoes.dev> | 2023-03-23 13:55:33 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-03-23 13:55:33 +0000 |
| commit | ecb3f2ffd7dd4aa26213844a023e37fab4057ed0 (patch) | |
| tree | 0cd0ea7eec8c05cdc8fae0a3ab15ef7c1402383c /azalea-nbt/src/decode.rs | |
| parent | 2a07962af9a318114f38d3afe748a05212cfbd59 (diff) | |
| download | azalea-drasl-ecb3f2ffd7dd4aa26213844a023e37fab4057ed0.tar.xz | |
rename Tag to Nbt
Diffstat (limited to 'azalea-nbt/src/decode.rs')
| -rwxr-xr-x | azalea-nbt/src/decode.rs | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index e2e9c7c9..5421e1c5 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -169,7 +169,7 @@ fn read_compound(stream: &mut Cursor<&[u8]>) -> Result<NbtCompound, Error> { break; } let name = read_string(stream)?; - let tag = Tag::read_known(stream, tag_id)?; + let tag = Nbt::read_known(stream, tag_id)?; map.insert(name, tag); } Ok(map) @@ -201,36 +201,36 @@ fn read_long_array(stream: &mut Cursor<&[u8]>) -> Result<NbtLongArray, Error> { Ok(longs) } -impl Tag { +impl Nbt { /// Read the NBT data when you already know the ID of the tag. You usually - /// want [`Tag::read`] if you're reading an NBT file. + /// want [`Nbt::read`] if you're reading an NBT file. #[inline] - fn read_known(stream: &mut Cursor<&[u8]>, id: u8) -> Result<Tag, Error> { + fn read_known(stream: &mut Cursor<&[u8]>, id: u8) -> Result<Nbt, Error> { Ok(match id { // Signifies the end of a TAG_Compound. It is only ever used inside // a TAG_Compound, and is not named despite being in a TAG_Compound - END_ID => Tag::End, + END_ID => Nbt::End, // A single signed byte - BYTE_ID => Tag::Byte(stream.read_i8()?), + BYTE_ID => Nbt::Byte(stream.read_i8()?), // A single signed, big endian 16 bit integer - SHORT_ID => Tag::Short(stream.read_i16::<BE>()?), + SHORT_ID => Nbt::Short(stream.read_i16::<BE>()?), // A single signed, big endian 32 bit integer - INT_ID => Tag::Int(stream.read_i32::<BE>()?), + INT_ID => Nbt::Int(stream.read_i32::<BE>()?), // A single signed, big endian 64 bit integer - LONG_ID => Tag::Long(stream.read_i64::<BE>()?), + LONG_ID => Nbt::Long(stream.read_i64::<BE>()?), // A single, big endian IEEE-754 single-precision floating point // number (NaN possible) - FLOAT_ID => Tag::Float(stream.read_f32::<BE>()?), + FLOAT_ID => Nbt::Float(stream.read_f32::<BE>()?), // A single, big endian IEEE-754 double-precision floating point // number (NaN possible) - DOUBLE_ID => Tag::Double(stream.read_f64::<BE>()?), + DOUBLE_ID => Nbt::Double(stream.read_f64::<BE>()?), // A length-prefixed array of signed bytes. The prefix is a signed // integer (thus 4 bytes) - BYTE_ARRAY_ID => Tag::ByteArray(read_byte_array(stream)?), + BYTE_ARRAY_ID => Nbt::ByteArray(read_byte_array(stream)?), // A length-prefixed modified UTF-8 string. The prefix is an // unsigned short (thus 2 bytes) signifying the length of the // string in bytes - STRING_ID => Tag::String(read_string(stream)?), + STRING_ID => Nbt::String(read_string(stream)?), // A list of nameless tags, all of the same type. The list is // prefixed with the Type ID of the items it contains (thus 1 // byte), and the length of the list as a signed integer (a further @@ -239,57 +239,57 @@ impl Tag { // notchian implementation uses TAG_End in that situation, but // another reference implementation by Mojang uses 1 instead; // parsers should accept any type if the length is <= 0). - LIST_ID => Tag::List(read_list(stream)?), + LIST_ID => Nbt::List(read_list(stream)?), // Effectively a list of a named tags. Order is not guaranteed. - COMPOUND_ID => Tag::Compound(read_compound(stream)?), + COMPOUND_ID => Nbt::Compound(read_compound(stream)?), // A length-prefixed array of signed integers. The prefix is a // signed integer (thus 4 bytes) and indicates the number of 4 byte // integers. - INT_ARRAY_ID => Tag::IntArray(read_int_array(stream)?), + INT_ARRAY_ID => Nbt::IntArray(read_int_array(stream)?), // A length-prefixed array of signed longs. The prefix is a signed // integer (thus 4 bytes) and indicates the number of 8 byte longs. - LONG_ARRAY_ID => Tag::LongArray(read_long_array(stream)?), + LONG_ARRAY_ID => Nbt::LongArray(read_long_array(stream)?), _ => return Err(Error::InvalidTagType(id)), }) } /// Read the NBT data. This will return a compound tag with a single item. - pub fn read(stream: &mut Cursor<&[u8]>) -> Result<Tag, Error> { + pub fn read(stream: &mut Cursor<&[u8]>) -> Result<Nbt, Error> { // default to compound tag // the parent compound only ever has one item let tag_id = stream.read_u8().unwrap_or(0); if tag_id == 0 { - return Ok(Tag::End); + return Ok(Nbt::End); } let name = read_string(stream)?; - let tag = Tag::read_known(stream, tag_id)?; + let tag = Nbt::read_known(stream, tag_id)?; let mut map = NbtCompound::with_capacity(1); map.insert(name, tag); - Ok(Tag::Compound(map)) + Ok(Nbt::Compound(map)) } /// Read the NBT data compressed wtih zlib. - pub fn read_zlib(stream: &mut impl BufRead) -> Result<Tag, Error> { + pub fn read_zlib(stream: &mut impl BufRead) -> Result<Nbt, Error> { let mut gz = ZlibDecoder::new(stream); let mut buf = Vec::new(); gz.read_to_end(&mut buf)?; - Tag::read(&mut Cursor::new(&buf)) + Nbt::read(&mut Cursor::new(&buf)) } /// Read the NBT data compressed wtih gzip. - pub fn read_gzip(stream: &mut Cursor<Vec<u8>>) -> Result<Tag, Error> { + pub fn read_gzip(stream: &mut Cursor<Vec<u8>>) -> Result<Nbt, Error> { let mut gz = GzDecoder::new(stream); let mut buf = Vec::new(); gz.read_to_end(&mut buf)?; - Tag::read(&mut Cursor::new(&buf)) + Nbt::read(&mut Cursor::new(&buf)) } } -impl McBufReadable for Tag { +impl McBufReadable for Nbt { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - Ok(Tag::read(buf)?) + Ok(Nbt::read(buf)?) } } impl From<Error> for BufReadError { |
