From 1a2c034b411e3d0dceb7b4a921ddd42226719bd0 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 6 Dec 2021 21:15:38 +0000 Subject: remove struct from friendly byte byffer --- minecraft-protocol/src/connection.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'minecraft-protocol/src/connection.rs') diff --git a/minecraft-protocol/src/connection.rs b/minecraft-protocol/src/connection.rs index 79058a75..b187baff 100644 --- a/minecraft-protocol/src/connection.rs +++ b/minecraft-protocol/src/connection.rs @@ -1,4 +1,4 @@ -use crate::{friendly_byte_buf::FriendlyByteBuf, packets::Packet, ServerIpAddress}; +use crate::{mc_buf, packets::Packet, ServerIpAddress}; use bytes::BytesMut; use tokio::{ io::{AsyncWriteExt, BufWriter}, @@ -44,20 +44,16 @@ impl Connection { // packet structure: // length + id + data - // Is this efficient? I have no idea, probably not. - // getting rid of the FriendlyByteBuffer struct might help - // write the packet id let mut id_and_data_buf = vec![packet.get_id()]; // write the packet data - let mut id_and_data_friendly_buf = FriendlyByteBuf::new(&mut id_and_data_buf); - packet.write(&mut id_and_data_friendly_buf); + packet.write(&mut id_and_data_buf); - // add the packet length to the beginning + // make a new buffer that has the length at the beginning + // and id+data at the end let mut complete_buf: Vec = Vec::new(); - let mut complete_friendly_buf = FriendlyByteBuf::new(&mut complete_buf); - complete_friendly_buf.write_varint(id_and_data_buf.len() as u32); + mc_buf::write_varint(&mut complete_buf, id_and_data_buf.len() as u32); complete_buf.append(&mut id_and_data_buf); // finally, write and flush to the stream -- cgit v1.2.3