macro_rules! packet {
(
$(#[$meta:meta])*
$vis:vis struct $Name:ident {
$( $fvis:vis $field:ident : $ty:ty ),* $(,)?
}
) => { ... };
}Expand description
Declare a typed packet struct whose fields are automatically encoded/decoded.
All field types must implement PacketField: bool, i32, i64,
u32, u64, f32, f64, String, Vec<u8>.
use yog_network::{packet, Packet};
packet! {
pub struct PingPacket {
seq: u32,
message: String,
}
}
let p = PingPacket { seq: 1, message: "hello".into() };
let decoded = PingPacket::decode(&p.encode()).unwrap();
assert_eq!(decoded.seq, 1);