Example usage for io.netty.buffer ByteBuf readLong

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

Introduction

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

Prototype

public abstract long readLong();

Source Link

Document

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

Usage

From source file:z.offheap.buffer.BufferTest3.java

License:Open Source License

@Test
public void sanitycheck() {
    System.out.println("start to sanity check...");

    ByteBuffer buffer = Buffer.create(5 * 8);

    ByteBuf nettyBuf = PooledByteBufAllocator.DEFAULT.directBuffer(5 * 8);

    buffer.clear().write((byte) 1).skipWriteTo(4).networkOrder().writeShortN((short) 2).writeIntN(12345)
            .write((byte) 123).writeCharN('[').writeFloatN(3.14159f).writeDoubleN(1.9999d).writeLongN(-2L)
            .write((byte) -1).writeCharN(']').writeIntN(Integer.MIN_VALUE);
    //4+2+4+1+2+4+8+8+1+2
    //8+8+8+8+4 -> 5*Long

    nettyBuf.clear().writeByte(1).writeByte(0).writeByte(0).writeByte(0).writeShort(2).writeInt(12345)
            .writeByte(123).writeChar('[').writeFloat(3.14159f).writeDouble(1.9999d).writeLong(-2L)
            .writeByte(-1).writeChar(']').writeInt(Integer.MIN_VALUE);

    long r1 = buffer.networkOrder().readLongN();
    long r2 = nettyBuf.readLong();
    assertThat(r1, is(r2));/*  w ww . ja  va  2 s . c om*/

    r1 = buffer.networkOrder().readLongN();
    r2 = nettyBuf.readLong();
    assertThat(r1, is(r2));

    r1 = buffer.networkOrder().readLongN();
    r2 = nettyBuf.readLong();
    assertThat(r1, is(r2));

    r1 = buffer.networkOrder().readLongN();
    r2 = nettyBuf.readLong();
    assertThat(r1, is(r2));

    r1 = buffer.networkOrder().readLongN();
    r2 = nettyBuf.readLong();
    assertThat(r1, is(r2));

    buffer.close();
}

From source file:z.offheap.buffer.contrast.ContrastTestNettyByteBuf.java

License:Open Source License

private long doWithNettyByteBuf(ByteBuf bn, int i) {
    bn.clear().writeByte(i).writeByte(i).writeShort(i).writeInt(i).writeLong(i);

    long rnb1 = bn.readLong();
    long rnb2 = bn.readLong();

    return rnb1 + rnb2;
}