long requestId = buffer.readLong();
byte status = buffer.readByte();
boolean isRequest = TransportStreams.statusIsRequest(status);
HandlesStreamInput handlesStream;
if (TransportStreams.statusIsCompress(status)) {
handlesStream = CachedStreamInput.cachedHandlesLzf(streamIn);
} else {
handlesStream = CachedStreamInput.cachedHandles(streamIn);
}
if (isRequest) {
String action = handleRequest(event, handlesStream, requestId);
if (buffer.readerIndex() != expectedIndexReader) {
if (buffer.readerIndex() < expectedIndexReader) {
logger.warn("Message not fully read (request) for [{}] and action [{}], resetting", requestId, action);
} else {
logger.warn("Message read past expected size (request) for [{}] and action [{}], resetting", requestId, action);
}
buffer.readerIndex(expectedIndexReader);
}
} else {
TransportResponseHandler handler = transportServiceAdapter.remove(requestId);
// ignore if its null, the adapter logs it
if (handler != null) {
if (TransportStreams.statusIsError(status)) {
handlerResponseError(handlesStream, handler);
} else {
handleResponse(handlesStream, handler);
}
} else {
// if its null, skip those bytes
buffer.readerIndex(markedReaderIndex + size);
}
if (buffer.readerIndex() != expectedIndexReader) {
if (buffer.readerIndex() < expectedIndexReader) {
logger.warn("Message not fully read (response) for [{}] handler {}, error [{}], resetting", requestId, handler, TransportStreams.statusIsError(status));
} else {
logger.warn("Message read past expected size (response) for [{}] handler {}, error [{}], resetting", requestId, handler, TransportStreams.statusIsError(status));
}
buffer.readerIndex(expectedIndexReader);
}
}
handlesStream.cleanHandles();
}