create package structs for easier handling of individual packages & finally fix status.

It finally works in the client to list the server
This commit is contained in:
OMGeeky
2024-11-15 00:54:41 +01:00
parent df1908bfaa
commit f09dadecbd
12 changed files with 537 additions and 91 deletions

View File

@@ -1,11 +1,45 @@
use crate::types::long::Long;
use crate::types::string::McString;
use crate::types::var_int::VarInt;
use crate::types::var_long::VarLong;
use crate::types::{McRead, McWrite};
use crate::utils::RWStreamWithLimit;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
pub struct Protocol {}
pub struct Protocol();
#[derive(Debug, Clone)]
pub struct Data {
pub timespan: Long,
}
impl McRead for Data {
async fn read_stream<T: AsyncRead + Unpin>(stream: &mut T) -> Result<Self, String>
where
Self: Sized,
{
Ok(Self {
timespan: Long::read_stream(stream).await?,
})
}
}
#[derive(Debug, Clone)]
pub struct ResponseData {
pub(crate) timespan: Long,
}
impl McWrite for ResponseData {
type Error = String;
async fn write_stream<T: AsyncWrite + Unpin>(
&self,
stream: &mut T,
) -> Result<usize, Self::Error> {
self.timespan
.write_stream(stream)
.await
.map_err(|e| e.to_string())
}
}
impl Protocol {
pub async fn handle<T: AsyncRead + AsyncWrite + Unpin>(
stream: &mut RWStreamWithLimit<'_, T>,