Skip to content

Commit bd6a8a5

Browse files
committed
use PrefixedOptional instead in ChatMessagePacket
1 parent 571a764 commit bd6a8a5

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

src/lib/net/crates/codec/src/decode/primitives.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -145,38 +145,6 @@ where
145145
}
146146
}
147147

148-
/// This implementation assumes that the optional was written using PacketByteBuf#writeNullable and has a leading bool.
149-
impl<T> NetDecode for Option<T>
150-
where
151-
T: NetDecode,
152-
{
153-
fn decode<R: Read>(reader: &mut R, opts: &NetDecodeOpts) -> Result<Self, NetDecodeError> {
154-
let is_some = <bool as NetDecode>::decode(reader, opts)?;
155-
156-
if !is_some {
157-
return Ok(None);
158-
}
159-
160-
let value = <T as NetDecode>::decode(reader, opts)?;
161-
162-
Ok(Some(value))
163-
}
164-
165-
async fn decode_async<R: AsyncRead + Unpin>(
166-
reader: &mut R,
167-
opts: &NetDecodeOpts,
168-
) -> Result<Self, NetDecodeError> {
169-
let is_some = <bool as NetDecode>::decode_async(reader, opts).await?;
170-
if !is_some {
171-
return Ok(None);
172-
}
173-
174-
let value = <T as NetDecode>::decode_async(reader, opts).await?;
175-
176-
Ok(Some(value))
177-
}
178-
}
179-
180148
/// This isn't actually a type in the Minecraft Protocol. This is just for saving data/ or for general use.
181149
/// It was created for saving/reading chunks!
182150
impl<K, V> NetDecode for HashMap<K, V>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use ferrumc_macros::{packet, NetDecode};
2-
use ferrumc_net_codec::net_types::var_int::VarInt;
2+
use ferrumc_net_codec::net_types::{prefixed_optional::PrefixedOptional, var_int::VarInt};
33

4-
#[derive(NetDecode, Debug, Clone)]
4+
#[derive(NetDecode)]
55
#[packet(packet_id = "chat", state = "play")]
66
pub struct ChatMessagePacket {
77
pub message: String,
88
pub timestamp: u64,
99
pub salt: u64,
1010
pub has_signature: bool,
11-
pub signature: Option<Vec<u64>>,
11+
pub signature: PrefixedOptional<Vec<u64>>,
1212
pub message_count: VarInt,
1313
pub acknowledged: Vec<u8>,
1414
}

0 commit comments

Comments
 (0)