#[packet]Expand description
Attribute macro for protocol packet structs.
Generates Encode, Decode, EncodedSize implementations and a
pub const PACKET_ID: i32 associated constant. The packet ID is NOT
included in the wire format — it is only a declarative constant used
by the packet registry for dispatch.
This replaces the need to manually derive all three traits on packet
structs. Field attributes (#[field(varint)], etc.) work the same
as with the individual derives.
§Example
ⓘ
#[derive(Debug, Clone, PartialEq)]
#[packet(id = 0x00)]
pub struct HandshakePacket {
#[field(varint)]
pub protocol_version: i32,
pub server_address: String,
pub server_port: u16,
#[field(varint)]
pub next_state: i32,
}
assert_eq!(HandshakePacket::PACKET_ID, 0x00);