mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
significantly optimize reading Vec<u8>
unfortunately, this introduces the requirement of using rust nightly
This commit is contained in:
parent
c8c356685d
commit
4d7bf6c50e
7 changed files with 28 additions and 4 deletions
|
@ -215,7 +215,7 @@ impl Client {
|
|||
println!("Got chunk cache center packet {:?}", p);
|
||||
}
|
||||
GamePacket::ClientboundLevelChunkWithLightPacket(p) => {
|
||||
println!("Got chunk with light packet");
|
||||
println!("Got chunk with light packet {} {}", p.x, p.z);
|
||||
}
|
||||
GamePacket::ClientboundLightUpdatePacket(p) => {
|
||||
println!("Got light update packet {:?}", p);
|
||||
|
|
|
@ -5,3 +5,5 @@ Sent and receive Minecraft packets. You should probably use `azalea` or `azalea-
|
|||
The goal is to **only** support the latest Minecraft version in order to ease development.
|
||||
|
||||
This is not yet complete, search for `TODO` in the code for things that need to be done.
|
||||
|
||||
Unfortunately, compiling the crate requires Rust nightly because specialization is not stable yet.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! This lib is responsible for parsing Minecraft packets.
|
||||
|
||||
#![feature(min_specialization)]
|
||||
|
||||
use std::net::IpAddr;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
|
@ -272,7 +272,7 @@ impl McBufReadable for UnsizedByteArray {
|
|||
|
||||
#[async_trait]
|
||||
impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
|
||||
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||
default async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||
where
|
||||
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||
{
|
||||
|
@ -285,6 +285,16 @@ impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl McBufReadable for Vec<u8> {
|
||||
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||
where
|
||||
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||
{
|
||||
buf.read_byte_array().await
|
||||
}
|
||||
}
|
||||
|
||||
// string
|
||||
#[async_trait]
|
||||
impl McBufReadable for String {
|
||||
|
|
|
@ -212,11 +212,17 @@ impl McBufWritable for UnsizedByteArray {
|
|||
// TODO: use specialization when that gets stabilized into rust
|
||||
// to optimize for Vec<u8> byte arrays
|
||||
impl<T: McBufWritable> McBufWritable for Vec<T> {
|
||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
default fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
buf.write_list(self, |buf, i| T::write_into(i, buf))
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufWritable for Vec<u8> {
|
||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
buf.write_byte_array(self)
|
||||
}
|
||||
}
|
||||
|
||||
// string
|
||||
impl McBufWritable for String {
|
||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
|
|
|
@ -149,7 +149,11 @@ where
|
|||
if let Some(compression_threshold) = compression_threshold {
|
||||
buf = compression_decoder(&mut buf.as_slice(), compression_threshold).await?;
|
||||
}
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
println!("decoding packet");
|
||||
let packet = packet_decoder(&mut buf.as_slice(), flow).await?;
|
||||
println!("decoded packet in {}ms", start_time.elapsed().as_millis());
|
||||
|
||||
Ok(packet)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ async fn main() {
|
|||
println!("Hello, world!");
|
||||
|
||||
// let address = "95.111.249.143:10000";
|
||||
let address = "localhost:50332";
|
||||
let address = "localhost:58422";
|
||||
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
|
Loading…
Add table
Reference in a new issue