Skip to content

Commit

Permalink
Merge branch 'tokio-rs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GongLG committed Feb 8, 2022
2 parents 5031a54 + 0b05ef6 commit 40416b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tokio-util/src/codec/bytes_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ impl Encoder<Bytes> for BytesCodec {
Ok(())
}
}

impl Encoder<BytesMut> 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(())
}
}
3 changes: 3 additions & 0 deletions tokio-util/tests/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 40416b3

Please sign in to comment.