Example usage for io.netty.buffer ByteBuf readInt

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

Introduction

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

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:com.eightkdata.mongowp.mongoserver.decoder.GetMoreMessageDecoder.java

License:Open Source License

@Override
public @Nonnegative GetMoreMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    buffer.skipBytes(4);/*w w w .j a va2s  .com*/
    String fullCollectionName = ByteBufUtil.readCString(buffer);
    int numberToReturn = buffer.readInt();
    long cursorId = buffer.readLong();

    return new GetMoreMessage(requestBaseMessage, fullCollectionName, numberToReturn, cursorId);
}

From source file:com.eightkdata.mongowp.mongoserver.decoder.InsertMessageDecoder.java

License:Open Source License

@Override
public @Nonnegative InsertMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    int flags = buffer.readInt();
    String fullCollectionName = ByteBufUtil.readCString(buffer);
    List<BSONDocument> documents = new ArrayList<BSONDocument>();
    while (buffer.readableBytes() > 0) {
        documents.add(new MongoBSONDocument(buffer));
    }// w ww  .  j ava  2 s  .  c o  m

    return new InsertMessage(requestBaseMessage, flags, fullCollectionName, documents);
}

From source file:com.eightkdata.mongowp.mongoserver.decoder.KillCursorsMessageDecoder.java

License:Open Source License

@Override
public @Nonnegative KillCursorsMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    buffer.skipBytes(4);/*from  w w  w  .  j av  a 2 s  .co m*/
    int numberOfCursors = buffer.readInt();
    long[] cursorIds = new long[numberOfCursors];
    for (int index = 0; index < numberOfCursors; index++) {
        cursorIds[index] = buffer.readLong();
    }

    return new KillCursorsMessage(requestBaseMessage, numberOfCursors, cursorIds);
}

From source file:com.eightkdata.mongowp.mongoserver.decoder.QueryMessageDecoder.java

License:Open Source License

@Override
public @Nonnegative QueryMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    int flags = buffer.readInt();
    String fullCollectionName = ByteBufUtil.readCString(buffer);
    int numberToSkip = buffer.readInt();
    int numberToReturn = buffer.readInt();
    BSONDocument document = new MongoBSONDocument(buffer);
    BSONDocument returnFieldsSelector = buffer.readableBytes() > 0 ? new MongoBSONDocument(buffer) : null;

    return new QueryMessage(requestBaseMessage, flags, fullCollectionName, numberToSkip, numberToReturn,
            document, returnFieldsSelector);
}

From source file:com.eightkdata.mongowp.mongoserver.decoder.UpdateMessageDecoder.java

License:Open Source License

@Override
public @Nonnegative UpdateMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    buffer.skipBytes(4);// w  ww .ja v  a  2  s .c om
    String fullCollectionName = ByteBufUtil.readCString(buffer);
    int flags = buffer.readInt();
    BSONDocument selector = new MongoBSONDocument(buffer);
    BSONDocument update = new MongoBSONDocument(buffer);

    return new UpdateMessage(requestBaseMessage, flags, fullCollectionName, selector, update);
}

From source file:com.eightkdata.mongowp.mongoserver.RequestMessageByteHandler.java

License:Open Source License

@Override
protected void decodeLittleEndian(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf,
        List<Object> objects) throws Exception {
    if (byteBuf instanceof EmptyByteBuf) {
        //TODO: This is a workaround. Check how to prevent calling decode on channel inactive
        return;/*from   w  ww  .j a va 2s  .c o  m*/
    }

    // Header
    RequestBaseMessage requestBaseMessage = BaseMessageDecoder.decode(channelHandlerContext, byteBuf);
    byteBuf.skipBytes(Ints.BYTES); // Ignore responseTo field in header
    int requestOpCodeInt = byteBuf.readInt();
    RequestOpCode requestOpCode = RequestOpCode.getByOpcode(requestOpCodeInt);
    if (null == requestOpCode) {
        LOGGER.warn(INVALID_OPCODE_MESSAGE, requestOpCodeInt);
        throw new InvalidMessageException(INVALID_OPCODE_MESSAGE + requestOpCodeInt);
    }

    // Body
    MessageDecoder<?> messageDecoder = MessageDecoderLocator.getByOpCode(requestOpCode);
    if (null == messageDecoder) {
        LOGGER.error(OPERATION_NOT_IMPLEMENTED, requestOpCode);
        throw new UnsupportedOperationException(OPERATION_NOT_IMPLEMENTED + requestOpCode);
    }

    objects.add(messageDecoder.decode(byteBuf, requestBaseMessage));
}

From source file:com.eightkdata.mongowp.server.decoder.DeleteMessageDecoder.java

License:Open Source License

@Override
@Nonnegative//from w  w w .j  a  va  2  s . c om
public DeleteMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidNamespaceException, InvalidBsonException {
    try {
        MyBsonContext context = new MyBsonContext(buffer);

        buffer.skipBytes(4);
        String fullCollectionName = stringReader.readCString(buffer, true);
        int flags = buffer.readInt();

        BsonDocument document = docReader.readDocument(HEAP, buffer);

        //TODO: improve the way database and cache are pooled
        String database = getDatabase(fullCollectionName).intern();
        String collection = getCollection(fullCollectionName).intern();

        return new DeleteMessage(requestBaseMessage, context, database, collection, document,
                EnumInt32FlagsUtil.isActive(Flag.SINGLE_REMOVE, flags));
    } catch (NettyBsonReaderException ex) {
        throw new InvalidBsonException(ex);
    }
}

From source file:com.eightkdata.mongowp.server.decoder.GetMoreMessageDecoder.java

License:Open Source License

@Override
public GetMoreMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidNamespaceException, InvalidBsonException {
    try {/*  w ww.j av  a 2  s.c o m*/
        buffer.skipBytes(4);
        String fullCollectionName = stringReader.readCString(buffer, true);
        int numberToReturn = buffer.readInt();
        long cursorId = buffer.readLong();

        //TODO: improve the way database and cache are pooled
        return new GetMoreMessage(requestBaseMessage, getDatabase(fullCollectionName).intern(),
                getCollection(fullCollectionName).intern(), numberToReturn, cursorId);
    } catch (NettyBsonReaderException ex) {
        throw new InvalidBsonException(ex);
    }
}

From source file:com.eightkdata.mongowp.server.decoder.InsertMessageDecoder.java

License:Open Source License

@Override
@SuppressFBWarnings(value = {//from   w  ww .  j a  va2  s .  co  m
        "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT" }, justification = "Findbugs thinks ByteBuf#readerIndex(...) has no"
                + "side effect")
public InsertMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidNamespaceException, InvalidBsonException {
    try {
        MyBsonContext context = new MyBsonContext(buffer);

        int flags = buffer.readInt();
        String fullCollectionName = stringReader.readCString(buffer, true);

        ByteBuf docBuf = buffer.slice(buffer.readerIndex(), buffer.readableBytes());
        docBuf.retain();

        buffer.readerIndex(buffer.writerIndex());

        ByteBufIterableDocumentProvider documents = new ByteBufIterableDocumentProvider(docBuf, docReader);

        //TODO: improve the way database and cache are pooled
        return new InsertMessage(requestBaseMessage, context, getDatabase(fullCollectionName).intern(),
                getCollection(fullCollectionName).intern(),
                EnumInt32FlagsUtil.isActive(Flag.CONTINUE_ON_ERROR, flags), documents);
    } catch (NettyBsonReaderException ex) {
        throw new InvalidBsonException(ex);
    }
}

From source file:com.eightkdata.mongowp.server.decoder.KillCursorsMessageDecoder.java

License:Open Source License

@Override
public KillCursorsMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidNamespaceException {
    buffer.skipBytes(4);/*from   ww  w .j a va  2 s.  c  o  m*/
    int numberOfCursors = buffer.readInt();
    long[] cursorIds = new long[numberOfCursors];
    for (int index = 0; index < numberOfCursors; index++) {
        cursorIds[index] = buffer.readLong();
    }

    return new KillCursorsMessage(requestBaseMessage, numberOfCursors, cursorIds);
}