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