}
@Override
public Object readMessage() throws ClassNotFoundException, IOException, MessageIncompatibleException {
// Read packet header
AMFMessage message = new AMFMessage();
int version = worker.readUnsignedShort();
message.setVersion(version);
if (worker.worksWith(message)) {
// Read headers
int headerCount = worker.readUnsignedShort();
for (int i = 0; i < headerCount; i++) {
message.getHeaders().add(readHeader());
}
// Read bodies
int bodyCount = worker.readUnsignedShort();
for (int i = 0; i < bodyCount; i++) {
message.getBodies().add(readBody());
}
} else {
throw new MessageIncompatibleException("Worker: " + worker.getClass().getCanonicalName()
+ " can't work with: " + message);
}