private static CouchbaseResponse handleOtherResponseMessages(BinaryRequest request, FullBinaryMemcacheResponse msg,
        ResponseStatus status, boolean seqOnMutation, String remoteHostname) {
        CouchbaseResponse response = null;
        ByteBuf content = msg.content();
        long cas = msg.getCAS();
        short statusCode = msg.getStatus();
        String bucket = request.bucket();

        if (request instanceof UnlockRequest) {
            response = new UnlockResponse(status, statusCode, bucket, content, request);
        } else if (request instanceof TouchRequest) {
            response = new TouchResponse(status, statusCode, bucket, content, request);
        } else if (request instanceof AppendRequest) {
            MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition());
            response = new AppendResponse(status, statusCode, cas, bucket, content, descr, request);
        } else if (request instanceof PrependRequest) {
            MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition());
            response = new PrependResponse(status, statusCode, cas, bucket, content, descr, request);
        } else if (request instanceof KeepAliveRequest) {
            releaseContent(content);
            response = new KeepAliveResponse(status, statusCode, request);
        } else if (request instanceof NoopRequest) {
            releaseContent(content);
            response = new NoopResponse(status, statusCode, request);
        } else if (request instanceof CounterRequest) {
            long value = status.isSuccess() ? content.readLong() : 0;
            releaseContent(content);

            MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition());
            response = new CounterResponse(status, statusCode, bucket, value, cas, descr, request);
        } else if (request instanceof StatRequest) {
            String key = null;
            if (msg.getKey() != null) {
                key = new String(msg.getKey(), CHARSET);
            }
            String value = content.toString(CHARSET);
            releaseContent(content);

            response = new StatResponse(status, statusCode, remoteHostname, key, value, bucket, request);
        } else if (request instanceof GetAllMutationTokensRequest) {
            // 2 bytes for partition ID, and 8 bytes for sequence number
            MutationToken[] mutationTokens = new MutationToken[content.readableBytes() / 10];
            for (int i = 0; i < mutationTokens.length; i++) {
                mutationTokens[i] = new MutationToken((long)content.readShort(), 0, content.readLong(), request.bucket());
            }
            releaseContent(content);
            response = new GetAllMutationTokensResponse(mutationTokens, status, statusCode, bucket, request);
        } else if (request instanceof ObserveRequest) {
            byte observed = ObserveResponse.ObserveStatus.UNKNOWN.value();
            long observedCas = 0;
            if (status.isSuccess()) {
                short keyLength = content.getShort(2);
                observed = content.getByte(keyLength + 4);
                observedCas = content.getLong(keyLength + 5);
            }
            releaseContent(content);
            response = new ObserveResponse(status, statusCode, observed, ((ObserveRequest) request).master(),
                    observedCas, bucket, request);
        } else if (request instanceof ObserveSeqnoRequest) {
            if (status.isSuccess()) {
                byte format = content.readByte();
                switch(format) {
                    case 0:
                        response = new NoFailoverObserveSeqnoResponse(
                            ((ObserveSeqnoRequest) request).master(),
                            content.readShort(),
                            content.readLong(),
                            content.readLong(),
                            content.readLong(),
                            status,
                            statusCode,
                            bucket,
                            request
                        );
                        break;
                    case 1:
                        response = new FailoverObserveSeqnoResponse(
                            ((ObserveSeqnoRequest) request).master(),
                            content.readShort(),
                            content.readLong(),
                            content.readLong(),
                            content.readLong(),
                            content.readLong(),
                            content.readLong(),
                            status,
                            statusCode,
                            bucket,
                            request
                        );
                        break;
                    default:
                        throw new IllegalStateException("Unknown format for observe-seq: " + format);
                }
            } else {
                response = new NoFailoverObserveSeqnoResponse(((ObserveSeqnoRequest) request).master(), (short) 0, 0,
                    0, 0, status, statusCode, bucket, request);
            }
            releaseContent(content);
        }

        return response;
    }
private static CouchbaseResponse handleOtherResponseMessages ( BinaryRequest request , FullBinaryMemcacheResponse msg , ResponseStatus status , boolean seqOnMutation , String remoteHostname ) { CouchbaseResponse response = null ; ByteBuf content = msg . content ( ) ; long cas = msg . getCAS ( ) ; short statusCode = msg . getStatus ( ) ; String bucket = request . bucket ( ) ; if ( request instanceof UnlockRequest ) { response = new UnlockResponse ( status , statusCode , bucket , content , request ) ; } else if ( request instanceof TouchRequest ) { response = new TouchResponse ( status , statusCode , bucket , content , request ) ; } else if ( request instanceof AppendRequest ) { MutationToken descr = extractToken ( bucket , seqOnMutation , status . isSuccess ( ) , msg . getExtras ( ) , request . partition ( ) ) ; response = new AppendResponse ( status , statusCode , cas , bucket , content , descr , request ) ; } else if ( request instanceof PrependRequest ) { MutationToken descr = extractToken ( bucket , seqOnMutation , status . isSuccess ( ) , msg . getExtras ( ) , request . partition ( ) ) ; response = new PrependResponse ( status , statusCode , cas , bucket , content , descr , request ) ; } else if ( request instanceof KeepAliveRequest ) { releaseContent ( content ) ; response = new KeepAliveResponse ( status , statusCode , request ) ; } else if ( request instanceof NoopRequest ) { releaseContent ( content ) ; response = new NoopResponse ( status , statusCode , request ) ; } else if ( request instanceof CounterRequest ) { long value = status . isSuccess ( ) ? content . readLong ( ) : 0 ; releaseContent ( content ) ; MutationToken descr = extractToken ( bucket , seqOnMutation , status . isSuccess ( ) , msg . getExtras ( ) , request . partition ( ) ) ; response = new CounterResponse ( status , statusCode , bucket , value , cas , descr , request ) ; } else if ( request instanceof StatRequest ) { String key = null ; if ( msg . getKey ( ) != null ) { key = new String ( msg . getKey ( ) , CHARSET ) ; } String value = content . toString ( CHARSET ) ; releaseContent ( content ) ; response = new StatResponse ( status , statusCode , remoteHostname , key , value , bucket , request ) ; } else if ( request instanceof GetAllMutationTokensRequest ) { MutationToken [ ] mutationTokens = new MutationToken [ content . readableBytes ( ) / 10 ] ; for ( int i = 0 ; i < mutationTokens . length ; i ++ ) { mutationTokens [ i ] = new MutationToken ( ( long ) content . readShort ( ) , 0 , content . readLong ( ) , request . bucket ( ) ) ; } releaseContent ( content ) ; response = new GetAllMutationTokensResponse ( mutationTokens , status , statusCode , bucket , request ) ; } else if ( request instanceof ObserveRequest ) { byte observed = ObserveResponse . ObserveStatus . UNKNOWN . value ( ) ; long observedCas = 0 ; if ( status . isSuccess ( ) ) { short keyLength = content . getShort ( 2 ) ; observed = content . getByte ( keyLength + 4 ) ; observedCas = content . getLong ( keyLength + 5 ) ; } releaseContent ( content ) ; response = new ObserveResponse ( status , statusCode , observed , ( ( ObserveRequest ) request ) . master ( ) , observedCas , bucket , request ) ; } else if ( request instanceof ObserveSeqnoRequest ) { if ( status . isSuccess ( ) ) { byte format = content . readByte ( ) ; switch ( format ) { case 0 : response = new NoFailoverObserveSeqnoResponse ( ( ( ObserveSeqnoRequest ) request ) . master ( ) , content . readShort ( ) , content . readLong ( ) , content . readLong ( ) , content . readLong ( ) , status , statusCode , bucket , request ) ; break ; case 1 : response = new FailoverObserveSeqnoResponse ( ( ( ObserveSeqnoRequest ) request ) . master ( ) , content . readShort ( ) , content . readLong ( ) , content . readLong ( ) , content . readLong ( ) , content . readLong ( ) , content . readLong ( ) , status , statusCode , bucket , request ) ; break ; default : throw new IllegalStateException ( "Unknown format for observe-seq: " + format ) ; } } else { response = new NoFailoverObserveSeqnoResponse ( ( ( ObserveSeqnoRequest ) request ) . master ( ) , ( short ) 0 , 0 , 0 , 0 , status , statusCode , bucket , request ) ; } releaseContent ( content ) ; } return response ; }
Helper method to decode all other response messages.

@param request the current request.
@param msg the current response message.
@param status the response status code.
@return the decoded response or null if none did match.