use core::{
pin::Pin,
task::{Context, Poll},
};
use crate::body::{Body, Frame, SizeHint};
use ::h3::server::RequestStream;
use h3_quinn::RecvStream;
use crate::{
bytes::{Buf, Bytes},
error::BodyError,
};
pub struct RequestBody(pub(super) RequestStream<RecvStream, Bytes>);
impl Body for RequestBody {
type Data = Bytes;
type Error = BodyError;
fn poll_frame(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Frame<Bytes>, BodyError>>> {
self.get_mut()
.0
.poll_recv_data(cx)?
.map(|res| res.map(|buf| Ok(Frame::Data(Bytes::copy_from_slice(buf.chunk())))))
}
fn is_end_stream(&self) -> bool {
false
}
fn size_hint(&self) -> SizeHint {
SizeHint::default()
}
}
impl From<RequestBody> for crate::body::RequestBody {
fn from(body: RequestBody) -> Self {
Self::H3(body)
}
}