diff --git a/tonic/src/codec/decode.rs b/tonic/src/codec/decode.rs index 157a27093..dbebfe21e 100644 --- a/tonic/src/codec/decode.rs +++ b/tonic/src/codec/decode.rs @@ -180,6 +180,7 @@ impl Streaming { } }; let len = self.buf.get_u32() as usize; + self.buf.reserve(len); self.state = State::ReadBody { compression: is_compressed, @@ -235,16 +236,6 @@ impl Stream for Streaming { }; if let Some(data) = chunk { - if data.remaining() > self.buf.remaining_mut() { - let amt = if data.remaining() > BUFFER_SIZE { - data.remaining() - } else { - BUFFER_SIZE - }; - - self.buf.reserve(amt); - } - self.buf.put(data); } else { // FIXME: improve buf usage.