codec: implement Encoder<BytesMut> for BytesCodec (#4465)

This commit is contained in:
Sunyeop Lee
2022-02-08 09:11:24 -05:00
committed by GitHub
parent d6143c9566
commit 0b05ef638d
2 changed files with 13 additions and 0 deletions
+10
View File
@@ -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
View File
@@ -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]