use core::task::{Context, Poll};
use crate::{eff::EffIndex, transport::wire::Payload};
mod labels;
pub use labels::FrameLabel;
pub(crate) use labels::{FrameLabelMask, LogicalLabel};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct SendMeta {
pub eff_index: EffIndex,
pub logical_label: LogicalLabel,
pub frame_label: FrameLabel,
pub peer: u8,
pub lane: u8,
pub is_control: bool,
}
#[derive(Clone, Copy, Debug)]
pub struct Outgoing<'f> {
pub(crate) meta: SendMeta,
pub(crate) payload: Payload<'f>,
}
impl<'f> Outgoing<'f> {
#[inline]
pub const fn frame_label(&self) -> FrameLabel {
self.meta.frame_label
}
#[inline]
pub const fn peer(&self) -> u8 {
self.meta.peer
}
#[inline]
pub const fn lane(&self) -> u8 {
self.meta.lane
}
#[inline]
pub const fn is_control(&self) -> bool {
self.meta.is_control
}
#[inline]
pub const fn payload(&self) -> Payload<'f> {
self.payload
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TransportError {
Offline,
Failed,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PortOpen {
local_role: u8,
session_id: crate::control::types::SessionId,
lane: crate::control::types::Lane,
}
impl PortOpen {
#[inline]
pub(crate) const fn from_descriptor(
local_role: u8,
session_id: crate::control::types::SessionId,
lane: crate::control::types::Lane,
) -> Self {
Self {
local_role,
session_id,
lane,
}
}
#[inline]
pub const fn local_role(self) -> u8 {
self.local_role
}
#[inline]
pub const fn session_id(self) -> crate::control::types::SessionId {
self.session_id
}
#[inline]
pub const fn lane(self) -> crate::control::types::Lane {
self.lane
}
}
pub trait Transport {
type Error: Into<TransportError>;
type Tx<'a>: 'a
where
Self: 'a;
type Rx<'a>: 'a
where
Self: 'a;
fn open<'a>(&'a self, port: PortOpen) -> (Self::Tx<'a>, Self::Rx<'a>);
fn poll_send<'a, 'f>(
&self,
tx: &'a mut Self::Tx<'a>,
outgoing: Outgoing<'f>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
where
'a: 'f;
fn cancel_send<'a>(&self, tx: &'a mut Self::Tx<'a>);
fn poll_recv<'a>(
&'a self,
rx: &'a mut Self::Rx<'a>,
cx: &mut Context<'_>,
) -> Poll<Result<Payload<'a>, Self::Error>>;
fn requeue<'a>(&self, rx: &mut Self::Rx<'a>) -> Result<(), Self::Error>;
fn recv_frame_hint<'a>(&self, rx: &mut Self::Rx<'a>) -> Option<FrameLabel> {
let _ = rx;
None
}
}
pub(crate) mod context;
pub(crate) mod trace;
pub(crate) mod wire;
#[cfg(all(test, hibana_repo_tests))]
mod tests;