aboutsummaryrefslogtreecommitdiff
path: root/azalea-nbt/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2023-03-23 13:55:33 +0000
committermat <github@matdoes.dev>2023-03-23 13:55:33 +0000
commitecb3f2ffd7dd4aa26213844a023e37fab4057ed0 (patch)
tree0cd0ea7eec8c05cdc8fae0a3ab15ef7c1402383c /azalea-nbt/src
parent2a07962af9a318114f38d3afe748a05212cfbd59 (diff)
downloadazalea-drasl-ecb3f2ffd7dd4aa26213844a023e37fab4057ed0.tar.xz
rename Tag to Nbt
Diffstat (limited to 'azalea-nbt/src')
-rwxr-xr-xazalea-nbt/src/decode.rs54
-rwxr-xr-xazalea-nbt/src/encode.rs62
-rwxr-xr-xazalea-nbt/src/lib.rs16
-rwxr-xr-xazalea-nbt/src/tag.rs18
4 files changed, 75 insertions, 75 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 {
diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs
index 4d76fede..79cd39d4 100755
--- a/azalea-nbt/src/encode.rs
+++ b/azalea-nbt/src/encode.rs
@@ -14,63 +14,63 @@ fn write_string(writer: &mut dyn Write, string: &str) {
fn write_compound(writer: &mut dyn Write, value: &NbtCompound, end_tag: bool) {
for (key, tag) in value.iter() {
match tag {
- Tag::End => {}
- Tag::Byte(value) => {
+ Nbt::End => {}
+ Nbt::Byte(value) => {
writer.write_u8(BYTE_ID).unwrap();
write_string(writer, key);
writer.write_i8(*value).unwrap();
}
- Tag::Short(value) => {
+ Nbt::Short(value) => {
writer.write_u8(SHORT_ID).unwrap();
write_string(writer, key);
writer.write_i16::<BE>(*value).unwrap();
}
- Tag::Int(value) => {
+ Nbt::Int(value) => {
writer.write_u8(INT_ID).unwrap();
write_string(writer, key);
writer.write_i32::<BE>(*value).unwrap();
}
- Tag::Long(value) => {
+ Nbt::Long(value) => {
writer.write_u8(LONG_ID).unwrap();
write_string(writer, key);
writer.write_i64::<BE>(*value).unwrap();
}
- Tag::Float(value) => {
+ Nbt::Float(value) => {
writer.write_u8(FLOAT_ID).unwrap();
write_string(writer, key);
writer.write_f32::<BE>(*value).unwrap();
}
- Tag::Double(value) => {
+ Nbt::Double(value) => {
writer.write_u8(DOUBLE_ID).unwrap();
write_string(writer, key);
writer.write_f64::<BE>(*value).unwrap();
}
- Tag::ByteArray(value) => {
+ Nbt::ByteArray(value) => {
writer.write_u8(BYTE_ARRAY_ID).unwrap();
write_string(writer, key);
write_byte_array(writer, value);
}
- Tag::String(value) => {
+ Nbt::String(value) => {
writer.write_u8(STRING_ID).unwrap();
write_string(writer, key);
write_string(writer, value);
}
- Tag::List(value) => {
+ Nbt::List(value) => {
writer.write_u8(LIST_ID).unwrap();
write_string(writer, key);
write_list(writer, value);
}
- Tag::Compound(value) => {
+ Nbt::Compound(value) => {
writer.write_u8(COMPOUND_ID).unwrap();
write_string(writer, key);
write_compound(writer, value, true);
}
- Tag::IntArray(value) => {
+ Nbt::IntArray(value) => {
writer.write_u8(INT_ARRAY_ID).unwrap();
write_string(writer, key);
write_int_array(writer, value);
}
- Tag::LongArray(value) => {
+ Nbt::LongArray(value) => {
writer.write_u8(LONG_ARRAY_ID).unwrap();
write_string(writer, key);
write_long_array(writer, value);
@@ -196,27 +196,27 @@ fn write_long_array(writer: &mut dyn Write, value: &Vec<i64>) {
}
}
-impl Tag {
+impl Nbt {
/// Write the tag as unnamed, uncompressed NBT data. If you're writing a
/// compound tag and the length of the NBT is already known, use
- /// [`Tag::write`] to avoid the `End` tag (this is used when writing NBT to
+ /// [`Nbt::write`] to avoid the `End` tag (this is used when writing NBT to
/// a file).
#[inline]
pub fn write_without_end(&self, writer: &mut dyn Write) {
match self {
- Tag::End => {}
- Tag::Byte(value) => writer.write_i8(*value).unwrap(),
- Tag::Short(value) => writer.write_i16::<BE>(*value).unwrap(),
- Tag::Int(value) => writer.write_i32::<BE>(*value).unwrap(),
- Tag::Long(value) => writer.write_i64::<BE>(*value).unwrap(),
- Tag::Float(value) => writer.write_f32::<BE>(*value).unwrap(),
- Tag::Double(value) => writer.write_f64::<BE>(*value).unwrap(),
- Tag::ByteArray(value) => write_byte_array(writer, value),
- Tag::String(value) => write_string(writer, value),
- Tag::List(value) => write_list(writer, value),
- Tag::Compound(value) => write_compound(writer, value, true),
- Tag::IntArray(value) => write_int_array(writer, value),
- Tag::LongArray(value) => write_long_array(writer, value),
+ Nbt::End => {}
+ Nbt::Byte(value) => writer.write_i8(*value).unwrap(),
+ Nbt::Short(value) => writer.write_i16::<BE>(*value).unwrap(),
+ Nbt::Int(value) => writer.write_i32::<BE>(*value).unwrap(),
+ Nbt::Long(value) => writer.write_i64::<BE>(*value).unwrap(),
+ Nbt::Float(value) => writer.write_f32::<BE>(*value).unwrap(),
+ Nbt::Double(value) => writer.write_f64::<BE>(*value).unwrap(),
+ Nbt::ByteArray(value) => write_byte_array(writer, value),
+ Nbt::String(value) => write_string(writer, value),
+ Nbt::List(value) => write_list(writer, value),
+ Nbt::Compound(value) => write_compound(writer, value, true),
+ Nbt::IntArray(value) => write_int_array(writer, value),
+ Nbt::LongArray(value) => write_long_array(writer, value),
}
}
@@ -227,10 +227,10 @@ impl Tag {
/// Will panic if the tag is not a Compound or End tag.
pub fn write(&self, writer: &mut impl Write) {
match self {
- Tag::Compound(value) => {
+ Nbt::Compound(value) => {
write_compound(writer, value, false);
}
- Tag::End => {
+ Nbt::End => {
END_ID.write_into(writer).unwrap();
}
_ => panic!("Not a compound tag"),
@@ -258,7 +258,7 @@ impl Tag {
}
}
-impl McBufWritable for Tag {
+impl McBufWritable for Nbt {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
self.write(buf);
Ok(())
diff --git a/azalea-nbt/src/lib.rs b/azalea-nbt/src/lib.rs
index 3c8aa2cd..b6a7a971 100755
--- a/azalea-nbt/src/lib.rs
+++ b/azalea-nbt/src/lib.rs
@@ -6,7 +6,7 @@ mod error;
mod tag;
pub use error::Error;
-pub use tag::{NbtCompound, NbtList, Tag};
+pub use tag::{NbtCompound, NbtList, Nbt};
#[cfg(test)]
mod tests {
@@ -20,25 +20,25 @@ mod tests {
#[test]
fn mcbuf_nbt() {
let mut buf = Vec::new();
- let tag = Tag::Compound(NbtCompound::from_iter(vec![(
+ let tag = Nbt::Compound(NbtCompound::from_iter(vec![(
"hello world".into(),
- Tag::Compound(NbtCompound::from_iter(vec![(
+ Nbt::Compound(NbtCompound::from_iter(vec![(
"name".into(),
- Tag::String("Bananrama".into()),
+ Nbt::String("Bananrama".into()),
)])),
)]));
tag.write_into(&mut buf).unwrap();
let mut buf = Cursor::new(&buf[..]);
- let result = Tag::read_from(&mut buf).unwrap();
+ let result = Nbt::read_from(&mut buf).unwrap();
assert_eq!(
result,
- Tag::Compound(NbtCompound::from_iter(vec![(
+ Nbt::Compound(NbtCompound::from_iter(vec![(
"hello world".into(),
- Tag::Compound(NbtCompound::from_iter(vec![(
+ Nbt::Compound(NbtCompound::from_iter(vec![(
"name".into(),
- Tag::String("Bananrama".into()),
+ Nbt::String("Bananrama".into()),
)])),
)]))
);
diff --git a/azalea-nbt/src/tag.rs b/azalea-nbt/src/tag.rs
index 7e4c5e25..573867ab 100755
--- a/azalea-nbt/src/tag.rs
+++ b/azalea-nbt/src/tag.rs
@@ -32,7 +32,7 @@ pub const LONG_ARRAY_ID: u8 = 12;
#[derive(Clone, Debug, PartialEq, Default, EnumAsInner)]
#[repr(u8)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(untagged))]
-pub enum Tag {
+pub enum Nbt {
#[default]
End = END_ID,
Byte(NbtByte) = BYTE_ID,
@@ -69,7 +69,7 @@ pub enum NbtList {
LongArray(Vec<NbtLongArray>) = LONG_ARRAY_ID,
}
-impl Tag {
+impl Nbt {
/// Get the numerical ID of the tag type.
#[inline]
pub fn id(&self) -> u8 {
@@ -96,7 +96,7 @@ impl NbtList {
#[derive(Debug, Clone, Default)]
pub struct NbtCompound {
sorted: bool,
- inner: Vec<(NbtString, Tag)>,
+ inner: Vec<(NbtString, Nbt)>,
}
impl NbtCompound {
#[inline]
@@ -117,7 +117,7 @@ impl NbtCompound {
/// If you previously used [`Self::insert_unsorted`] without [`Self::sort`],
/// this function may return incorrect results.
#[inline]
- pub fn get(&mut self, key: &NbtString) -> Option<&Tag> {
+ pub fn get(&mut self, key: &NbtString) -> Option<&Nbt> {
if !self.sorted {
self.sort()
}
@@ -131,7 +131,7 @@ impl NbtCompound {
/// [`Self::insert_unsorted`] and then [`Self::sort`] after everything is
/// inserted.
#[inline]
- pub fn insert(&mut self, key: NbtString, value: Tag) {
+ pub fn insert(&mut self, key: NbtString, value: Nbt) {
self.inner.push((key, value));
}
@@ -142,7 +142,7 @@ impl NbtCompound {
}
#[inline]
- pub fn iter(&self) -> std::slice::Iter<'_, (CompactString, Tag)> {
+ pub fn iter(&self) -> std::slice::Iter<'_, (CompactString, Nbt)> {
self.inner.iter()
}
}
@@ -160,7 +160,7 @@ impl Serialize for NbtCompound {
impl<'de> Deserialize<'de> for NbtCompound {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::collections::BTreeMap;
- let map = <BTreeMap<NbtString, Tag> as Deserialize>::deserialize(deserializer)?;
+ let map = <BTreeMap<NbtString, Nbt> as Deserialize>::deserialize(deserializer)?;
Ok(Self {
inner: map.into_iter().collect(),
sorted: false,
@@ -168,8 +168,8 @@ impl<'de> Deserialize<'de> for NbtCompound {
}
}
-impl FromIterator<(NbtString, Tag)> for NbtCompound {
- fn from_iter<T: IntoIterator<Item = (NbtString, Tag)>>(iter: T) -> Self {
+impl FromIterator<(NbtString, Nbt)> for NbtCompound {
+ fn from_iter<T: IntoIterator<Item = (NbtString, Nbt)>>(iter: T) -> Self {
let inner = iter.into_iter().collect::<Vec<_>>();
Self {
inner,