use crate::core::MessageId;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct PacketIndex(pub u16);
impl PacketIndex {
pub const ZERO: Self = Self(0);
#[must_use]
pub const fn new(raw: u16) -> Self {
Self(raw)
}
#[must_use]
pub const fn get(self) -> u16 {
self.0
}
#[must_use]
pub const fn next(self) -> Self {
Self(self.0.wrapping_add(1))
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct PacketKey {
pub message_id: MessageId,
pub packet_index: PacketIndex,
}
impl PacketKey {
#[must_use]
pub const fn new(message_id: MessageId, packet_index: PacketIndex) -> Self {
Self {
message_id,
packet_index,
}
}
}
#[cfg(test)]
mod tests {
use super::PacketIndex;
#[test]
fn next_wraps_at_u16_max() {
assert_eq!(PacketIndex::new(u16::MAX).next(), PacketIndex::ZERO);
}
}