From 2fe2f0401b159a980e17635c8cce7b991d542fe2 Mon Sep 17 00:00:00 2001 From: David Raifaizen Date: Fri, 8 Jan 2021 17:20:07 -0500 Subject: [PATCH] util: expose FramedWrite/Framed::write_buffer/write_buffer_mut --- tokio-util/src/codec/framed.rs | 10 ++++++++++ tokio-util/src/codec/framed_write.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/tokio-util/src/codec/framed.rs b/tokio-util/src/codec/framed.rs index cb9941234..fe00c0785 100644 --- a/tokio-util/src/codec/framed.rs +++ b/tokio-util/src/codec/framed.rs @@ -208,6 +208,16 @@ impl Framed { &mut self.inner.state.read.buffer } + /// Returns a reference to the write buffer. + pub fn write_buffer(&self) -> &BytesMut { + &self.inner.state.write.buffer + } + + /// Returns a mutable reference to the write buffer. + pub fn write_buffer_mut(&mut self) -> &mut BytesMut { + &mut self.inner.state.write.buffer + } + /// Consumes the `Framed`, 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_write.rs b/tokio-util/src/codec/framed_write.rs index a166bec33..7df0d6a80 100644 --- a/tokio-util/src/codec/framed_write.rs +++ b/tokio-util/src/codec/framed_write.rs @@ -4,6 +4,7 @@ use crate::codec::framed_impl::{FramedImpl, WriteFrame}; use tokio::io::AsyncWrite; use tokio_stream::Stream; +use bytes::BytesMut; use futures_sink::Sink; use pin_project_lite::pin_project; use std::fmt; @@ -86,6 +87,16 @@ impl FramedWrite { pub fn encoder_mut(&mut self) -> &mut E { &mut self.inner.codec } + + /// Returns a reference to the write buffer. + pub fn write_buffer(&self) -> &BytesMut { + &self.inner.state.buffer + } + + /// Returns a mutable reference to the write buffer. + pub fn write_buffer_mut(&mut self) -> &mut BytesMut { + &mut self.inner.state.buffer + } } // This impl just defers to the underlying FramedImpl