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:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testReadCoilsResponse() {
    ReadCoilsResponse response = new ReadCoilsResponse(Unpooled.buffer().writeByte(1));
    response.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    ReadCoilsResponse decoded = (ReadCoilsResponse) decoder.decode(encoded);

    response.content().resetReaderIndex();

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getCoilStatus(), decoded.getCoilStatus());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testReadDiscreteInputsResponse() {
    ReadDiscreteInputsResponse response = new ReadDiscreteInputsResponse(Unpooled.buffer().writeByte(1));
    response.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    ReadDiscreteInputsResponse decoded = (ReadDiscreteInputsResponse) decoder.decode(encoded);

    response.content().resetReaderIndex();

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getInputStatus(), decoded.getInputStatus());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testReadHoldingRegistersResponse() {
    ReadHoldingRegistersResponse response = new ReadHoldingRegistersResponse(
            Unpooled.buffer().writeByte(1).writeByte(2));
    response.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    ReadHoldingRegistersResponse decoded = (ReadHoldingRegistersResponse) decoder.decode(encoded);

    response.content().resetReaderIndex();

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getRegisters(), decoded.getRegisters());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testReadInputRegistersResponse() {
    ReadInputRegistersResponse response = new ReadInputRegistersResponse(
            Unpooled.buffer().writeByte(1).writeByte(2));
    response.retain().content().markReaderIndex();

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    ReadInputRegistersResponse decoded = (ReadInputRegistersResponse) decoder.decode(encoded);

    response.content().resetReaderIndex();

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getRegisters(), decoded.getRegisters());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testWriteSingleCoilResponse() {
    WriteSingleCoilResponse response = new WriteSingleCoilResponse(0, 0xFF00);

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    WriteSingleCoilResponse decoded = (WriteSingleCoilResponse) decoder.decode(encoded);

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getAddress(), decoded.getAddress());
    assertEquals(response.getValue(), decoded.getValue());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testWriteSingleRegisterResponse() {
    WriteSingleRegisterResponse response = new WriteSingleRegisterResponse(0, 0xFF00);

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    WriteSingleRegisterResponse decoded = (WriteSingleRegisterResponse) decoder.decode(encoded);

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getAddress(), decoded.getAddress());
    assertEquals(response.getValue(), decoded.getValue());
}

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testWriteMultipleCoilsResponse() {
    WriteMultipleCoilsResponse response = new WriteMultipleCoilsResponse(0, 10);

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    WriteMultipleCoilsResponse decoded = (WriteMultipleCoilsResponse) decoder.decode(encoded);

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

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testWriteMultipleRegistersResponse() {
    WriteMultipleRegistersResponse response = new WriteMultipleRegistersResponse(0, 10);

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    WriteMultipleRegistersResponse decoded = (WriteMultipleRegistersResponse) decoder.decode(encoded);

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

From source file:ModbusResponseSerializationTest.java

License:Apache License

@Test
public void testMaskWriteRegisterResponse() {
    MaskWriteRegisterResponse response = new MaskWriteRegisterResponse(0, 0x1234, 0xFFFF);

    ByteBuf encoded = encoder.encode(response, Unpooled.buffer());
    MaskWriteRegisterResponse decoded = (MaskWriteRegisterResponse) decoder.decode(encoded);

    assertEquals(response.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(response.getAddress(), decoded.getAddress());
    assertEquals(response.getAndMask(), decoded.getAndMask());
    assertEquals(response.getOrMask(), decoded.getOrMask());
}

From source file:DescriptorTester.java

License:Open Source License

public ByteBuf ACDescriptorTest() {
    ODLCapwapMessage msg = null;/*  w  ww  . j  ava 2s  .c om*/
    DiscoveryType discoveryType = null;
    ACDescriptor acDescriptor = null;

    ByteBuf buf = Unpooled.buffer();
    msg = new ODLCapwapMessage();

    //create  Discovery Type
    discoveryType = new DiscoveryType();
    discoveryType.setDhcp();
    msg.ctrlMsg.addMessageElement(discoveryType);

    //create AcDescriptor element
    acDescriptor = new ACDescriptor();
    acDescriptor.setStations(2).setActiveWtps(2).setLimit(12).setMaxWtps(3).setSecuritySbit().setRmac((byte) 2)
            .setDtlsPolicyDbit();
    //Now create Information Sub Element
    ACInformationSubElement e = new ACInformationSubElement(64);
    byte[] dummy = new byte[64];
    e.setAcInfoVendorId(12);
    e.setAcInfoType(35);
    e.setAcInfoData(dummy);

    acDescriptor.addAcInformationSubElem(e);

    ACInformationSubElement e1 = new ACInformationSubElement(128);
    byte[] dummy1 = new byte[128];
    e1.setAcInfoVendorId(102);
    e1.setAcInfoType(3);
    e1.setAcInfoData(dummy1);
    acDescriptor.addAcInformationSubElem(e1);

    //Add message element to Capwap Message
    msg.ctrlMsg.addMessageElement(acDescriptor);

    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);

    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    return buf;
}