aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/azalea-protocol-macros/src/lib.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-10-07 20:12:36 -0500
committerGitHub <noreply@github.com>2022-10-07 20:12:36 -0500
commitbc3aa9467ae1e2d0ea1727093af9b0af14965e69 (patch)
tree8db3b735daed484507129eb0683db88ddec14210 /azalea-protocol/azalea-protocol-macros/src/lib.rs
parent695efef66fdf1e08f0cb6d8783c085875100fa2d (diff)
downloadazalea-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/azalea-protocol-macros/src/lib.rs')
-rw-r--r--azalea-protocol/azalea-protocol-macros/src/lib.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/azalea-protocol/azalea-protocol-macros/src/lib.rs b/azalea-protocol/azalea-protocol-macros/src/lib.rs
index ecdabbca..b7e85435 100644
--- a/azalea-protocol/azalea-protocol-macros/src/lib.rs
+++ b/azalea-protocol/azalea-protocol-macros/src/lib.rs
@@ -30,7 +30,7 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
}
pub fn read(
- buf: &mut impl std::io::Read,
+ buf: &mut std::io::Cursor<&[u8]>,
) -> Result<#state, azalea_buf::BufReadError> {
use azalea_buf::McBufReadable;
Ok(Self::read_from(buf)?.get())
@@ -223,7 +223,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
#id => {
let data = #module::#name::read(buf).map_err(|e| crate::read::ReadPacketError::Parse { source: e, packet_id: #id, packet_name: #name_litstr.to_string() })?;
let mut leftover = Vec::new();
- let _ = buf.read_to_end(&mut leftover);
+ let _ = std::io::Read::read_to_end(buf, &mut leftover);
if !leftover.is_empty() {
return Err(crate::read::ReadPacketError::LeftoverData { packet_name: #name_litstr.to_string(), data: leftover });
}
@@ -250,9 +250,10 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
#[cfg(debug_assertions)]
{
let mut leftover = Vec::new();
- let _ = buf.read_to_end(&mut leftover);
+ let _ = std::io::Read::read_to_end(buf, &mut leftover);
if !leftover.is_empty() {
return Err(crate::read::ReadPacketError::LeftoverData { packet_name: #name_litstr.to_string(), data: leftover });
+
}
}
data
@@ -312,7 +313,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
/// Read a packet by its id, ConnectionProtocol, and flow
fn read(
id: u32,
- buf: &mut impl std::io::Read,
+ buf: &mut std::io::Cursor<&[u8]>,
) -> Result<#serverbound_state_name, crate::read::ReadPacketError>
where
Self: Sized,
@@ -343,7 +344,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
/// Read a packet by its id, ConnectionProtocol, and flow
fn read(
id: u32,
- buf: &mut impl std::io::Read,
+ buf: &mut std::io::Cursor<&[u8]>,
) -> Result<#clientbound_state_name, crate::read::ReadPacketError>
where
Self: Sized,