aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-01 23:55:19 -0600
committermat <github@matdoes.dev>2022-01-01 23:55:19 -0600
commita1afbb6031527c1db5831fc8e916bc0ecce633b4 (patch)
tree56fbccf52645cc2eefd231506ffe8ed71018dc01 /azalea-protocol/src/mc_buf.rs
parente81b85dd5bdd6d42ee84f24ed4a142f6141f170e (diff)
downloadazalea-drasl-a1afbb6031527c1db5831fc8e916bc0ecce633b4.tar.xz
start adding packet macros
Diffstat (limited to 'azalea-protocol/src/mc_buf.rs')
-rw-r--r--azalea-protocol/src/mc_buf.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/azalea-protocol/src/mc_buf.rs b/azalea-protocol/src/mc_buf.rs
index 860f61f2..72583d5a 100644
--- a/azalea-protocol/src/mc_buf.rs
+++ b/azalea-protocol/src/mc_buf.rs
@@ -35,7 +35,7 @@ pub trait Writable {
fn write_varint(&mut self, value: i32) -> Result<(), std::io::Error>;
fn write_utf_with_len(&mut self, string: &str, len: usize) -> Result<(), std::io::Error>;
fn write_utf(&mut self, string: &str) -> Result<(), std::io::Error>;
- fn write_short(&mut self, n: u16) -> Result<(), std::io::Error>;
+ fn write_short(&mut self, n: i16) -> Result<(), std::io::Error>;
fn write_byte_array(&mut self, bytes: &[u8]) -> Result<(), std::io::Error>;
fn write_int(&mut self, n: i32) -> Result<(), std::io::Error>;
fn write_boolean(&mut self, b: bool) -> Result<(), std::io::Error>;
@@ -125,8 +125,8 @@ impl Writable for Vec<u8> {
self.write_utf_with_len(string, MAX_STRING_LENGTH.into())
}
- fn write_short(&mut self, n: u16) -> Result<(), std::io::Error> {
- WriteBytesExt::write_u16::<BigEndian>(self, n)
+ fn write_short(&mut self, n: i16) -> Result<(), std::io::Error> {
+ WriteBytesExt::write_i16::<BigEndian>(self, n)
}
fn write_byte_array(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
@@ -176,6 +176,7 @@ pub trait Readable {
async fn read_nbt(&mut self) -> Result<azalea_nbt::Tag, String>;
async fn read_long(&mut self) -> Result<i64, String>;
async fn read_resource_location(&mut self) -> Result<ResourceLocation, String>;
+ async fn read_short(&mut self) -> Result<i16, String>;
}
#[async_trait]
@@ -334,6 +335,13 @@ where
let location = ResourceLocation::new(&location_string)?;
Ok(location)
}
+
+ async fn read_short(&mut self) -> Result<i16, String> {
+ match AsyncReadExt::read_i16(self).await {
+ Ok(r) => Ok(r),
+ Err(_) => Err("Error reading short".to_string()),
+ }
+ }
}
#[cfg(test)]