List of usage examples for io.netty.buffer Unpooled copiedBuffer
public static ByteBuf copiedBuffer(ByteBuffer... buffers)
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameDecoderTest.java
License:Open Source License
@Test public void testLoopResponse() throws Exception { VantageSerialFrameDecoder d = new VantageSerialFrameDecoder(); ByteBuf buf = Unpooled.copiedBuffer(new byte[] { 0x4c, 0x4f, 0x4f, 0x00, 0x01, (byte) 0xff, 0x7f, (byte) 0x88, 0x74, (byte) 0xbd, 0x02, 0x15, (byte) 0xb5, 0x01, 0x01, (byte) 0xff, (byte) 0xfa, 0x00, 0x11, 0x00, 0x13, 0x00, 0x04, 0x00, 0x0e, 0x01, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, 0x12, 0x00, (byte) 0xff, 0x23, (byte) 0xff, 0x2a, 0x00, 0x2b, 0x00, (byte) 0xff, 0x7f, 0x00, 0x00, (byte) 0xff, (byte) 0xff, 0x7f, 0x00, 0x00, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, (byte) 0xe5, (byte) 0xff, 0x7c, 0x5c, 0x7c, 0x5c, (byte) 0x8a, 0x74, (byte) 0xff, 0x02, 0x07, 0x0c, 0x13, 0x05, 0x11, 0x0e, 0x20, 0x0c, 0x04, 0x04, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, 0x10, 0x13, (byte) 0x8c, (byte) 0xe2 }); List<Object> l = new ArrayList<>(); d.decode(null, buf, l);/* w ww . ja v a2 s .c o m*/ assertEquals(1, l.size()); assertTrue(l.get(0) instanceof LoopResponse); LoopResponse lr = (LoopResponse) l.get(0); assertEquals(437.0, lr.getOutsideTemp(), 0); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameDecoderTest.java
License:Open Source License
@Test public void testSegmentedLoopResponse() throws Exception { VantageSerialFrameDecoder d = new VantageSerialFrameDecoder(); ByteBuf buf1 = Unpooled.copiedBuffer(new byte[] { 0x4c, 0x4f, 0x4f, 0x00, 0x01, (byte) 0xff, 0x7f, (byte) 0x88, 0x74, (byte) 0xbd, 0x02, 0x15, (byte) 0xb5, 0x01, 0x01, (byte) 0xff, (byte) 0xfa, 0x00, 0x11, 0x00, 0x13, 0x00, 0x04, 0x00, 0x0e, 0x01, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, 0x12, 0x00, (byte) 0xff, 0x23, (byte) 0xff, 0x2a, 0x00, 0x2b, 0x00, (byte) 0xff, 0x7f, 0x00, 0x00, (byte) 0xff, (byte) 0xff, 0x7f, 0x00, 0x00, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, (byte) 0xe5, (byte) 0xff, 0x7c, 0x5c, 0x7c, 0x5c, (byte) 0x8a, 0x74, (byte) 0xff, 0x02, 0x07, 0x0c, 0x13, 0x05, 0x11, 0x0e }); ByteBuf buf2 = Unpooled.copiedBuffer(new byte[] { 0x20, 0x0c, 0x04, 0x04, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, (byte) 0xff, 0x7f, 0x10, 0x13, (byte) 0x8c, (byte) 0xe2 }); List<Object> l = new ArrayList<>(); d.decode(null, buf1, l);//from w w w.j a v a 2 s . c o m assertEquals(0, l.size()); d.decode(null, Unpooled.copiedBuffer(buf1, buf2), l); assertEquals(1, l.size()); assertTrue(l.get(0) instanceof LoopResponse); LoopResponse lr = (LoopResponse) l.get(0); assertEquals(437.0, lr.getOutsideTemp(), 0); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameDecoderTest.java
License:Open Source License
@Test public void testVersionResponse() throws Exception { VantageSerialFrameDecoder d = new VantageSerialFrameDecoder(); ByteBuf buf = Unpooled.copiedBuffer( new byte[] { 0x4D, 0x61, 0x79, 0x20, 0x20, 0x31, 0x20, 0x32, 0x30, 0x31, 0x32, 10, 13 }); List<Object> l = new ArrayList<>(); d.decode(null, buf, l);//from w w w.j a v a 2s . c o m assertEquals(1, l.size()); assertTrue(l.get(0) instanceof VersionResponse); assertEquals("May 1 2012", ((VersionResponse) l.get(0)).getValue()); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameDecoderTest.java
License:Open Source License
@Test public void testTestResponse() throws Exception { VantageSerialFrameDecoder d = new VantageSerialFrameDecoder(); ByteBuf buf = Unpooled.copiedBuffer(new byte[] { 'T', 'E', 'S', 'T', 10, 13 }); List<Object> l = new ArrayList<>(); d.decode(null, buf, l);// www .jav a2 s . co m assertEquals(1, l.size()); assertTrue(l.get(0) instanceof com.whizzosoftware.hobson.davisvantage.api.command.Test); }
From source file:com.whizzosoftware.hobson.mysensors.protocol.MySensorsDecoderTest.java
License:Open Source License
@Test public void testMessageWithPayload() throws Exception { List<Object> out = new ArrayList<>(); MySensorsDecoder decoder = new MySensorsDecoder(); decoder.decode(null, Unpooled.copiedBuffer("255;255;3;0;3;payload".getBytes()), out); assertEquals(1, out.size());//www . j a v a 2 s .c o m MySensorsMessage m = (MySensorsMessage) out.get(0); assertEquals(255, m.getNodeId()); assertEquals(255, m.getChildSensorId()); assertEquals(3, m.getCommand()); assertFalse(m.isAck()); assertEquals(3, m.getType()); assertEquals("payload", m.getPayload()); }
From source file:com.whizzosoftware.hobson.mysensors.protocol.MySensorsDecoderTest.java
License:Open Source License
@Test public void testMessageWithoutPayload() throws Exception { List<Object> out = new ArrayList<>(); MySensorsDecoder decoder = new MySensorsDecoder(); decoder.decode(null, Unpooled.copiedBuffer("255;255;3;0;3;".getBytes()), out); assertEquals(1, out.size());//ww w.j a v a 2 s.com MySensorsMessage m = (MySensorsMessage) out.get(0); assertEquals(255, m.getNodeId()); assertEquals(255, m.getChildSensorId()); assertEquals(3, m.getCommand()); assertFalse(m.isAck()); assertEquals(3, m.getType()); assertNull(m.getPayload()); }
From source file:com.whizzosoftware.hobson.mysensors.protocol.MySensorsDecoderTest.java
License:Open Source License
@Test public void testInvalidMessage() throws Exception { List<Object> out = new ArrayList<>(); MySensorsDecoder decoder = new MySensorsDecoder(); decoder.decode(null, Unpooled.copiedBuffer("0;255;3;0;9".getBytes()), out); }
From source file:com.whizzosoftware.hobson.ssdp.SSDPPlugin.java
License:Open Source License
public void sendDiscoveryPacket() { try {/*w ww . j ava 2 s .co m*/ if (localChannel != null) { logger.debug("Sending SSDP discovery packet"); byte[] disco = SSDPPacket.createSearchRequest().toString().getBytes(); ByteBuf buf = Unpooled.copiedBuffer(disco); localChannel.writeAndFlush(new DatagramPacket(buf, groupAddress, localAddress)).sync(); } } catch (Throwable e) { e.printStackTrace(); } }
From source file:com.whizzosoftware.hobson.ssdp.SSDPPlugin.java
License:Open Source License
public void sendDiscoveryResponse(InetSocketAddress address, DeviceAdvertisement da) throws IOException { try {/*from ww w. ja v a2 s. c om*/ if (localChannel != null) { String data = SSDPPacket.createSearchResponse(da.getUri(), da.getId(), "urn").toString(); logger.trace("Sending SSDP search response to {}: {}", address, data); ByteBuf buf = Unpooled.copiedBuffer(data.getBytes()); localChannel.writeAndFlush(new DatagramPacket(buf, address, localAddress)).sync(); } } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.wx3.galacdecks.networking.HttpHandler.java
License:Open Source License
private void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, String text) { ByteBuf content = Unpooled.copiedBuffer(text.getBytes()); FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content); res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); HttpHeaders.setContentLength(res, content.readableBytes()); sendHttpResponse(ctx, req, res);/*from www.j a v a 2 s .c om*/ }