mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
impl Write instead of Vec<u8> for consistency
This commit is contained in:
parent
bec2da64d8
commit
a24d00d998
17 changed files with 100 additions and 130 deletions
|
@ -123,7 +123,7 @@ fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl crate::mc_buf::McBufWritable for #ident {
|
impl crate::mc_buf::McBufWritable for #ident {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
#(#write_fields)*
|
#(#write_fields)*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
||||||
syn::Data::Enum(syn::DataEnum { .. }) => {
|
syn::Data::Enum(syn::DataEnum { .. }) => {
|
||||||
quote! {
|
quote! {
|
||||||
impl crate::mc_buf::McBufWritable for #ident {
|
impl crate::mc_buf::McBufWritable for #ident {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
crate::mc_buf::Writable::write_varint(buf, *self as i32)
|
crate::mc_buf::Writable::write_varint(buf, *self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
|
||||||
#state::#ident(self)
|
#state::#ident(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
crate::mc_buf::McBufWritable::write_into(self, buf)
|
crate::mc_buf::McBufWritable::write_into(self, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
match self {
|
match self {
|
||||||
#write_match_contents
|
#write_match_contents
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ mod write;
|
||||||
|
|
||||||
use packet_macros::{McBufReadable, McBufWritable};
|
use packet_macros::{McBufReadable, McBufWritable};
|
||||||
pub use read::{read_varint_async, McBufReadable, McBufVarintReadable, Readable};
|
pub use read::{read_varint_async, McBufReadable, McBufVarintReadable, Readable};
|
||||||
use std::ops::{Deref, Index};
|
use std::ops::Deref;
|
||||||
pub use write::{McBufVarintWritable, McBufWritable, Writable};
|
pub use write::{McBufVarintWritable, McBufWritable, Writable};
|
||||||
|
|
||||||
// const DEFAULT_NBT_QUOTA: u32 = 2097152;
|
// const DEFAULT_NBT_QUOTA: u32 = 2097152;
|
||||||
|
|
|
@ -8,49 +8,10 @@ use byteorder::{BigEndian, WriteBytesExt};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub trait Writable {
|
pub trait Writable: Write {
|
||||||
fn write_list<F, T>(&mut self, list: &[T], writer: F) -> Result<(), std::io::Error>
|
fn write_list<F, T>(&mut self, list: &[T], writer: F) -> Result<(), std::io::Error>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self, &T) -> Result<(), std::io::Error> + Copy,
|
F: FnOnce(&mut Self, &T) -> Result<(), std::io::Error> + Copy,
|
||||||
T: Sized,
|
|
||||||
Self: Sized;
|
|
||||||
fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error>;
|
|
||||||
fn write_map<KF, VF, KT, VT>(
|
|
||||||
&mut self,
|
|
||||||
map: Vec<(KT, VT)>,
|
|
||||||
key_writer: KF,
|
|
||||||
value_writer: VF,
|
|
||||||
) -> Result<(), std::io::Error>
|
|
||||||
where
|
|
||||||
KF: Fn(&mut Self, KT) -> Result<(), std::io::Error> + Copy,
|
|
||||||
VF: Fn(&mut Self, VT) -> Result<(), std::io::Error> + Copy,
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
fn write_byte(&mut self, n: u8) -> Result<(), std::io::Error>;
|
|
||||||
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error>;
|
|
||||||
fn write_varint(&mut self, value: i32) -> Result<(), std::io::Error>;
|
|
||||||
fn write_utf_with_len(&mut self, string: &str, len: usize) -> Result<(), std::io::Error>;
|
|
||||||
fn write_utf(&mut self, string: &str) -> Result<(), std::io::Error>;
|
|
||||||
fn write_short(&mut self, n: i16) -> Result<(), std::io::Error>;
|
|
||||||
fn write_byte_array(&mut self, bytes: &[u8]) -> Result<(), std::io::Error>;
|
|
||||||
fn write_int(&mut self, n: i32) -> Result<(), std::io::Error>;
|
|
||||||
fn write_boolean(&mut self, b: bool) -> Result<(), std::io::Error>;
|
|
||||||
fn write_nbt(&mut self, nbt: &azalea_nbt::Tag) -> Result<(), std::io::Error>;
|
|
||||||
fn write_long(&mut self, n: i64) -> Result<(), std::io::Error>;
|
|
||||||
fn write_resource_location(
|
|
||||||
&mut self,
|
|
||||||
location: &ResourceLocation,
|
|
||||||
) -> Result<(), std::io::Error>;
|
|
||||||
fn write_float(&mut self, n: f32) -> Result<(), std::io::Error>;
|
|
||||||
fn write_double(&mut self, n: f64) -> Result<(), std::io::Error>;
|
|
||||||
fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Writable for Vec<u8> {
|
|
||||||
fn write_list<F, T>(&mut self, list: &[T], writer: F) -> Result<(), std::io::Error>
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self, &T) -> Result<(), std::io::Error> + Copy,
|
|
||||||
Self: Sized,
|
|
||||||
{
|
{
|
||||||
self.write_varint(list.len() as i32)?;
|
self.write_varint(list.len() as i32)?;
|
||||||
for item in list {
|
for item in list {
|
||||||
|
@ -72,7 +33,6 @@ impl Writable for Vec<u8> {
|
||||||
where
|
where
|
||||||
KF: Fn(&mut Self, KT) -> Result<(), std::io::Error> + Copy,
|
KF: Fn(&mut Self, KT) -> Result<(), std::io::Error> + Copy,
|
||||||
VF: Fn(&mut Self, VT) -> Result<(), std::io::Error> + Copy,
|
VF: Fn(&mut Self, VT) -> Result<(), std::io::Error> + Copy,
|
||||||
Self: Sized,
|
|
||||||
{
|
{
|
||||||
self.write_varint(map.len() as i32)?;
|
self.write_varint(map.len() as i32)?;
|
||||||
for (key, value) in map {
|
for (key, value) in map {
|
||||||
|
@ -87,7 +47,7 @@ impl Writable for Vec<u8> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
|
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
|
||||||
self.extend_from_slice(bytes);
|
self.write_all(bytes);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +100,10 @@ impl Writable for Vec<u8> {
|
||||||
self.write_byte(if b { 1 } else { 0 })
|
self.write_byte(if b { 1 } else { 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_nbt(&mut self, nbt: &azalea_nbt::Tag) -> Result<(), std::io::Error> {
|
fn write_nbt(&mut self, nbt: &azalea_nbt::Tag) -> Result<(), std::io::Error>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
nbt.write(self)
|
nbt.write(self)
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -164,7 +127,10 @@ impl Writable for Vec<u8> {
|
||||||
self.write_utf(&location.to_string())
|
self.write_utf(&location.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error> {
|
fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
let [a, b, c, d] = uuid.to_int_array();
|
let [a, b, c, d] = uuid.to_int_array();
|
||||||
a.write_into(self)?;
|
a.write_into(self)?;
|
||||||
b.write_into(self)?;
|
b.write_into(self)?;
|
||||||
|
@ -174,34 +140,30 @@ impl Writable for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait McBufWritable
|
impl<W: Write + ?Sized> Writable for W {}
|
||||||
where
|
|
||||||
Self: Sized,
|
pub trait McBufWritable {
|
||||||
{
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait McBufVarintWritable
|
pub trait McBufVarintWritable {
|
||||||
where
|
fn varint_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
||||||
Self: Sized,
|
|
||||||
{
|
|
||||||
fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for i32 {
|
impl McBufWritable for i32 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Writable::write_int(buf, *self)
|
Writable::write_int(buf, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufVarintWritable for i32 {
|
impl McBufVarintWritable for i32 {
|
||||||
fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn varint_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(*self)
|
buf.write_varint(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for UnsizedByteArray {
|
impl McBufWritable for UnsizedByteArray {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_bytes(self)
|
buf.write_bytes(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,132 +171,132 @@ impl McBufWritable for UnsizedByteArray {
|
||||||
// TODO: use specialization when that gets stabilized into rust
|
// TODO: use specialization when that gets stabilized into rust
|
||||||
// to optimize for Vec<u8> byte arrays
|
// to optimize for Vec<u8> byte arrays
|
||||||
impl<T: McBufWritable> McBufWritable for Vec<T> {
|
impl<T: McBufWritable> McBufWritable for Vec<T> {
|
||||||
default fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_list(self, |buf, i| T::write_into(i, buf))
|
buf.write_list(self, |buf, i| T::write_into(i, buf))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Vec<u8> {
|
impl McBufWritable for Vec<u8> {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte_array(self)
|
buf.write_byte_array(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// string
|
// string
|
||||||
impl McBufWritable for String {
|
impl McBufWritable for String {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_utf(self)
|
buf.write_utf(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceLocation
|
// ResourceLocation
|
||||||
impl McBufWritable for ResourceLocation {
|
impl McBufWritable for ResourceLocation {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_resource_location(self)
|
buf.write_resource_location(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u32
|
// u32
|
||||||
impl McBufWritable for u32 {
|
impl McBufWritable for u32 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i16::write_into(&(*self as i16), buf)
|
i16::write_into(&(*self as i16), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u32 varint
|
// u32 varint
|
||||||
impl McBufVarintWritable for u32 {
|
impl McBufVarintWritable for u32 {
|
||||||
fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn varint_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i32::varint_write_into(&(*self as i32), buf)
|
i32::varint_write_into(&(*self as i32), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u16
|
// u16
|
||||||
impl McBufWritable for u16 {
|
impl McBufWritable for u16 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i16::write_into(&(*self as i16), buf)
|
i16::write_into(&(*self as i16), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u16 varint
|
// u16 varint
|
||||||
impl McBufVarintWritable for u16 {
|
impl McBufVarintWritable for u16 {
|
||||||
fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn varint_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i32::varint_write_into(&(*self as i32), buf)
|
i32::varint_write_into(&(*self as i32), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u8
|
// u8
|
||||||
impl McBufWritable for u8 {
|
impl McBufWritable for u8 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self)
|
buf.write_byte(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i16
|
// i16
|
||||||
impl McBufWritable for i16 {
|
impl McBufWritable for i16 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Writable::write_short(buf, *self)
|
Writable::write_short(buf, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i64
|
// i64
|
||||||
impl McBufWritable for i64 {
|
impl McBufWritable for i64 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Writable::write_long(buf, *self)
|
Writable::write_long(buf, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u64
|
// u64
|
||||||
impl McBufWritable for u64 {
|
impl McBufWritable for u64 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i64::write_into(&(*self as i64), buf)
|
i64::write_into(&(*self as i64), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool
|
// bool
|
||||||
impl McBufWritable for bool {
|
impl McBufWritable for bool {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_boolean(*self)
|
buf.write_boolean(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i8
|
// i8
|
||||||
impl McBufWritable for i8 {
|
impl McBufWritable for i8 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self as u8)
|
buf.write_byte(*self as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// f32
|
// f32
|
||||||
impl McBufWritable for f32 {
|
impl McBufWritable for f32 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_float(*self)
|
buf.write_float(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// f64
|
// f64
|
||||||
impl McBufWritable for f64 {
|
impl McBufWritable for f64 {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_double(*self)
|
buf.write_double(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GameType
|
// GameType
|
||||||
impl McBufWritable for GameType {
|
impl McBufWritable for GameType {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
u8::write_into(&self.to_id(), buf)
|
u8::write_into(&self.to_id(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option<GameType>
|
// Option<GameType>
|
||||||
impl McBufWritable for Option<GameType> {
|
impl McBufWritable for Option<GameType> {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(GameType::to_optional_id(self) as u8)
|
buf.write_byte(GameType::to_optional_id(self) as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option<String>
|
// Option<String>
|
||||||
impl<T: McBufWritable> McBufWritable for Option<T> {
|
impl<T: McBufWritable> McBufWritable for Option<T> {
|
||||||
default fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
if let Some(s) = self {
|
if let Some(s) = self {
|
||||||
buf.write_boolean(true)?;
|
buf.write_boolean(true)?;
|
||||||
s.write_into(buf)?;
|
s.write_into(buf)?;
|
||||||
|
@ -347,14 +309,14 @@ impl<T: McBufWritable> McBufWritable for Option<T> {
|
||||||
|
|
||||||
// azalea_nbt::Tag
|
// azalea_nbt::Tag
|
||||||
impl McBufWritable for azalea_nbt::Tag {
|
impl McBufWritable for azalea_nbt::Tag {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_nbt(self)
|
buf.write_nbt(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Difficulty
|
// Difficulty
|
||||||
impl McBufWritable for Difficulty {
|
impl McBufWritable for Difficulty {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
u8::write_into(&self.id(), buf)
|
u8::write_into(&self.id(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +333,7 @@ impl McBufWritable for Component {
|
||||||
// let component = Component::deserialize(json).map_err(|e| e.to_string())?;
|
// let component = Component::deserialize(json).map_err(|e| e.to_string())?;
|
||||||
// Ok(component)
|
// Ok(component)
|
||||||
// }
|
// }
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
// component doesn't have serialize implemented yet
|
// component doesn't have serialize implemented yet
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -379,7 +341,7 @@ impl McBufWritable for Component {
|
||||||
|
|
||||||
// Slot
|
// Slot
|
||||||
impl McBufWritable for Slot {
|
impl McBufWritable for Slot {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
match self {
|
match self {
|
||||||
Slot::Empty => buf.write_byte(0)?,
|
Slot::Empty => buf.write_byte(0)?,
|
||||||
Slot::Present(i) => {
|
Slot::Present(i) => {
|
||||||
|
@ -395,7 +357,7 @@ impl McBufWritable for Slot {
|
||||||
|
|
||||||
// Slot
|
// Slot
|
||||||
impl McBufWritable for Uuid {
|
impl McBufWritable for Uuid {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_uuid(self)?;
|
buf.write_uuid(self)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -404,7 +366,7 @@ impl McBufWritable for Uuid {
|
||||||
|
|
||||||
// BlockPos
|
// BlockPos
|
||||||
impl McBufWritable for BlockPos {
|
impl McBufWritable for BlockPos {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_long(
|
buf.write_long(
|
||||||
(((self.x & 0x3FFFFFF) as i64) << 38)
|
(((self.x & 0x3FFFFFF) as i64) << 38)
|
||||||
| (((self.z & 0x3FFFFFF) as i64) << 12)
|
| (((self.z & 0x3FFFFFF) as i64) << 12)
|
||||||
|
@ -415,7 +377,7 @@ impl McBufWritable for BlockPos {
|
||||||
|
|
||||||
// Direction
|
// Direction
|
||||||
impl McBufWritable for Direction {
|
impl McBufWritable for Direction {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(*self as i32)
|
buf.write_varint(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use super::GamePacket;
|
use super::GamePacket;
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use std::{hash::Hash, io::Read};
|
use std::{
|
||||||
|
hash::Hash,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug)]
|
#[derive(Hash, Clone, Debug)]
|
||||||
pub struct ClientboundDeclareCommandsPacket {
|
pub struct ClientboundDeclareCommandsPacket {
|
||||||
|
@ -14,7 +17,7 @@ impl ClientboundDeclareCommandsPacket {
|
||||||
GamePacket::ClientboundDeclareCommandsPacket(self)
|
GamePacket::ClientboundDeclareCommandsPacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
panic!("ClientboundDeclareCommandsPacket::write not implemented")
|
panic!("ClientboundDeclareCommandsPacket::write not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ impl<T: McBufReadable> McBufReadable for BrigadierNumber<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T: McBufWritable> McBufWritable for BrigadierNumber<T> {
|
impl<T: McBufWritable> McBufWritable for BrigadierNumber<T> {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
let mut flags = 0;
|
let mut flags = 0;
|
||||||
if self.min.is_some() {
|
if self.min.is_some() {
|
||||||
flags |= 0x01;
|
flags |= 0x01;
|
||||||
|
@ -101,7 +104,7 @@ impl McBufReadable for BrigadierString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl McBufWritable for BrigadierString {
|
impl McBufWritable for BrigadierString {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self as u8)?;
|
buf.write_byte(*self as u8)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
||||||
use packet_macros::GamePacket;
|
use packet_macros::GamePacket;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
pub struct ClientboundPlayerAbilitiesPacket {
|
pub struct ClientboundPlayerAbilitiesPacket {
|
||||||
|
@ -32,7 +31,7 @@ impl McBufReadable for PlayerAbilitiesFlags {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for PlayerAbilitiesFlags {
|
impl McBufWritable for PlayerAbilitiesFlags {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
let mut byte = 0;
|
let mut byte = 0;
|
||||||
if self.invulnerable {
|
if self.invulnerable {
|
||||||
byte = byte | 1;
|
byte = byte | 1;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
|
@ -75,7 +75,7 @@ impl McBufReadable for Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl McBufWritable for Action {
|
impl McBufWritable for Action {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(match self {
|
buf.write_byte(match self {
|
||||||
Action::AddPlayer(_) => 0,
|
Action::AddPlayer(_) => 0,
|
||||||
Action::UpdateGameMode(_) => 1,
|
Action::UpdateGameMode(_) => 1,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
||||||
use packet_macros::GamePacket;
|
use packet_macros::GamePacket;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
pub struct ClientboundPlayerPositionPacket {
|
pub struct ClientboundPlayerPositionPacket {
|
||||||
|
@ -41,7 +40,7 @@ impl McBufReadable for RelativeArguments {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for RelativeArguments {
|
impl McBufWritable for RelativeArguments {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
let mut byte = 0;
|
let mut byte = 0;
|
||||||
if self.x {
|
if self.x {
|
||||||
byte = byte | 0b1;
|
byte = byte | 0b1;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_core::{resource_location::ResourceLocation, Slot};
|
use azalea_core::{resource_location::ResourceLocation, Slot};
|
||||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
pub struct ClientboundRecipePacket {
|
pub struct ClientboundRecipePacket {
|
||||||
|
@ -35,7 +34,7 @@ pub enum State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for State {
|
impl McBufWritable for State {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(*self as i32)?;
|
buf.write_varint(*self as i32)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
mc_buf::{Readable, Writable},
|
mc_buf::{Readable, Writable},
|
||||||
packets::{McBufReadable, McBufWritable},
|
packets::{McBufReadable, McBufWritable},
|
||||||
|
@ -7,6 +5,7 @@ use crate::{
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use azalea_core::{BlockPos, Direction, Slot};
|
use azalea_core::{BlockPos, Direction, Slot};
|
||||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
|
@ -40,7 +39,7 @@ impl McBufReadable for Vec<EntityDataItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Vec<EntityDataItem> {
|
impl McBufWritable for Vec<EntityDataItem> {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
for item in self {
|
for item in self {
|
||||||
buf.write_byte(item.index)?;
|
buf.write_byte(item.index)?;
|
||||||
item.value.write_into(buf)?;
|
item.value.write_into(buf)?;
|
||||||
|
@ -124,7 +123,7 @@ impl McBufReadable for EntityDataValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for EntityDataValue {
|
impl McBufWritable for EntityDataValue {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,7 +398,7 @@ impl McBufReadable for ParticleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for ParticleData {
|
impl McBufWritable for ParticleData {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
|
@ -44,7 +44,7 @@ impl McBufReadable for Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Operation {
|
impl McBufWritable for Operation {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self as u8)?;
|
buf.write_byte(*self as u8)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use azalea_core::{resource_location::ResourceLocation, Slot};
|
use azalea_core::{resource_location::ResourceLocation, Slot};
|
||||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
|
@ -35,7 +35,7 @@ pub struct ShapedRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for ShapedRecipe {
|
impl McBufWritable for ShapedRecipe {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(self.width.try_into().unwrap())?;
|
buf.write_varint(self.width.try_into().unwrap())?;
|
||||||
buf.write_varint(self.height.try_into().unwrap())?;
|
buf.write_varint(self.height.try_into().unwrap())?;
|
||||||
buf.write_utf(&self.group)?;
|
buf.write_utf(&self.group)?;
|
||||||
|
@ -122,7 +122,7 @@ pub struct Ingredient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Recipe {
|
impl McBufWritable for Recipe {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use packet_macros::GamePacket;
|
use packet_macros::GamePacket;
|
||||||
use std::{collections::HashMap, io::Read};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, GamePacket)]
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
pub struct ClientboundUpdateTagsPacket {
|
pub struct ClientboundUpdateTagsPacket {
|
||||||
|
@ -33,7 +36,7 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
|
impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(self.len() as i32)?;
|
buf.write_varint(self.len() as i32)?;
|
||||||
for (k, v) in self {
|
for (k, v) in self {
|
||||||
k.write_into(buf)?;
|
k.write_into(buf)?;
|
||||||
|
@ -51,7 +54,7 @@ impl McBufReadable for Tags {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Tags {
|
impl McBufWritable for Tags {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
self.name.write_into(buf)?;
|
self.name.write_into(buf)?;
|
||||||
buf.write_int_id_list(&self.elements)?;
|
buf.write_int_id_list(&self.elements)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use super::LoginPacket;
|
use super::LoginPacket;
|
||||||
use crate::mc_buf::{Readable, Writable};
|
use crate::mc_buf::{Readable, Writable};
|
||||||
|
@ -17,7 +17,7 @@ impl ClientboundGameProfilePacket {
|
||||||
LoginPacket::ClientboundGameProfilePacket(self)
|
LoginPacket::ClientboundGameProfilePacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
for n in self.game_profile.uuid.to_int_array() {
|
for n in self.game_profile.uuid.to_int_array() {
|
||||||
buf.write_int(n as i32).unwrap();
|
buf.write_int(n as i32).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::{hash::Hash, io::Read};
|
use std::{
|
||||||
|
hash::Hash,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
use super::LoginPacket;
|
use super::LoginPacket;
|
||||||
use crate::mc_buf::Readable;
|
use crate::mc_buf::Readable;
|
||||||
|
@ -15,11 +18,11 @@ impl ClientboundHelloPacket {
|
||||||
LoginPacket::ClientboundHelloPacket(self)
|
LoginPacket::ClientboundHelloPacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
panic!("ClientboundHelloPacket::write not implemented")
|
panic!("ClientboundHelloPacket::write not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
||||||
let server_id = buf.read_utf_with_len(20)?;
|
let server_id = buf.read_utf_with_len(20)?;
|
||||||
let public_key = buf.read_byte_array()?;
|
let public_key = buf.read_byte_array()?;
|
||||||
let nonce = buf.read_byte_array()?;
|
let nonce = buf.read_byte_array()?;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::{hash::Hash, io::Read};
|
use std::{
|
||||||
|
hash::Hash,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::mc_buf::{Readable, Writable};
|
use crate::mc_buf::{Readable, Writable};
|
||||||
|
|
||||||
|
@ -14,12 +17,12 @@ impl ClientboundLoginCompressionPacket {
|
||||||
LoginPacket::ClientboundLoginCompressionPacket(self)
|
LoginPacket::ClientboundLoginCompressionPacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(self.compression_threshold).unwrap();
|
buf.write_varint(self.compression_threshold).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
||||||
let compression_threshold = buf.read_varint()?;
|
let compression_threshold = buf.read_varint()?;
|
||||||
|
|
||||||
Ok(ClientboundLoginCompressionPacket {
|
Ok(ClientboundLoginCompressionPacket {
|
||||||
|
|
|
@ -3,7 +3,7 @@ pub mod handshake;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connect::PacketFlow,
|
connect::PacketFlow,
|
||||||
|
@ -40,7 +40,7 @@ where
|
||||||
/// Read a packet by its id, ConnectionProtocol, and flow
|
/// Read a packet by its id, ConnectionProtocol, and flow
|
||||||
fn read(id: u32, flow: &PacketFlow, buf: &mut impl Read) -> Result<Self, String>;
|
fn read(id: u32, flow: &PacketFlow, buf: &mut impl Read) -> Result<Self, String>;
|
||||||
|
|
||||||
fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error>;
|
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufReadable for ConnectionProtocol {
|
impl McBufReadable for ConnectionProtocol {
|
||||||
|
@ -51,7 +51,7 @@ impl McBufReadable for ConnectionProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for ConnectionProtocol {
|
impl McBufWritable for ConnectionProtocol {
|
||||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(*self as i32)
|
buf.write_varint(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -41,7 +41,7 @@ impl ClientboundStatusResponsePacket {
|
||||||
StatusPacket::ClientboundStatusResponsePacket(self)
|
StatusPacket::ClientboundStatusResponsePacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue