async_compression/tokio/bufread/generic/
decoder.rs1use crate::{
2 codecs::DecodeV2,
3 core::util::{PartialBuffer, WriteBuffer},
4 generic::bufread::impl_decoder,
5};
6
7use core::{
8 pin::Pin,
9 task::{Context, Poll},
10};
11use std::io::{IoSlice, Result};
12
13use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
14
15impl_decoder!();
16
17impl<R: AsyncBufRead, D: DecodeV2> AsyncRead for Decoder<R, D> {
18 fn poll_read(
19 self: Pin<&mut Self>,
20 cx: &mut Context<'_>,
21 buf: &mut ReadBuf<'_>,
22 ) -> Poll<Result<()>> {
23 if buf.remaining() == 0 {
24 return Poll::Ready(Ok(()));
25 }
26
27 let mut output = WriteBuffer::new_initialized(buf.initialize_unfilled());
28 match self.do_poll_read(cx, &mut output)? {
29 Poll::Pending if output.written().is_empty() => Poll::Pending,
30 _ => {
31 let len = output.written_len();
32 buf.advance(len);
33 Poll::Ready(Ok(()))
34 }
35 }
36 }
37}
38
39impl<R: AsyncWrite, D> AsyncWrite for Decoder<R, D> {
40 fn poll_write(
41 mut self: Pin<&mut Self>,
42 cx: &mut Context<'_>,
43 buf: &[u8],
44 ) -> Poll<Result<usize>> {
45 self.get_pin_mut().poll_write(cx, buf)
46 }
47
48 fn poll_write_vectored(
49 mut self: Pin<&mut Self>,
50 cx: &mut Context<'_>,
51 mut bufs: &[IoSlice<'_>],
52 ) -> Poll<Result<usize>> {
53 self.get_pin_mut().poll_write_vectored(cx, bufs)
54 }
55
56 fn is_write_vectored(&self) -> bool {
57 self.get_ref().is_write_vectored()
58 }
59
60 fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
61 self.get_pin_mut().poll_flush(cx)
62 }
63
64 fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
65 self.get_pin_mut().poll_shutdown(cx)
66 }
67}