Skip to content
This repository has been archived by the owner on Sep 13, 2018. It is now read-only.

Commit

Permalink
Reserve BytesMut size in encode.
Browse files Browse the repository at this point in the history
BytesMut::put panics if not enough free space is available.
As Encoder::encode should not panic, call BytesMut::reserve
before calling BytesMut::put.
  • Loading branch information
jannic committed Mar 18, 2017
1 parent 74de146 commit 6dacc75
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/simple_client_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ impl Encoder for IntCodec {
type Error = io::Error;

fn encode(&mut self, item: u64, into: &mut BytesMut) -> io::Result<()> {
into.put(item.to_string().as_bytes());
let string = item.to_string();
into.reserve(string.as_bytes().len());
into.put(string.as_bytes());
Ok(())
}
}
Expand Down

0 comments on commit 6dacc75

Please sign in to comment.