Skip to content

Commit

Permalink
Allocate enough room for type byte as well as message, to avoid tripp…
Browse files Browse the repository at this point in the history
…ing assertion about capacity of the buffer
  • Loading branch information
srowen committed Dec 9, 2014
1 parent bcb5cda commit 9e1d502
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static BlockTransferMessage fromByteArray(byte[] msg) {

/** Serializes the 'type' byte followed by the message itself. */
public byte[] toByteArray() {
ByteBuf buf = Unpooled.buffer(encodedLength());
// Allow room for encoded message, plus the type byte
ByteBuf buf = Unpooled.buffer(encodedLength() + 1);
buf.writeByte(type().id);
encode(buf);
assert buf.writableBytes() == 0 : "Writable bytes remain: " + buf.writableBytes();
Expand Down

0 comments on commit 9e1d502

Please sign in to comment.