Example usage for io.netty.buffer ByteBuf writeInt

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

Introduction

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

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

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

License:Apache License

@Test
public void testHttpGoAwayFrameWithDebugData() throws Exception {
    int debugDataLength = 1024;
    int length = 8 + debugDataLength;
    byte flags = 0;
    int streamId = 0; // connection identifier
    int lastStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int errorCode = RANDOM.nextInt();

    ByteBuf frame = goAwayFrame(length, flags, streamId);
    frame.writeInt(lastStreamId);
    frame.writeInt(errorCode);//from  w  w w .  j av a 2s  . c o m
    writeRandomData(frame, debugDataLength);
    decoder.decode(frame);

    verify(delegate).readGoAwayFrame(lastStreamId, errorCode);
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testInvalidHttpGoAwayFrame() throws Exception {
    int length = 4; // invalid length
    byte flags = 0;
    int streamId = 0; // connection identifier
    int lastStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf frame = goAwayFrame(length, flags, streamId);
    frame.writeInt(lastStreamId);
    decoder.decode(frame);//from  w ww.  j a va  2 s . c o  m

    verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testIllegalHttpGoAwayFrame() throws Exception {
    int length = 8;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01; // illegal stream identifier
    int lastStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int errorCode = RANDOM.nextInt();

    ByteBuf frame = goAwayFrame(length, flags, streamId);
    frame.writeInt(lastStreamId);
    frame.writeInt(errorCode);/*w  w  w.  j a v  a  2  s  . co  m*/
    decoder.decode(frame);

    verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testHttpWindowUpdateFrame() throws Exception {
    int length = 4;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF; // connection identifier allowed
    int windowSizeIncrement = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf frame = windowUpdateFrame(length, flags, streamId);
    frame.writeInt(windowSizeIncrement);
    decoder.decode(frame);/*from   w w w  .  j a  va 2s.  c  o  m*/

    verify(delegate).readWindowUpdateFrame(streamId, windowSizeIncrement);
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testHttpWindowUpdateFrameReservedBits() throws Exception {
    int length = 4;
    byte flags = (byte) 0xFF; // should ignore any unknown flags
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF; // connection identifier allowed
    int windowSizeIncrement = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf frame = windowUpdateFrame(length, flags, streamId);
    setReservedBits(frame);/*from  ww  w  .  j  av a  2  s .c  om*/
    frame.writeInt(windowSizeIncrement | 0x80000000); // should ignore reserved bit
    decoder.decode(frame);

    verify(delegate).readWindowUpdateFrame(streamId, windowSizeIncrement);
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testInvalidHttpWindowUpdateFrame() throws Exception {
    int length = 8; // invalid length
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF; // connection identifier allowed
    int windowSizeIncrement = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf frame = windowUpdateFrame(length, flags, streamId);
    frame.writeInt(windowSizeIncrement);
    decoder.decode(frame);//w  w  w. jav  a  2s . c o  m

    verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

@Test
public void testIllegalHttpWindowUpdateFrame() throws Exception {
    int length = 4;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF; // connection identifier allowed
    int windowSizeIncrement = 0; // illegal delta window size

    ByteBuf frame = windowUpdateFrame(length, flags, streamId);
    frame.writeInt(windowSizeIncrement);
    decoder.decode(frame);/*from   w w w  . j a  va 2s. co  m*/

    verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

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

License:Apache License

private ByteBuf frame(int length, int type, byte flags, int streamId) {
    ByteBuf buffer = releaseLater(Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length));
    buffer.writeMedium(length);/*  w ww  .j  ava2s . c o  m*/
    buffer.writeByte(type);
    buffer.writeByte(flags);
    buffer.writeInt(streamId);
    return buffer;
}

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

License:Apache License

private void writePriorityFields(ByteBuf frame, boolean exclusive, int dependency, int weight) {
    int dependencyWithFlag = exclusive ? dependency | 0x80000000 : dependency;
    frame.writeInt(dependencyWithFlag);
    frame.writeByte(weight);/*  w w w. j  a  v  a2  s .  c  o m*/
}