use core::future::Future;
use crate::transport::protocols::Protocol;
use crate::transport::TransportResult;
use crate::Frame;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct StreamId(pub u32);
impl StreamId {
pub const fn new(id: u32) -> Self {
Self(id)
}
pub const fn value(&self) -> u32 {
self.0
}
pub const fn is_client_initiated(&self) -> bool {
self.0 % 2 == 1
}
pub const fn is_server_initiated(&self) -> bool {
self.0 % 2 == 0
}
}
#[derive(Debug, Clone)]
pub struct MultiplexedFrame {
pub stream_id: StreamId,
pub frame: Frame,
}
pub trait MultiplexedProtocol: Protocol {
fn max_concurrent_streams() -> u32;
#[allow(async_fn_in_trait)]
fn emit_on_stream(
&mut self,
stream_id: StreamId,
frame: Frame,
) -> impl Future<Output = TransportResult<Option<Frame>>> + Send;
fn allocate_stream_id(&mut self) -> Option<StreamId>;
fn close_stream(&mut self, stream_id: StreamId);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StreamState {
Idle,
Open,
HalfClosedLocal,
HalfClosedRemote,
Closed,
}