Skip to content

Commit 9b15071

Browse files
committed
Revert "feat: add PacketDyn"
This reverts commit 9b8945f.
1 parent 9b8945f commit 9b15071

2 files changed

Lines changed: 7 additions & 69 deletions

File tree

crates/macros/src/proto.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,6 @@ pub fn define_versions_internal(input: TokenStream) -> TokenStream {
407407
quote! { #struct_ident::#name(pk) => <<#struct_ident as ProtoVersionPackets>::#name as ::bedrock_protocol_core::ProtoCodec>::size_hint(pk), }
408408
});
409409

410-
let packet_as_dyn = previous_packets.keys().map(|name| {
411-
quote! { #struct_ident::#name(pk) => pk, }
412-
});
413-
414-
let packet_into_dyn = previous_packets.keys().map(|name| {
415-
quote! { #struct_ident::#name(pk) => Box::new(pk), }
416-
});
417-
418410
let packet_ser = previous_packets.keys().map(|name| {
419411
quote! {
420412
#struct_ident::#name(pk) => {
@@ -449,31 +441,31 @@ pub fn define_versions_internal(input: TokenStream) -> TokenStream {
449441
#[derive(Clone, std::fmt::Debug)]
450442
pub enum #struct_ident {
451443
#(#packet_variants)*
452-
Unknown(::bedrock_protocol_core::UnknownPacket),
444+
Unknown(u16, Box<[u8]>),
453445
}
454446

455447
impl ::bedrock_protocol_core::Packets for #struct_ident {
456448
#[inline]
457449
fn id(&self) -> u16 {
458450
match self {
459451
#(#packet_id)*
460-
#struct_ident::Unknown(pk) => { return pk.id; },
452+
#struct_ident::Unknown(id, _) => { return *id; },
461453
};
462454
}
463455

464456
#[inline]
465457
fn compress(&self) -> bool {
466458
match self {
467459
#(#packet_compress)*
468-
#struct_ident::Unknown(_) => { return true; },
460+
#struct_ident::Unknown(_, _) => { return true; },
469461
};
470462
}
471463

472464
#[inline]
473465
fn encrypt(&self) -> bool {
474466
match self {
475467
#(#packet_encrypt)*
476-
#struct_ident::Unknown(_) => { return true; },
468+
#struct_ident::Unknown(_, _) => { return true; },
477469
};
478470
}
479471

@@ -484,7 +476,7 @@ pub fn define_versions_internal(input: TokenStream) -> TokenStream {
484476

485477
match self {
486478
#(#packet_ser)*
487-
#struct_ident::Unknown(pk) => stream.write_all(pk.buf.as_ref())
479+
#struct_ident::Unknown(_, buf) => stream.write_all(buf)
488480
.map_err(|e| ::bedrock_protocol_core::error::PacketCodecError::InvalidPacket {
489481
packet_name: "Unknown",
490482
packet_id: header.packet_id,
@@ -510,10 +502,7 @@ pub fn define_versions_internal(input: TokenStream) -> TokenStream {
510502
packet_id: header.packet_id,
511503
error: e.into(),
512504
})?;
513-
#struct_ident::Unknown(::bedrock_protocol_core::UnknownPacket {
514-
id: unknown,
515-
buf: buf.into_boxed_slice()
516-
})
505+
#struct_ident::Unknown(unknown, buf.into_boxed_slice())
517506
},
518507
};
519508
Ok((packet, header))
@@ -523,23 +512,7 @@ pub fn define_versions_internal(input: TokenStream) -> TokenStream {
523512
fn size_hint(&self, header: &::bedrock_protocol_core::PacketHeader) -> usize {
524513
<::bedrock_protocol_core::PacketHeader as ::bedrock_protocol_core::ProtoCodec>::size_hint(header) + match self {
525514
#(#packet_size_prediction)*
526-
#struct_ident::Unknown(pk) => pk.buf.len(),
527-
}
528-
}
529-
530-
#[inline]
531-
fn as_dyn(&self) -> &dyn ::bedrock_protocol_core::PacketDyn {
532-
match self {
533-
#(#packet_as_dyn)*
534-
#struct_ident::Unknown(pk) => pk,
535-
}
536-
}
537-
538-
#[inline]
539-
fn into_dyn(self) -> Box<dyn ::bedrock_protocol_core::PacketDyn> {
540-
match self {
541-
#(#packet_into_dyn)*
542-
#struct_ident::Unknown(pk) => Box::new(pk),
515+
#struct_ident::Unknown(_, buf) => buf.len(),
543516
}
544517
}
545518
}

crates/protocol_core/src/lib.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
extern crate core;
22

3-
use std::any::Any;
43
use std::io::{Read, Write};
54

65
use crate::error::{PacketCodecError, ProtoCodecError};
@@ -28,37 +27,6 @@ pub trait Packet: Sized + ProtoCodec {
2827
const ENCRYPT: bool;
2928
}
3029

31-
pub trait PacketDyn: Any {
32-
fn id(&self) -> u16;
33-
fn name(&self) -> &'static str;
34-
}
35-
36-
impl<T: Packet + 'static> PacketDyn for T {
37-
fn id(&self) -> u16 {
38-
T::ID
39-
}
40-
41-
fn name(&self) -> &'static str {
42-
std::any::type_name::<T>()
43-
}
44-
}
45-
46-
#[derive(Clone, Debug)]
47-
pub struct UnknownPacket {
48-
pub id: u16,
49-
pub buf: Box<[u8]>,
50-
}
51-
52-
impl PacketDyn for UnknownPacket {
53-
fn id(&self) -> u16 {
54-
self.id
55-
}
56-
57-
fn name(&self) -> &'static str {
58-
std::any::type_name::<UnknownPacket>()
59-
}
60-
}
61-
6230
pub trait Packets: Sized {
6331
fn id(&self) -> u16;
6432
fn compress(&self) -> bool;
@@ -73,7 +41,4 @@ pub trait Packets: Sized {
7341
fn deserialize<R: Read>(stream: &mut R) -> Result<(Self, PacketHeader), PacketCodecError>;
7442

7543
fn size_hint(&self, header: &PacketHeader) -> usize;
76-
77-
fn as_dyn(&self) -> &dyn PacketDyn;
78-
fn into_dyn(self) -> Box<dyn PacketDyn>;
7944
}

0 commit comments

Comments
 (0)