diff options
| author | mat <github@matdoes.dev> | 2022-04-26 22:15:07 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-26 22:15:07 -0500 |
| commit | f859dbbba06278f52517b0096b92ff3a6932ee28 (patch) | |
| tree | 66f72298eb041f77afd4cff75e39e41caf91a7b0 /azalea-protocol/src/mc_buf/read.rs | |
| parent | 9c69d7d5f2f704b1de37e1a102bf4390cdd879a5 (diff) | |
| download | azalea-drasl-f859dbbba06278f52517b0096b92ff3a6932ee28.tar.xz | |
update brigadier
Diffstat (limited to 'azalea-protocol/src/mc_buf/read.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/read.rs | 20 |
1 files changed, 19 insertions, 1 deletions
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<ResourceLocation, String>; async fn read_short(&mut self) -> Result<i16, String>; async fn read_float(&mut self) -> Result<f32, String>; + async fn read_double(&mut self) -> Result<f64, String>; } #[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<f64, String> { + 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<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_double().await + } +} + // GameType #[async_trait] impl McBufReadable for GameType { |
