From f859dbbba06278f52517b0096b92ff3a6932ee28 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 26 Apr 2022 22:15:07 -0500 Subject: update brigadier --- azalea-protocol/src/mc_buf/read.rs | 20 +++++++++++++++++++- azalea-protocol/src/mc_buf/write.rs | 12 ++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'azalea-protocol/src/mc_buf') diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index 4c126b7e..d3382e0a 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -28,6 +28,7 @@ pub trait Readable { async fn read_resource_location(&mut self) -> Result; async fn read_short(&mut self) -> Result; async fn read_float(&mut self) -> Result; + async fn read_double(&mut self) -> Result; } #[async_trait] @@ -130,7 +131,6 @@ where self.read_exact(&mut buffer) .await .map_err(|_| "Invalid UTF-8".to_string())?; - string.push_str(std::str::from_utf8(&buffer).unwrap()); if string.len() > length as usize { return Err(format!( @@ -200,6 +200,13 @@ where Err(_) => Err("Error reading float".to_string()), } } + + async fn read_double(&mut self) -> Result { + match AsyncReadExt::read_f64(self).await { + Ok(r) => Ok(r), + Err(_) => Err("Error reading double".to_string()), + } + } } #[async_trait] @@ -399,6 +406,17 @@ impl McBufReadable for f32 { } } +// f64 +#[async_trait] +impl McBufReadable for f64 { + async fn read_into(buf: &mut R) -> Result + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_double().await + } +} + // GameType #[async_trait] impl McBufReadable for GameType { diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index 2c46157b..b57ad786 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -42,6 +42,7 @@ pub trait Writable { location: &ResourceLocation, ) -> Result<(), std::io::Error>; fn write_float(&mut self, n: f32) -> Result<(), std::io::Error>; + fn write_double(&mut self, n: f64) -> Result<(), std::io::Error>; } #[async_trait] @@ -152,6 +153,10 @@ impl Writable for Vec { WriteBytesExt::write_f32::(self, n) } + fn write_double(&mut self, n: f64) -> Result<(), std::io::Error> { + WriteBytesExt::write_f64::(self, n) + } + fn write_resource_location( &mut self, location: &ResourceLocation, @@ -291,6 +296,13 @@ impl McBufWritable for f32 { } } +// f64 +impl McBufWritable for f64 { + fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + buf.write_double(*self) + } +} + // GameType impl McBufWritable for GameType { fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { -- cgit v1.2.3