use std::io;
use tokio::io::duplex;
use wireframe::app::{Packet, WireframeApp};
use super::{EMPTY_SERVER_CAPACITY, MAX_CAPACITY, TestSerializer, drive::drive_internal};
pub async fn run_app<S, C, E>(
app: WireframeApp<S, C, E>,
frames: Vec<Vec<u8>>,
capacity: Option<usize>,
) -> io::Result<Vec<u8>>
where
S: TestSerializer,
C: Send + 'static,
E: Packet,
{
let capacity = capacity.unwrap_or(super::DEFAULT_CAPACITY);
if capacity == 0 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"capacity must be greater than zero",
));
}
if capacity > MAX_CAPACITY {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("capacity must not exceed {MAX_CAPACITY} bytes"),
));
}
drive_internal(
|server| async move { app.handle_connection(server).await },
frames,
capacity,
)
.await
}
pub async fn run_with_duplex_server<S, C, E>(app: WireframeApp<S, C, E>)
where
S: TestSerializer,
C: Send + 'static,
E: Packet,
{
let (_, server) = duplex(EMPTY_SERVER_CAPACITY); app.handle_connection(server).await;
}