Skip to content

Commit

Permalink
util: expose FramedWrite/Framed::write_buffer/write_buffer_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
craftytrickster authored Jan 8, 2021
1 parent e42317b commit 2fe2f04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tokio-util/src/codec/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ impl<T, U> Framed<T, U> {
&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
Expand Down
11 changes: 11 additions & 0 deletions tokio-util/src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,16 @@ impl<T, E> FramedWrite<T, E> {
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
Expand Down

0 comments on commit 2fe2f04

Please sign in to comment.