diff --git a/tokio-util/src/codec/bytes_codec.rs b/tokio-util/src/codec/bytes_codec.rs index 275031c06..ceab228b9 100644 --- a/tokio-util/src/codec/bytes_codec.rs +++ b/tokio-util/src/codec/bytes_codec.rs @@ -74,3 +74,13 @@ impl Encoder for BytesCodec { Ok(()) } } + +impl Encoder for BytesCodec { + type Error = io::Error; + + fn encode(&mut self, data: BytesMut, buf: &mut BytesMut) -> Result<(), io::Error> { + buf.reserve(data.len()); + buf.put(data); + Ok(()) + } +} diff --git a/tokio-util/tests/codecs.rs b/tokio-util/tests/codecs.rs index aae612938..f9a780140 100644 --- a/tokio-util/tests/codecs.rs +++ b/tokio-util/tests/codecs.rs @@ -38,6 +38,9 @@ fn bytes_encoder() { codec .encode(Bytes::from_static(&[0; INITIAL_CAPACITY + 1]), &mut buf) .unwrap(); + codec + .encode(BytesMut::from(&b"hello"[..]), &mut buf) + .unwrap(); } #[test]