From 456369983826cd83233a6359cfe7aaadecf7ae95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Wed, 20 May 2020 21:45:03 +0200 Subject: [PATCH] codec: add Framed::read_buffer_mut (#2546) Adds a method to retrieve a mutable reference to the Framed stream's read buffer. This makes it possible to e.g. externally clear the buffer to prevent the codec from parsing stale data. --- tokio-util/src/codec/framed.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tokio-util/src/codec/framed.rs b/tokio-util/src/codec/framed.rs index bf05a3ae8..b23f9386c 100644 --- a/tokio-util/src/codec/framed.rs +++ b/tokio-util/src/codec/framed.rs @@ -195,6 +195,11 @@ impl Framed { &self.inner.state.read.buffer } + /// Returns a mutable reference to the read buffer. + pub fn read_buffer_mut(&mut self) -> &mut BytesMut { + &mut self.inner.state.read.buffer + } + /// Consumes the `Framed`, returning its underlying I/O stream. /// /// Note that care should be taken to not tamper with the underlying stream