#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpConversationId(u32);
impl KcpConversationId {
pub const fn new(raw: u32) -> Self {
Self(raw)
}
pub const fn raw(self) -> u32 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpCommand(u8);
impl KcpCommand {
pub const PUSH: Self = Self(81);
pub const ACK: Self = Self(82);
pub const WASK: Self = Self(83);
pub const WINS: Self = Self(84);
pub const fn new(raw: u8) -> Self {
Self(raw)
}
pub const fn raw(self) -> u8 {
self.0
}
pub const fn known(self) -> Option<KcpKnownCommand> {
KcpKnownCommand::from_raw(self.0)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum KcpKnownCommand {
Push,
Ack,
Wask,
Wins,
}
impl KcpKnownCommand {
pub const fn from_raw(raw: u8) -> Option<Self> {
match raw {
81 => Some(Self::Push),
82 => Some(Self::Ack),
83 => Some(Self::Wask),
84 => Some(Self::Wins),
_ => None,
}
}
pub const fn command(self) -> KcpCommand {
match self {
Self::Push => KcpCommand::PUSH,
Self::Ack => KcpCommand::ACK,
Self::Wask => KcpCommand::WASK,
Self::Wins => KcpCommand::WINS,
}
}
pub const fn raw(self) -> u8 {
self.command().raw()
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpFragment(u8);
impl KcpFragment {
pub const fn new(raw: u8) -> Self {
Self(raw)
}
pub const fn raw(self) -> u8 {
self.0
}
pub const fn is_final(self) -> bool {
self.0 == 0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpTimestamp(u32);
impl KcpTimestamp {
pub const fn new(raw: u32) -> Self {
Self(raw)
}
pub const fn raw(self) -> u32 {
self.0
}
pub const fn distance_from(self, earlier: Self) -> i32 {
self.0.wrapping_sub(earlier.0) as i32
}
pub const fn is_before(self, other: Self) -> bool {
self.distance_from(other) < 0
}
pub const fn is_after(self, other: Self) -> bool {
self.distance_from(other) > 0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpSequenceNumber(u32);
impl KcpSequenceNumber {
pub const fn new(raw: u32) -> Self {
Self(raw)
}
pub const fn raw(self) -> u32 {
self.0
}
pub const fn distance_from(self, earlier: Self) -> i32 {
self.0.wrapping_sub(earlier.0) as i32
}
pub const fn is_before(self, other: Self) -> bool {
self.distance_from(other) < 0
}
pub const fn is_after(self, other: Self) -> bool {
self.distance_from(other) > 0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct KcpUnacknowledged(u32);
impl KcpUnacknowledged {
pub const fn new(raw: u32) -> Self {
Self(raw)
}
pub const fn raw(self) -> u32 {
self.0
}
pub const fn into_sequence_number(self) -> KcpSequenceNumber {
KcpSequenceNumber::new(self.0)
}
}