Example usage for io.netty.buffer Unpooled wrappedBuffer

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

Introduction

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

Prototype

public static ByteBuf wrappedBuffer(ByteBuffer... buffers) 

Source Link

Document

Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them.

Usage

From source file:com.whizzosoftware.wzwave.frame.NodeProtocolInfoTest.java

License:Open Source License

@Test
public void testResponseConstructor() {
    byte[] b = new byte[] { 0x01, 0x09, 0x01, 0x41, (byte) 0x92, 0x16, 0x00, 0x02, 0x02, 0x01, 0x33 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    NodeProtocolInfo npi = new NodeProtocolInfo(buffer);
    assertEquals(1, buffer.readableBytes());
    assertTrue(npi.isListening());/*  w  w  w .ja  va2s.c  o  m*/
    assertTrue(npi.isBeaming());
    assertFalse(npi.isRouting());
    assertEquals(40000, npi.getMaxBaudRate());
    assertEquals(3, npi.getVersion());
    assertFalse(npi.hasSecurity());
    assertEquals(0x02, npi.getBasicDeviceClass());
    assertEquals(0x02, npi.getGenericDeviceClass());
    assertEquals(0x01, npi.getSpecificDeviceClass());
}

From source file:com.whizzosoftware.wzwave.frame.RequestNodeInfoTest.java

License:Open Source License

@Test
public void testResponseConstructor() {
    byte[] b = new byte[] { 0x01, 0x04, 0x01, 0x60, 0x01, (byte) 0x9B };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    RequestNodeInfo rni = new RequestNodeInfo(buffer);
    assertEquals(1, buffer.readableBytes());
    assertNotNull(rni.getRetVal());/*from   w w  w.ja v  a 2 s. com*/
    assertEquals((byte) 0x01, (byte) rni.getRetVal());
    assertTrue(rni.wasSuccessfullySent());
    assertEquals(1, buffer.readableBytes());
}

From source file:com.whizzosoftware.wzwave.frame.SendDataTest.java

License:Open Source License

@Test
public void testMessageByteArrayConstructorWithRequest() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x25, 0x02, 0x05, 0x08, -45 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    SendData sd = new SendData(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(DataFrameType.REQUEST, sd.getType());
    assertFalse(sd.hasRetVal());//from w w  w.  j a v a2s .co m
    assertEquals((byte) 0x06, sd.getNodeId());
    assertTrue(sd.hasCallbackId());
    assertEquals((byte) 0x08, (byte) sd.getCallbackId());
}

From source file:com.whizzosoftware.wzwave.frame.SendDataTest.java

License:Open Source License

@Test
public void testMessageByteArrayConstructorWithRetval() {
    byte[] b = new byte[] { 0x01, 0x04, 0x01, 0x13, 0x01, (byte) 0xE8 };
    ByteBuf buffer = Unpooled.wrappedBuffer(b);
    SendData sd = new SendData(buffer);
    assertEquals(1, buffer.readableBytes());
    assertEquals(DataFrameType.RESPONSE, sd.getType());
    assertTrue(sd.hasRetVal());/*from w  w  w  .  j  a  va  2  s . co m*/
    assertEquals((byte) 0x01, (byte) sd.getRetVal());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithExpectedResponse() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x25, 0x02, 0x05, 0x08, -45 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);
    assertFalse(t.isComplete());// w  w w . j  a v  a2 s.  c o m
    assertTrue(t.shouldRetry());

    assertTrue(t.addFrame(new ACK()));
    assertFalse(t.isComplete());
    assertFalse(t.hasError());
    assertTrue(t.shouldRetry());

    b = new byte[] { 0x01, 0x04, 0x01, 0x13, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());
    assertFalse(t.hasError());
    assertTrue(t.shouldRetry());

    b = new byte[] { 0x01, 0x05, 0x00, 0x13, 0x00, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());
    assertFalse(t.hasError());
    assertTrue(t.shouldRetry());

    assertTrue(t.addFrame(
            new ApplicationCommand(DataFrameType.RESPONSE, (byte) 0x00, (byte) 0x01, new byte[] { 0x00 })));
    assertTrue(t.isComplete());
    assertFalse(t.hasError());
    assertTrue(t.shouldRetry());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithoutExpectedResponse() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x25, 0x02, 0x05, 0x08, -45 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);
    assertFalse(t.isComplete());//  w  ww  .j a va2  s .c o m

    assertTrue(t.addFrame(new ACK()));
    assertFalse(t.isComplete());

    b = new byte[] { 0x01, 0x04, 0x01, 0x13, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());

    b = new byte[] { 0x01, 0x05, 0x00, 0x13, 0x00, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());
    assertTrue(t.shouldRetry());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithCANBeforeACK() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x2E, 0x02, 0x25, 0x02, 0x05, 0x4A, (byte) 0xA1 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);

    // receive CAN
    assertTrue(t.addFrame(new CAN()));
    assertTrue(t.isComplete());//from   w  w w .j  av a  2  s  .co  m
    assertTrue(t.hasError());
    assertTrue(t.shouldRetry());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithCANAfterACK() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x2E, 0x02, 0x25, 0x02, 0x05, 0x4A, (byte) 0xA1 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);

    // receive ACK
    assertTrue(t.addFrame(new ACK()));
    assertFalse(t.isComplete());/*from  ww w . jav a2  s . co m*/
    assertFalse(t.hasError());

    // receive CAN
    assertTrue(t.addFrame(new CAN()));
    assertTrue(t.isComplete());
    assertTrue(t.hasError());
    assertTrue(t.shouldRetry());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithCANAfterResponse() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x2E, 0x02, 0x25, 0x02, 0x05, 0x4A, (byte) 0xA1 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);

    // receive ACK
    assertTrue(t.addFrame(new ACK()));
    assertFalse(t.isComplete());/*from w  w w  . jav a  2s .co m*/
    assertFalse(t.hasError());

    // receive response
    b = new byte[] { 0x01, 0x04, 0x01, 0x13, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());

    // receive CAN
    assertTrue(t.addFrame(new CAN()));
    assertTrue(t.isComplete());
    assertTrue(t.hasError());
    assertTrue(t.shouldRetry());
}

From source file:com.whizzosoftware.wzwave.frame.transaction.SendDataTransactionTest.java

License:Open Source License

@Test
public void testTransactionWithCANAfterRequest() {
    byte[] b = new byte[] { 0x01, 0x09, 0x00, 0x13, 0x2E, 0x02, 0x25, 0x02, 0x05, 0x4A, (byte) 0xA1 };
    SendData startFrame = new SendData(Unpooled.wrappedBuffer(b));
    SendDataTransaction t = new SendDataTransaction(startFrame, true, true);

    // receive ACK
    assertTrue(t.addFrame(new ACK()));
    assertFalse(t.isComplete());//  w w w.j  av a2  s .  c  om
    assertFalse(t.hasError());

    // receive response
    b = new byte[] { 0x01, 0x04, 0x01, 0x13, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());

    b = new byte[] { 0x01, 0x05, 0x00, 0x13, 0x00, 0x00, -45 };
    assertTrue(t.addFrame(new SendData(Unpooled.wrappedBuffer(b))));
    assertFalse(t.isComplete());
    assertFalse(t.hasError());

    // receive CAN
    assertTrue(t.addFrame(new CAN()));
    assertTrue(t.isComplete());
    assertTrue(t.hasError());
    assertTrue(t.shouldRetry());
}