final byte[] array;
final int offset;
final int length = buf.readableBytes();
if (buf.hasArray()) {
array = buf.array();
offset = buf.arrayOffset() + buf.readerIndex();
} else {
array = new byte[length];
buf.getBytes(buf.readerIndex(), array, 0, length);
offset = 0;