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.bson.netty.DefaultNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonJavaScriptWithScope readJavaScriptWithScope(@Loose @ModifiesIndexes ByteBuf byteBuf)
        throws NettyBsonReaderException {
    byteBuf.readInt();
    String js = getStringReader().readString(byteBuf, false);
    BsonDocument scope = readJavaScriptScope(byteBuf);

    return new DefaultBsonJavaScriptWithCode(js, scope);
}

From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonTimestamp readTimestamp(@Loose @ModifiesIndexes ByteBuf byteBuf) {
    int ordinal = byteBuf.readInt();
    int seconds = byteBuf.readInt();
    return new DefaultBsonTimestamp(seconds, ordinal);
}

From source file:com.eightkdata.mongowp.bson.netty.OffHeapNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonDocument readDocument(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException {
    int length = byteBuf.readInt();
    int significantLenght = length - 4; //the final 0x00 must be included

    ByteBuf significantSlice = byteBuf.readSlice(significantLenght);

    assert byteBuf.getByte(byteBuf.readerIndex() - 1) == 0x00;

    return new IterableNettyBsonDocument(significantSlice, this);
}

From source file:com.eightkdata.mongowp.bson.netty.OffHeapNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonArray readArray(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException {
    int length = byteBuf.readInt();
    int significantLenght = length - 4; //the final 0x00 must be included

    ByteBuf significantSlice = byteBuf.readSlice(significantLenght);

    assert byteBuf.getByte(byteBuf.readerIndex() - 1) == 0x00;

    return new IterableNettyBsonArray(significantSlice, this);
}

From source file:com.eightkdata.mongowp.bson.netty.OffHeapValuesNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonDocument readDocument(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException {
    int length = byteBuf.readInt();
    int significantLenght = length - 4 - 1;

    ByteBuf significantSlice = byteBuf.readSlice(significantLenght);

    byte b = byteBuf.readByte();
    assert b == 0x00;

    ArrayList<BsonDocument.Entry<?>> list = new ArrayList<>();
    while (significantSlice.readableBytes() > 0) {
        Entry<?> entry = readDocumentEntry(significantSlice);
        list.add(entry);/*  ww  w.ja  va 2s  . c  om*/
    }
    return new ListBasedBsonDocument(list);
}

From source file:com.eightkdata.mongowp.bson.netty.OffHeapValuesNettyBsonLowLevelReader.java

License:Open Source License

@Override
BsonBinary readBinary(@Loose @ModifiesIndexes ByteBuf byteBuf) {
    int length = byteBuf.readInt();
    byte subtype = byteBuf.readByte();

    ByteBuf content = byteBuf.readSlice(length);

    return new NettyBsonBsonBinary(subtype, ParsingTools.getBinarySubtype(subtype), content);
}

From source file:com.eightkdata.mongowp.bson.netty.PooledNettyStringReader.java

License:Open Source License

@Override
public String readString(@Loose @ModifiesIndexes ByteBuf byteBuf, boolean likelyCacheable) {
    int stringLength = byteBuf.readInt();

    String str = stringPool.fromPool(likelyCacheable, byteBuf.slice(byteBuf.readerIndex(), stringLength - 1));

    byteBuf.skipBytes(stringLength);//from  w w w .ja  va2s.c  o  m

    return str;
}

From source file:com.eightkdata.mongowp.bson.netty.PooledNettyStringReader.java

License:Open Source License

@Override
public ByteBuf readStringAsSlice(@Loose @ModifiesIndexes ByteBuf byteBuf) {
    int stringLength = byteBuf.readInt();
    ByteBuf result = byteBuf.readSlice(stringLength - 1);
    byte b = byteBuf.readByte(); // discard the last 0x00
    assert b == 0x00;

    return result;
}

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

License:Open Source License

/**
 * Method that constructs a RequestBaseMessage object based on a correctly-positioned ByteBuf.
 * This method modifies the internal state of the ByteBuf.
 * It expects the ByteBuf to be positioned just before the start of the requestId field.
 * After running, the method will leave the ByteBuf positioned just after the responseTo field,
 * i.e., just before reading the opCode.
 *
 * @param channelHandlerContext/* ww  w .  ja  va 2 s .  c om*/
 * @param byteBuf
 * @return
 */
public static RequestBaseMessage decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
    InetSocketAddress socketAddress = (InetSocketAddress) channelHandlerContext.channel().remoteAddress();

    return new RequestBaseMessage(socketAddress.getAddress(), socketAddress.getPort(), byteBuf.readInt());
}

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

License:Open Source License

@Override
public @Nonnegative DeleteMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidMessageException {
    buffer.skipBytes(4);//w w w.j  a  v a2  s .  com
    String fullCollectionName = ByteBufUtil.readCString(buffer);
    int flags = buffer.readInt();
    BSONDocument document = new MongoBSONDocument(buffer);

    return new DeleteMessage(requestBaseMessage, flags, fullCollectionName, document);
}