diff options
| author | mat <github@matdoes.dev> | 2022-08-24 21:09:17 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-08-24 21:09:17 -0500 |
| commit | 029ae0e567ccdc631a358755eba43b742811ff05 (patch) | |
| tree | a955489edeac1d303063b72392ecd644d070c57d | |
| parent | c64f10605bef9e5bf459b011b86ac6282b3d22e4 (diff) | |
| download | azalea-drasl-029ae0e567ccdc631a358755eba43b742811ff05.tar.xz | |
use unsigned integers for nbt lengths
probably not an optimization, just makes more sense
| -rwxr-xr-x | azalea-nbt/src/decode.rs | 6 | ||||
| -rwxr-xr-x | azalea-nbt/src/encode.rs | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index d4760807..2ab337fc 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -39,7 +39,7 @@ impl Tag { // A length-prefixed array of signed bytes. The prefix is a signed // integer (thus 4 bytes) 7 => { - let length = stream.read_i32::<BE>()?; + let length = stream.read_u32::<BE>()?; let mut bytes = vec![0; length as usize]; stream.read_exact(&mut bytes)?; Tag::ByteArray(bytes) @@ -84,7 +84,7 @@ impl Tag { // signed integer (thus 4 bytes) and indicates the number of 4 byte // integers. 11 => { - let length = stream.read_i32::<BE>()?; + let length = stream.read_u32::<BE>()?; let mut ints = Vec::with_capacity(length as usize); for _ in 0..length { ints.push(stream.read_i32::<BE>()?); @@ -94,7 +94,7 @@ impl Tag { // A length-prefixed array of signed longs. The prefix is a signed // integer (thus 4 bytes) and indicates the number of 8 byte longs. 12 => { - let length = stream.read_i32::<BE>()?; + let length = stream.read_u32::<BE>()?; let mut longs = Vec::with_capacity(length as usize); for _ in 0..length { longs.push(stream.read_i64::<BE>()?); diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs index 53e618f4..49c31192 100755 --- a/azalea-nbt/src/encode.rs +++ b/azalea-nbt/src/encode.rs @@ -10,7 +10,7 @@ use std::io::Write; #[inline] fn write_string(writer: &mut dyn Write, string: &str) -> Result<(), Error> { - writer.write_i16::<BE>(string.len() as i16)?; + writer.write_u16::<BE>(string.len() as u16)?; writer.write_all(string.as_bytes())?; Ok(()) @@ -142,14 +142,14 @@ fn write_list(writer: &mut dyn Write, value: &[Tag]) -> Result<(), Error> { #[inline] fn write_bytearray(writer: &mut dyn Write, value: &Vec<u8>) -> Result<(), Error> { - writer.write_i32::<BE>(value.len() as i32)?; + writer.write_u32::<BE>(value.len() as u32)?; writer.write_all(value)?; Ok(()) } #[inline] fn write_intarray(writer: &mut dyn Write, value: &Vec<i32>) -> Result<(), Error> { - writer.write_i32::<BE>(value.len() as i32)?; + writer.write_u32::<BE>(value.len() as u32)?; for &int in value { writer.write_i32::<BE>(int)?; } @@ -158,7 +158,7 @@ fn write_intarray(writer: &mut dyn Write, value: &Vec<i32>) -> Result<(), Error> #[inline] fn write_longarray(writer: &mut dyn Write, value: &Vec<i64>) -> Result<(), Error> { - writer.write_i32::<BE>(value.len() as i32)?; + writer.write_u32::<BE>(value.len() as u32)?; for &long in value { writer.write_i64::<BE>(long)?; } |
