diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-07 20:12:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 20:12:36 -0500 |
| commit | bc3aa9467ae1e2d0ea1727093af9b0af14965e69 (patch) | |
| tree | 8db3b735daed484507129eb0683db88ddec14210 /azalea-protocol/src/packets/status | |
| parent | 695efef66fdf1e08f0cb6d8783c085875100fa2d (diff) | |
| download | azalea-drasl-bc3aa9467ae1e2d0ea1727093af9b0af14965e69.tar.xz | |
Replace impl Read with Cursor<&[u8]> (#26)
* Start getting rid of Cursor
* try to make the tests pass and fail
* make the tests pass
* remove unused uses
* fix clippy warnings
* fix potential OOM exploits
* fix OOM in az-nbt
* fix nbt benchmark
* fix a test
* start replacing it with Cursor<Vec<u8>>
* wip
* fix all the issues
* fix all tests
* fix nbt benchmark
* fix warnings
Diffstat (limited to 'azalea-protocol/src/packets/status')
| -rwxr-xr-x | azalea-protocol/src/packets/status/clientbound_status_response_packet.rs | 30 |
1 files changed, 13 insertions, 17 deletions
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 f7a349e2..f8b46b8d 100755 --- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -1,14 +1,14 @@ -use super::ClientboundStatusPacket; -use azalea_buf::{BufReadError, McBufReadable}; +use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use azalea_chat::component::Component; +use azalea_protocol_macros::ClientboundStatusPacket; use serde::Deserialize; use serde_json::Value; -use std::io::{Read, Write}; +use std::io::{Cursor, Write}; #[derive(Clone, Debug, Deserialize)] pub struct Version { pub name: Component, - pub protocol: u32, + pub protocol: i32, } #[derive(Clone, Debug, Deserialize)] @@ -26,7 +26,7 @@ pub struct Players { } // the entire packet is just json, which is why it has deserialize -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, ClientboundStatusPacket)] pub struct ClientboundStatusResponsePacket { pub description: Component, pub favicon: Option<String>, @@ -34,21 +34,17 @@ pub struct ClientboundStatusResponsePacket { pub version: Version, } -impl ClientboundStatusResponsePacket { - pub fn get(self) -> ClientboundStatusPacket { - ClientboundStatusPacket::StatusResponse(self) - } - - pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { - Ok(()) - } - - pub fn read(buf: &mut impl Read) -> Result<ClientboundStatusPacket, BufReadError> { +impl McBufReadable for ClientboundStatusResponsePacket { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<ClientboundStatusResponsePacket, BufReadError> { let status_string = String::read_from(buf)?; let status_json: Value = serde_json::from_str(status_string.as_str())?; - let packet = ClientboundStatusResponsePacket::deserialize(status_json)?.get(); + Ok(ClientboundStatusResponsePacket::deserialize(status_json)?) + } +} - Ok(packet) +impl McBufWritable for ClientboundStatusResponsePacket { + fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { + todo!() } } |
