use crate::{
misc::{
ConnectionState, LeaseMut, Stream, Vector, Xorshift64,
partitioned_filled_buffer::PartitionedFilledBuffer,
},
web_socket::{
Frame, FrameMut,
compression::NegotiatedCompression,
web_socket_parts::web_socket_part::{
WebSocketCommonPart, WebSocketReaderPart, WebSocketWriterPart,
},
},
};
use core::marker::PhantomData;
#[derive(Debug)]
pub struct WebSocketCommonPartMut<'instance, NC, S, const IS_CLIENT: bool> {
pub(crate) wsc: WebSocketCommonPart<
&'instance mut ConnectionState,
&'instance mut NC,
&'instance mut Xorshift64,
&'instance mut S,
IS_CLIENT,
>,
}
#[derive(Debug)]
pub struct WebSocketReaderPartMut<'instance, NC, S, const IS_CLIENT: bool> {
pub(crate) phantom: PhantomData<(NC, S)>,
pub(crate) wsrp: WebSocketReaderPart<
&'instance mut PartitionedFilledBuffer,
&'instance mut Vector<u8>,
IS_CLIENT,
>,
}
impl<'instance, NC, S, const IS_CLIENT: bool> WebSocketReaderPartMut<'instance, NC, S, IS_CLIENT>
where
NC: NegotiatedCompression,
S: Stream,
{
#[inline]
pub async fn read_frame(
&mut self,
common: &mut WebSocketCommonPartMut<'instance, NC, S, IS_CLIENT>,
) -> crate::Result<FrameMut<'_, IS_CLIENT>> {
self.wsrp.read_frame_from_stream(&mut common.wsc).await
}
}
#[derive(Debug)]
pub struct WebSocketWriterPartMut<'instance, NC, S, const IS_CLIENT: bool> {
pub(crate) phantom: PhantomData<(NC, S)>,
pub(crate) wswp: WebSocketWriterPart<&'instance mut Vector<u8>, IS_CLIENT>,
}
impl<'instance, NC, S, const IS_CLIENT: bool> WebSocketWriterPartMut<'instance, NC, S, IS_CLIENT>
where
NC: NegotiatedCompression,
S: Stream,
{
#[inline]
pub async fn write_frame<P>(
&mut self,
common: &mut WebSocketCommonPartMut<'instance, NC, S, IS_CLIENT>,
frame: &mut Frame<P, IS_CLIENT>,
) -> crate::Result<()>
where
P: LeaseMut<[u8]>,
{
self.wswp.write_frame(&mut common.wsc, frame).await
}
}