// Check that the packet has some free space for the header
if (buffer.rpos() < 5) {
log.warn("Performance cost: when sending a packet, ensure that "
+ "5 bytes are available in front of the buffer");
Buffer nb = new Buffer();
nb.wpos(5);
nb.putBuffer(buffer);
buffer = nb;
}
// Grab the length of the packet (excluding the 5 header bytes)
int len = buffer.available();