Example usage for io.netty.buffer Unpooled buffer

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

Introduction

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

Prototype

public static ByteBuf buffer() 

Source Link

Document

Creates a new big-endian Java heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand.

Usage

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndQuantity")
public void testReadHoldingRegistersRequest(int address, int quantity) {
    ReadHoldingRegistersRequest request = new ReadHoldingRegistersRequest(address, quantity);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    ReadHoldingRegistersRequest decoded = (ReadHoldingRegistersRequest) decoder.decode(encoded);

    assertEquals(request.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndQuantity")
public void testReadInputRegistersRequest(int address, int quantity) {
    ReadInputRegistersRequest request = new ReadInputRegistersRequest(address, quantity);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    ReadInputRegistersRequest decoded = (ReadInputRegistersRequest) decoder.decode(encoded);

    assertEquals(request.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test
public void testWriteSingleCoilRequest() {
    boolean[] values = new boolean[] { false, true };

    for (int address = 0; address <= 65535; address++) {
        for (boolean value : values) {
            WriteSingleCoilRequest request = new WriteSingleCoilRequest(address, value);

            ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
            WriteSingleCoilRequest decoded = (WriteSingleCoilRequest) decoder.decode(encoded);

            assertEquals(request.getAddress(), decoded.getAddress());
            assertEquals(request.getValue(), decoded.getValue());
        }/*from  ww w .j  av a 2  s .c o m*/
    }
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndRegisterValue")
public void testWriteSingleRegisterRequest(int address, int value) {
    WriteSingleRegisterRequest request = new WriteSingleRegisterRequest(address, value);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    WriteSingleRegisterRequest decoded = (WriteSingleRegisterRequest) decoder.decode(encoded);

    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getValue(), decoded.getValue());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndQuantityAndValues")
public void testWriteMultipleCoilsRequest(int address, int quantity, byte[] values) {
    WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(address, quantity, values);
    request.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    WriteMultipleCoilsRequest decoded = (WriteMultipleCoilsRequest) decoder.decode(encoded);

    request.content().resetReaderIndex();

    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
    assertEquals(request.getValues(), decoded.getValues());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test
public void testWriteMultipleRegistersRequest() {
    WriteMultipleRegistersRequest request = new WriteMultipleRegistersRequest(0, 2, new byte[] { 1, 2, 3, 4 });
    request.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    WriteMultipleRegistersRequest decoded = (WriteMultipleRegistersRequest) decoder.decode(encoded);

    request.content().resetReaderIndex();

    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
    assertEquals(request.getValues(), decoded.getValues());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test
public void testMaskWriteRegisterRequest() {
    MaskWriteRegisterRequest request = new MaskWriteRegisterRequest(0, 0x0000, 0xFFFF);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    MaskWriteRegisterRequest decoded = (MaskWriteRegisterRequest) decoder.decode(encoded);

    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getAndMask(), decoded.getAndMask());
    assertEquals(request.getOrMask(), decoded.getOrMask());
}

From source file:alluxio.network.protocol.RPCBlockReadRequestTest.java

License:Apache License

/**
 * Sets up the buffer before a test runs.
 */
@Before
public final void before() {
    mBuffer = Unpooled.buffer();
}

From source file:appeng.core.sync.packets.PacketAssemblerAnimation.java

License:Open Source License

public PacketAssemblerAnimation(final BlockPos pos, final byte rate, final IAEItemStack is) throws IOException {

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeInt(this.x = pos.getX());
    data.writeInt(this.y = pos.getY());
    data.writeInt(this.z = pos.getZ());
    data.writeByte(this.rate = rate);
    is.writeToPacket(data);//w  w w.ja  va2s . co m
    this.is = is;

    this.configureWrite(data);
}

From source file:appeng.core.sync.packets.PacketClick.java

License:Open Source License

public PacketClick(final BlockPos pos, final EnumFacing side, final float hitX, final float hitY,
        final float hitZ, final EnumHand hand) {

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeInt(this.x = pos.getX());
    data.writeInt(this.y = pos.getY());
    data.writeInt(this.z = pos.getZ());
    if (side == null) {
        data.writeByte(-1);/*from  w w w .  j a  va 2s.co  m*/
    } else {
        data.writeByte(side.ordinal());
    }
    data.writeFloat(this.hitX = hitX);
    data.writeFloat(this.hitY = hitY);
    data.writeFloat(this.hitZ = hitZ);
    data.writeByte(hand.ordinal());

    this.configureWrite(data);
}