aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/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/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/src/lib.rs')
-rwxr-xr-xazalea-protocol/src/lib.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs
index 9fff59f8..4da2ba90 100755
--- a/azalea-protocol/src/lib.rs
+++ b/azalea-protocol/src/lib.rs
@@ -52,6 +52,8 @@ pub async fn connect(address: ServerAddress) -> Result<(), Box<dyn std::error::E
#[cfg(test)]
mod tests {
+ use std::io::Cursor;
+
use crate::{
packets::login::{
serverbound_hello_packet::{ProfilePublicKeyData, ServerboundHelloPacket},
@@ -60,7 +62,7 @@ mod tests {
read::read_packet,
write::write_packet,
};
- use std::io::Cursor;
+ use bytes::BytesMut;
use uuid::Uuid;
#[tokio::test]
@@ -75,15 +77,22 @@ mod tests {
profile_id: Some(Uuid::from_u128(0)),
}
.get();
- let mut stream = Cursor::new(Vec::new());
+ let mut stream = Vec::new();
write_packet(packet, &mut stream, None, &mut None)
.await
.unwrap();
- stream.set_position(0);
+ println!("stream: {stream:?}");
- let _ = read_packet::<ServerboundLoginPacket, _>(&mut stream, None, &mut None)
- .await
- .unwrap();
+ let mut stream = Cursor::new(stream);
+
+ let _ = read_packet::<ServerboundLoginPacket, _>(
+ &mut stream,
+ &mut BytesMut::new(),
+ None,
+ &mut None,
+ )
+ .await
+ .unwrap();
}
}