int length = buf.readInt();
available -= 4;
if (length <= 0) {
ret.add(new TaskMessage(task, null));
break;
}
// Make sure if there's enough bytes in the buffer.
if (available < length) {
// The whole bytes were not received yet - return null.
buf.resetReaderIndex();
break;
}
available -= length;
// There's enough bytes in the buffer. Read it.
ChannelBuffer payload = buf.readBytes(length);
// Successfully decoded a frame.
// Return a TaskMessage object
ret.add(new TaskMessage(task, payload.array()));
}
if (ret.size() == 0) {
return null;
} else {