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.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertHeadersFrame(ByteBuf frame, int streamId, boolean exclusive, int dependency,
        int weight, boolean last, ByteBuf headerBlock) {
    boolean hasPriority = exclusive || dependency != HTTP_DEFAULT_DEPENDENCY || weight != HTTP_DEFAULT_WEIGHT;
    int maxLength = hasPriority ? HTTP_MAX_LENGTH - 5 : HTTP_MAX_LENGTH;
    byte type = 0x01;
    byte flags = 0x00;
    if (last) {/*from w ww  .  j  a va 2s .c o  m*/
        flags |= 0x01;
    }
    if (headerBlock.readableBytes() <= maxLength) {
        flags |= 0x04;
    }
    if (hasPriority) {
        flags |= 0x20;
    }
    int length = assertFrameHeader(frame, type, flags, streamId);
    if (hasPriority) {
        assertTrue(length >= 5);
        if (exclusive) {
            assertEquals(dependency | 0x80000000, frame.readInt());
        } else {
            assertEquals(dependency, frame.readInt());
        }
        assertEquals(weight - 1, frame.readUnsignedByte());
        length -= 5;
    }
    assertTrue(length <= headerBlock.readableBytes());
    for (int i = 0; i < length; i++) {
        assertEquals(headerBlock.readByte(), frame.readByte());
    }
    while (headerBlock.isReadable()) {
        type = 0x09;
        flags = 0x00;
        if (headerBlock.readableBytes() <= HTTP_MAX_LENGTH) {
            flags |= 0x04;
        }
        length = assertFrameHeader(frame, type, flags, streamId);
        assertTrue(length <= headerBlock.readableBytes());
        for (int i = 0; i < length; i++) {
            assertEquals(headerBlock.readByte(), frame.readByte());
        }
    }
    assertFalse(frame.isReadable());
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertPriorityFrame(ByteBuf frame, int streamId, boolean exclusive, int dependency,
        int weight) {
    byte type = 0x02;
    byte flags = 0x00;
    assertEquals(5, assertFrameHeader(frame, type, flags, streamId));
    if (exclusive) {
        assertEquals(dependency | 0x80000000, frame.readInt());
    } else {/* w ww.  j  a  va  2  s .  c om*/
        assertEquals(dependency, frame.readInt());
    }
    assertEquals(weight - 1, frame.readUnsignedByte());
    assertFalse(frame.isReadable());
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertRstStreamFrame(ByteBuf frame, int streamId, int errorCode) {
    byte type = 0x03;
    byte flags = 0x00;
    assertEquals(4, assertFrameHeader(frame, type, flags, streamId));
    assertEquals(errorCode, frame.readInt());
    assertFalse(frame.isReadable());//ww  w .ja va 2s  .  c o  m
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertSettingsFrame(ByteBuf frame, boolean ack, int id, int value) {
    byte type = 0x04;
    byte flags = ack ? (byte) 0x01 : 0x00;
    int length = assertFrameHeader(frame, type, flags, 0);
    if (ack) {/*from  w  w w.  j  a v  a2 s .c  o  m*/
        assertEquals(0, length);
    } else {
        assertEquals(6, length);
        assertEquals(id, frame.readUnsignedShort());
        assertEquals(value, frame.readInt());
    }
    assertFalse(frame.isReadable());
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertPushPromiseFrame(ByteBuf frame, int streamId, int promisedStreamId,
        ByteBuf headerBlock) {/*from  ww  w  . ja  v  a2  s . c  om*/
    int maxLength = HTTP_MAX_LENGTH - 4;
    byte type = 0x05;
    byte flags = 0x00;
    if (headerBlock.readableBytes() <= maxLength) {
        flags |= 0x04;
    }
    int length = assertFrameHeader(frame, type, flags, streamId);
    assertTrue(length >= 4);
    assertEquals(promisedStreamId, frame.readInt());
    length -= 4;
    assertTrue(length <= headerBlock.readableBytes());
    for (int i = 0; i < length; i++) {
        assertEquals(headerBlock.readByte(), frame.readByte());
    }
    while (headerBlock.isReadable()) {
        type = 0x09;
        flags = 0x00;
        if (headerBlock.readableBytes() <= HTTP_MAX_LENGTH) {
            flags |= 0x04;
        }
        length = assertFrameHeader(frame, type, flags, streamId);
        assertTrue(length <= headerBlock.readableBytes());
        for (int i = 0; i < length; i++) {
            assertEquals(headerBlock.readByte(), frame.readByte());
        }
    }
    assertFalse(frame.isReadable());
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertGoAwayFrame(ByteBuf frame, int lastStreamId, int errorCode) {
    byte type = 0x07;
    byte flags = 0x00;
    assertEquals(8, assertFrameHeader(frame, type, flags, 0));
    assertEquals(lastStreamId, frame.readInt());
    assertEquals(errorCode, frame.readInt());
    assertFalse(frame.isReadable());//w  ww  .  j a v  a2  s. c  o  m
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertWindowUpdateFrame(ByteBuf frame, int streamId, int windowSizeIncrement) {
    byte type = 0x08;
    byte flags = 0x00;
    assertEquals(4, assertFrameHeader(frame, type, flags, streamId));
    assertEquals(windowSizeIncrement, frame.readInt());
    assertFalse(frame.isReadable());/*from   ww  w.  ja  v a2 s.  c o  m*/
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static int assertFrameHeader(ByteBuf frame, byte type, byte flags, int streamId) {
    int length = frame.readUnsignedMedium();
    assertEquals(type, frame.readByte());
    assertEquals(flags, frame.readByte());
    assertEquals(streamId, frame.readInt());
    return length;
}

From source file:com.uber.tchannel.codecs.CodecUtils.java

License:Open Source License

public static int decodeChecksum(ChecksumType checksumType, ByteBuf buffer) {
    switch (checksumType) {
    case Adler32:
    case FarmhashFingerPrint32:
    case CRC32C:/*from  www. j av a  2s  .c  o m*/
        return buffer.readInt();
    case NoChecksum:
    default:
        return 0;
    }
}

From source file:com.vethrfolnir.game.network.login.LoginServerClientHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf buff = (ByteBuf) msg;

    int opcode = buff.readUnsignedByte();

    switch (opcode) {
    case 0xBB://from   ww w .  j av a 2s  .  c om
        ServerKill.read(serverClient, buff);
        break;
    case 0xA1:
        int newId = buff.readInt();
        RecievedAlternativeId.read(serverClient, buff, newId);
        break;
    default:
        log.warn("Unknown packet 0x" + PrintData.fillHex(opcode, 2) + ". Dump: "
                + PrintData.printData(buff.nioBuffer(0, buff.writerIndex())));
        break;
    }

    buff.release();
}