Example usage for io.netty.buffer ByteBuf forEachByteDesc

List of usage examples for io.netty.buffer ByteBuf forEachByteDesc

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf forEachByteDesc.

Prototype

public abstract int forEachByteDesc(ByteProcessor processor);

Source Link

Document

Iterates over the readable bytes of this buffer with the specified processor in descending order.

Usage

From source file:com.couchbase.client.core.endpoint.view.ViewHandler.java

License:Apache License

/**
 * Parse out the info portion from the header part of the query response.
 *
 * This includes the total rows, but also debug info if attached.
 *///from  ww w. j  a v  a2 s .co m
private void parseViewInfo() {
    int rowsStart = -1;
    for (int i = responseContent.readerIndex(); i < responseContent.writerIndex() - 2; i++) {
        byte curr = responseContent.getByte(i);
        byte f1 = responseContent.getByte(i + 1);
        byte f2 = responseContent.getByte(i + 2);

        if (curr == '"' && f1 == 'r' && f2 == 'o') {
            rowsStart = i;
            break;
        }
    }

    if (rowsStart == -1) {
        return;
    }

    ByteBuf info = responseContent.readBytes(rowsStart - responseContent.readerIndex());
    int closingPointer = info.forEachByteDesc(new ByteBufProcessor() {
        @Override
        public boolean process(byte value) throws Exception {
            return value != ',';
        }
    });

    if (closingPointer > 0) {
        info.setByte(closingPointer, '}');
        viewInfoObservable.onNext(info);
    } else {
        viewInfoObservable.onNext(Unpooled.EMPTY_BUFFER);
    }
    viewInfoObservable.onCompleted();
    viewParsingState = QUERY_STATE_ROWS;
}