suon_protocol 0.1.0

Binary protocol encoding and decoding for the Suon MMORPG framework
Documentation
//! Server keep-alive packet.

use super::prelude::*;

/// Packet sent by the server to keep the connection active without payload data.
///
/// # Examples
/// ```
/// use suon_protocol::packets::server::{Encodable, prelude::KeepAlivePacket};
///
/// assert_eq!(KeepAlivePacket.encode_with_kind().as_ref(), &[29]);
/// ```
pub struct KeepAlivePacket;

impl Encodable for KeepAlivePacket {
    const KIND: PacketKind = PacketKind::KeepAlive;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn should_encode_keep_alive_with_kind_only() {
        let encoded = KeepAlivePacket.encode_with_kind();

        assert_eq!(
            encoded.as_ref(),
            &[PacketKind::KeepAlive as u8],
            "KeepAlive packets should encode to just their kind byte"
        );
    }
}