diff --git a/tokio-util/src/codec/framed.rs b/tokio-util/src/codec/framed.rs index 8f2317f09..c95d643b0 100644 --- a/tokio-util/src/codec/framed.rs +++ b/tokio-util/src/codec/framed.rs @@ -120,6 +120,11 @@ impl Framed { &mut self.inner.get_mut().get_mut().1 } + /// Returns a reference to the read buffer. + pub fn read_buffer(&self) -> &BytesMut { + self.inner.buffer() + } + /// Consumes the `Frame`, returning its underlying I/O stream. /// /// Note that care should be taken to not tamper with the underlying stream diff --git a/tokio-util/src/codec/framed_read.rs b/tokio-util/src/codec/framed_read.rs index 6f79cb9a7..e10f2968c 100644 --- a/tokio-util/src/codec/framed_read.rs +++ b/tokio-util/src/codec/framed_read.rs @@ -79,6 +79,11 @@ impl FramedRead { pub fn decoder_mut(&mut self) -> &mut D { &mut self.inner.inner.1 } + + /// Returns a reference to the read buffer. + pub fn read_buffer(&self) -> &BytesMut { + &self.inner.buffer + } } impl Stream for FramedRead @@ -174,6 +179,10 @@ impl FramedRead2 { pub(crate) fn get_mut(&mut self) -> &mut T { &mut self.inner } + + pub(crate) fn buffer(&self) -> &BytesMut { + &self.buffer + } } impl Stream for FramedRead2