From dedcd0de8f017a00645b31cfdc1819a4e8da0850 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 1 May 2022 23:35:30 -0500 Subject: impl Write instead of Vec for consistency --- .../src/packets/game/clientbound_declare_commands_packet.rs | 11 +++++++---- .../src/packets/game/clientbound_player_abilities_packet.rs | 5 ++--- .../src/packets/game/clientbound_player_info_packet.rs | 4 ++-- .../src/packets/game/clientbound_player_position_packet.rs | 5 ++--- azalea-protocol/src/packets/game/clientbound_recipe_packet.rs | 7 +++---- .../src/packets/game/clientbound_set_entity_data_packet.rs | 9 ++++----- .../src/packets/game/clientbound_update_attributes_packet.rs | 4 ++-- .../src/packets/game/clientbound_update_recipes_packet.rs | 6 +++--- .../src/packets/game/clientbound_update_tags_packet.rs | 9 ++++++--- .../src/packets/login/clientbound_game_profile_packet.rs | 4 ++-- azalea-protocol/src/packets/login/clientbound_hello_packet.rs | 9 ++++++--- .../src/packets/login/clientbound_login_compression_packet.rs | 9 ++++++--- azalea-protocol/src/packets/mod.rs | 6 +++--- .../src/packets/status/clientbound_status_response_packet.rs | 4 ++-- 14 files changed, 50 insertions(+), 42 deletions(-) (limited to 'azalea-protocol/src/packets') diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs index 703811c0..27f4fb16 100755 --- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs @@ -1,7 +1,10 @@ use super::GamePacket; use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_core::resource_location::ResourceLocation; -use std::{hash::Hash, io::Read}; +use std::{ + hash::Hash, + io::{Read, Write}, +}; #[derive(Hash, Clone, Debug)] pub struct ClientboundDeclareCommandsPacket { @@ -14,7 +17,7 @@ impl ClientboundDeclareCommandsPacket { GamePacket::ClientboundDeclareCommandsPacket(self) } - pub fn write(&self, _buf: &mut Vec) -> Result<(), std::io::Error> { + pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { panic!("ClientboundDeclareCommandsPacket::write not implemented") } @@ -60,7 +63,7 @@ impl McBufReadable for BrigadierNumber { } } impl McBufWritable for BrigadierNumber { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut flags = 0; if self.min.is_some() { flags |= 0x01; @@ -101,7 +104,7 @@ impl McBufReadable for BrigadierString { } } impl McBufWritable for BrigadierString { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_byte(*self as u8)?; Ok(()) } diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs index 3ca1ac85..cd645fe6 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs @@ -1,7 +1,6 @@ -use std::io::Read; - use crate::mc_buf::{McBufReadable, McBufWritable, Readable}; use packet_macros::GamePacket; +use std::io::{Read, Write}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundPlayerAbilitiesPacket { @@ -32,7 +31,7 @@ impl McBufReadable for PlayerAbilitiesFlags { } impl McBufWritable for PlayerAbilitiesFlags { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut byte = 0; if self.invulnerable { byte = byte | 1; diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs index 97b68259..9c34d06e 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs @@ -1,7 +1,7 @@ use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_chat::component::Component; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use std::io::Read; +use std::io::{Read, Write}; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -75,7 +75,7 @@ impl McBufReadable for Action { } } impl McBufWritable for Action { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_byte(match self { Action::AddPlayer(_) => 0, Action::UpdateGameMode(_) => 1, diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs index e47ca9e1..cac4665d 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs @@ -1,7 +1,6 @@ -use std::io::Read; - use crate::mc_buf::{McBufReadable, McBufWritable, Readable}; use packet_macros::GamePacket; +use std::io::{Read, Write}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundPlayerPositionPacket { @@ -41,7 +40,7 @@ impl McBufReadable for RelativeArguments { } impl McBufWritable for RelativeArguments { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut byte = 0; if self.x { byte = byte | 0b1; diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs index 4847bbf8..543fb64c 100644 --- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -1,8 +1,7 @@ +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_core::{resource_location::ResourceLocation, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use std::io::Read; - -use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; +use std::io::{Read, Write}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundRecipePacket { @@ -35,7 +34,7 @@ pub enum State { } impl McBufWritable for State { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_varint(*self as i32)?; Ok(()) } diff --git a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs index 302d832a..5d288518 100644 --- a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs @@ -1,5 +1,3 @@ -use std::io::Read; - use crate::{ mc_buf::{Readable, Writable}, packets::{McBufReadable, McBufWritable}, @@ -7,6 +5,7 @@ use crate::{ use azalea_chat::component::Component; use azalea_core::{BlockPos, Direction, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; +use std::io::{Read, Write}; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -40,7 +39,7 @@ impl McBufReadable for Vec { } impl McBufWritable for Vec { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { for item in self { buf.write_byte(item.index)?; item.value.write_into(buf)?; @@ -124,7 +123,7 @@ impl McBufReadable for EntityDataValue { } impl McBufWritable for EntityDataValue { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { todo!(); } } @@ -399,7 +398,7 @@ impl McBufReadable for ParticleData { } impl McBufWritable for ParticleData { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { todo!() } } diff --git a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs index 6e0aae29..82f34f96 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs @@ -1,7 +1,7 @@ use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_core::resource_location::ResourceLocation; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use std::io::Read; +use std::io::{Read, Write}; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -44,7 +44,7 @@ impl McBufReadable for Operation { } impl McBufWritable for Operation { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_byte(*self as u8)?; Ok(()) } diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs index 4b1a322a..d15e10c3 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read, Write}; use azalea_core::{resource_location::ResourceLocation, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; @@ -35,7 +35,7 @@ pub struct ShapedRecipe { } impl McBufWritable for ShapedRecipe { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_varint(self.width.try_into().unwrap())?; buf.write_varint(self.height.try_into().unwrap())?; buf.write_utf(&self.group)?; @@ -122,7 +122,7 @@ pub struct Ingredient { } impl McBufWritable for Recipe { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { todo!() } } diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs index 4646c2d3..f82a4177 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs @@ -1,7 +1,10 @@ use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_core::resource_location::ResourceLocation; use packet_macros::GamePacket; -use std::{collections::HashMap, io::Read}; +use std::{ + collections::HashMap, + io::{Read, Write}, +}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundUpdateTagsPacket { @@ -33,7 +36,7 @@ impl McBufReadable for HashMap> { } impl McBufWritable for HashMap> { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_varint(self.len() as i32)?; for (k, v) in self { k.write_into(buf)?; @@ -51,7 +54,7 @@ impl McBufReadable for Tags { } impl McBufWritable for Tags { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.name.write_into(buf)?; buf.write_int_id_list(&self.elements)?; Ok(()) diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs index bcdcd105..dd077ced 100755 --- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read, Write}; use super::LoginPacket; use crate::mc_buf::{Readable, Writable}; @@ -17,7 +17,7 @@ impl ClientboundGameProfilePacket { LoginPacket::ClientboundGameProfilePacket(self) } - pub fn write(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { for n in self.game_profile.uuid.to_int_array() { buf.write_int(n as i32).unwrap(); } diff --git a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs index 06f346c2..f7de4c21 100755 --- a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs @@ -1,4 +1,7 @@ -use std::{hash::Hash, io::Read}; +use std::{ + hash::Hash, + io::{Read, Write}, +}; use super::LoginPacket; use crate::mc_buf::Readable; @@ -15,11 +18,11 @@ impl ClientboundHelloPacket { LoginPacket::ClientboundHelloPacket(self) } - pub fn write(&self, _buf: &mut Vec) -> Result<(), std::io::Error> { + pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { panic!("ClientboundHelloPacket::write not implemented") } - pub fn read(buf: &mut impl Read) -> Result { + pub fn read(buf: &mut impl Read) -> Result { let server_id = buf.read_utf_with_len(20)?; let public_key = buf.read_byte_array()?; let nonce = buf.read_byte_array()?; diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs index a5ab78bb..b1323f50 100755 --- a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs @@ -1,4 +1,7 @@ -use std::{hash::Hash, io::Read}; +use std::{ + hash::Hash, + io::{Read, Write}, +}; use crate::mc_buf::{Readable, Writable}; @@ -14,12 +17,12 @@ impl ClientboundLoginCompressionPacket { LoginPacket::ClientboundLoginCompressionPacket(self) } - pub fn write(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_varint(self.compression_threshold).unwrap(); Ok(()) } - pub fn read(buf: &mut impl Read) -> Result { + pub fn read(buf: &mut impl Read) -> Result { let compression_threshold = buf.read_varint()?; Ok(ClientboundLoginCompressionPacket { diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 67fa92e9..a706646d 100755 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -3,7 +3,7 @@ pub mod handshake; pub mod login; pub mod status; -use std::io::Read; +use std::io::{Read, Write}; use crate::{ connect::PacketFlow, @@ -40,7 +40,7 @@ where /// Read a packet by its id, ConnectionProtocol, and flow fn read(id: u32, flow: &PacketFlow, buf: &mut impl Read) -> Result; - fn write(&self, buf: &mut Vec) -> Result<(), std::io::Error>; + fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>; } impl McBufReadable for ConnectionProtocol { @@ -51,7 +51,7 @@ impl McBufReadable for ConnectionProtocol { } impl McBufWritable for ConnectionProtocol { - fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_varint(*self as i32) } } diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs index f5789ae3..2acdb8c2 100755 --- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read, Write}; use azalea_chat::component::Component; use serde::Deserialize; @@ -41,7 +41,7 @@ impl ClientboundStatusResponsePacket { StatusPacket::ClientboundStatusResponsePacket(self) } - pub fn write(&self, _buf: &mut Vec) -> Result<(), std::io::Error> { + pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { Ok(()) } -- cgit v1.2.3