Example usage for io.netty.buffer Unpooled EMPTY_BUFFER

List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled EMPTY_BUFFER.

Prototype

ByteBuf EMPTY_BUFFER

To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.

Click Source Link

Document

A buffer whose capacity is 0 .

Usage

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

License:Apache License

@Test
public void testEmptyHttpHeadersFrame() throws Exception {
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    boolean exclusive = RANDOM.nextBoolean();
    int dependency = RANDOM.nextInt() & 0x7FFFFFFF;
    int weight = (RANDOM.nextInt() & 0xFF) + 1;
    ByteBuf frame = releaseLater(//from   w  ww. j  a va 2  s. c  om
            ENCODER.encodeHeadersFrame(streamId, false, exclusive, dependency, weight, Unpooled.EMPTY_BUFFER));
    assertHeadersFrame(frame, streamId, exclusive, dependency, weight, false, Unpooled.EMPTY_BUFFER);
}

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

License:Apache License

@Test
public void testLastHttpHeadersFrame() throws Exception {
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    boolean exclusive = false;
    int dependency = HTTP_DEFAULT_DEPENDENCY;
    int weight = HTTP_DEFAULT_WEIGHT;
    ByteBuf frame = releaseLater(// w w  w . ja v a2 s.c  om
            ENCODER.encodeHeadersFrame(streamId, true, exclusive, dependency, weight, Unpooled.EMPTY_BUFFER));
    assertHeadersFrame(frame, streamId, exclusive, dependency, weight, true, Unpooled.EMPTY_BUFFER);
}

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

License:Apache License

@Test
public void testEmptyHttpPushPromiseFrame() throws Exception {
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    ByteBuf frame = releaseLater(/*ww  w .j av  a  2  s.  co  m*/
            ENCODER.encodePushPromiseFrame(streamId, promisedStreamId, Unpooled.EMPTY_BUFFER));
    assertPushPromiseFrame(frame, streamId, promisedStreamId, Unpooled.EMPTY_BUFFER);
}

From source file:com.uber.tchannel.checksum.ChecksumsTest.java

License:Open Source License

@Test
public void testVerifyAcceptNoChecksum() throws Exception {
    CallRequestFrame callRequestFrame = Fixtures.callRequest(0, false, Unpooled.EMPTY_BUFFER);
    assertTrue(Checksums.verifyChecksum(callRequestFrame));
    callRequestFrame.release();/*from   ww  w  . jav a  2 s. c  o  m*/
}

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

License:Open Source License

public static ByteBuf compose(ByteBuf first, ByteBuf second) {
    if (first == Unpooled.EMPTY_BUFFER) {
        return second;
    } else if (second == Unpooled.EMPTY_BUFFER) {
        return first;
    } else {/* ww  w . j a v a 2  s .co m*/
        return Unpooled.wrappedBuffer(first, second);
    }
}

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

License:Open Source License

public static ByteBuf readArg(ByteBuf buffer) {
    if (buffer.readableBytes() < TFrame.FRAME_SIZE_LENGTH) {
        return null;
    }/*w w w  . jav  a2  s . com*/

    int len = buffer.readUnsignedShort();
    if (len > buffer.readableBytes()) {
        throw new UnsupportedOperationException("wrong read index for args");
    } else if (len == 0) {
        return Unpooled.EMPTY_BUFFER;
    }

    /* Read a slice, retain a copy */
    ByteBuf arg = buffer.readSlice(len);
    arg.retain();

    return arg;
}

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

License:Open Source License

public static void readArgs(List<ByteBuf> args, ByteBuf buffer) {

    ByteBuf arg = null;/*from   w  w  w.j  a  v a 2s  . c  o  m*/
    if (args.isEmpty()) {
        args.add(Unpooled.EMPTY_BUFFER);
    }

    boolean first = true;
    while (true) {
        arg = readArg(buffer);
        if (arg == null) {
            return;
        } else if (first) {
            first = false;
            ByteBuf prev = args.get(args.size() - 1);
            args.set(args.size() - 1, compose(prev, arg));
        } else {
            args.add(arg);
        }
    }
}

From source file:com.uber.tchannel.frames.CallFrame.java

License:Open Source License

public final ByteBuf encodePayload(ByteBufAllocator allocator) {
    List<ByteBuf> args = new ArrayList<>();
    args.add(Unpooled.EMPTY_BUFFER);
    args.add(Unpooled.EMPTY_BUFFER);//from w  w  w . j  a  va2s. c  o  m
    args.add(Unpooled.EMPTY_BUFFER);
    return encodePayload(allocator, args);
}

From source file:com.uber.tchannel.frames.PingRequestFrame.java

License:Open Source License

@Override
public ByteBuf encodeHeader(ByteBufAllocator allocator) {
    return Unpooled.EMPTY_BUFFER;
}

From source file:com.uber.tchannel.handlers.InitDefaultRequestHandlerTest.java

License:Open Source License

@Test
public void testInvalidCallBeforeInitRequest() throws Exception {
    // Given/*from  ww  w. j  a  va  2 s. c o  m*/
    EmbeddedChannel channel = new EmbeddedChannel(new InitRequestHandler(new PeerManager(new Bootstrap())));

    CallRequestFrame callRequestFrame = Fixtures.callRequest(0, false, Unpooled.EMPTY_BUFFER);

    channel.writeInbound(
            MessageCodec.encode(MessageCodec.encode(PooledByteBufAllocator.DEFAULT, callRequestFrame)));

    TFrame tFrame = MessageCodec.decode((ByteBuf) channel.readOutbound());
    ErrorFrame errorFrame = (ErrorFrame) MessageCodec.decode(tFrame);
    tFrame.release();
    assertNotNull(errorFrame);
    assertThat(errorFrame.getErrorType(), is(ErrorType.FatalProtocolError));
    assertThat(errorFrame.getMessage(), containsString("The first frame should be an Init Request"));

    channel.writeOutbound();
}