2 unstable releases

0.2.0 Mar 20, 2023
0.1.0 Jan 13, 2023

#28 in #osu

Download history 8/week @ 2024-02-05 12/week @ 2024-02-19 14/week @ 2024-02-26 5/week @ 2024-03-04 13/week @ 2024-03-11 16/week @ 2024-03-25 29/week @ 2024-04-01

59 downloads per month
Used in bancho-packets

MIT license

9KB
85 lines

bancho-packets-derive

Available derives

  • ReadPacket: This derive macro will implement the BanchoPacketRead trait for the struct.
  • WritePacket: This derive macro will implement the BanchoPacketRead trait for the struct.
  • PacketLength: This derive macro will implement the BanchoPacketLength trait for the struct.

example

use bancho_packets::{ReadPacket, PacketReader, PayloadReader};

#[derive(Debug, Clone, ReadPacket)]
/// [`BanchoMessage`] is the message structure of the bancho client.
pub struct BanchoMessage {
    pub sender: String,
    pub content: String,
    pub target: String,
    pub sender_id: i32,
}

// Now we can use [`PayloadReader`] to read the [`BanchoMessage`] from bytes.
let mut reader = PacketReader::new(&[
    1, 0, 0, 20, 0, 0, 0, 11, 0, 11, 6, 228, 189, 160, 229, 165, 189,
    11, 4, 35, 111, 115, 117, 0, 0, 0, 0,
]);
let packet = reader.next().unwrap();

let mut payload_reader = PayloadReader::new(packet.payload.unwrap());
let message = payload_reader.read::<BanchoMessage>();

println!("{:?}: {:?}", packet.id, message);

Dependencies

~1.5MB
~33K SLoC