// because the whole frame might not be in the buffer yet.
// We will reset the buffer position to the marked position if
// there's not enough bytes in the buffer.
buf.markReaderIndex();
TSOMessage msg;
try {
if (zipper != null) {
msg = zipper.decodeMessage(buf);
LOG.debug("Zipper returned " + msg);
if (msg != null) {
return msg;
}
buf.resetReaderIndex();
}
byte type = buf.readByte();
if (LOG.isTraceEnabled()) {
LOG.trace("Decoding message : " + type);
}
switch (type) {
case TSOMessage.TimestampRequest:
msg = new TimestampRequest();
break;
case TSOMessage.TimestampResponse:
msg = new TimestampResponse();
break;
case TSOMessage.CommitRequest:
msg = new CommitRequest();
break;
case TSOMessage.CommitResponse:
msg = new CommitResponse();
break;
case TSOMessage.CommitQueryRequest:
msg = new CommitQueryRequest();
break;
case TSOMessage.CommitQueryResponse:
msg = new CommitQueryResponse();
break;
case TSOMessage.CommittedTransactionReport:
msg = new CommittedTransactionReport();
break;
case TSOMessage.LargestDeletedTimestampReport:
msg = new LargestDeletedTimestampReport();
break;
case TSOMessage.AbortRequest:
msg = new AbortRequest();
break;
case TSOMessage.FullAbortReport:
msg = new FullAbortRequest();
break;
default:
throw new Exception("Wrong type " + type + " (" + Integer.toHexString(type) + ") " + buf.toString().length());
}
msg.readObject(buf);
} catch (IndexOutOfBoundsException e) {
// Not enough byte in the buffer, reset to the start for the next try
buf.resetReaderIndex();
return null;
} catch (EOFException e) {