use super::Stream;
use crate::frame::Mask;
use crate::bleed::Store;
pub(super) type HeadStore = Store<14>;
pub(super) type PingStore = Store<125>;
#[derive(Debug)]
pub(super) struct HeartBeat {
pub ping_store: PingStore,
pub is_complete: bool,
}
impl HeartBeat {
#[inline]
pub const fn new() -> Self {
Self {
ping_store: PingStore::new(),
is_complete: false,
}
}
}
#[derive(Debug)]
pub(super) enum ReadState {
ReadHead(HeadStore),
ReadData {
next: u64,
mask: Mask,
},
ReadPing {
next: u8,
mask: Mask,
},
ProcessBuf {
beg: usize,
end: usize,
processed: usize,
},
Eof,
Close,
}
impl ReadState {
#[inline]
pub const fn new() -> Self { ReadState::ReadHead(Store::new()) }
}
#[allow(clippy::enum_variant_names)]
#[derive(Debug)]
pub(super) enum WriteState {
WriteHead(HeadStore),
WriteData(u64),
WriteZero,
}
impl WriteState {
#[inline]
pub const fn new() -> Self { WriteState::WriteHead(Store::new()) }
}
impl<IO, Role, Guard> Stream<IO, Role, Guard> {
#[inline]
pub const fn is_pinged(&self) -> bool { !self.heartbeat.ping_store.is_empty() }
#[inline]
pub const fn is_ping_completed(&self) -> bool { self.heartbeat.is_complete }
#[inline]
pub const fn ping_data(&self) -> &[u8] { self.heartbeat.ping_store.read() }
#[inline]
pub const fn is_read_eof(&self) -> bool { matches!(&self.read_state, ReadState::Eof) }
#[inline]
pub const fn is_read_close(&self) -> bool { matches!(&self.read_state, ReadState::Close) }
#[inline]
pub const fn is_read_end(&self) -> bool { self.is_read_eof() || self.is_read_close() }
#[inline]
pub const fn is_write_zero(&self) -> bool { matches!(&self.write_state, WriteState::WriteZero) }
#[inline]
pub const fn is_read_partial_head(&self) -> bool {
matches!(&self.read_state, ReadState::ReadHead(..))
}
#[inline]
pub const fn is_write_partial_head(&self) -> bool {
matches!(&self.write_state, WriteState::WriteHead(..))
}
}