List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:com.cloudhopper.smpp.util.ChannelBufferUtilTest.java
License:Apache License
@Test public void writeAddress() throws Exception { Address addr0 = null;//from w w w .j av a 2 s . co m ByteBuf buffer0 = null; buffer0 = Unpooled.buffer().capacity(10); // handle null case buffer0.clear(); ChannelBufferUtil.writeAddress(buffer0, addr0); Assert.assertArrayEquals(HexUtil.toByteArray("000000"), BufferHelper.createByteArray(buffer0)); // handle default address buffer0.clear(); ChannelBufferUtil.writeAddress(buffer0, new Address()); Assert.assertArrayEquals(HexUtil.toByteArray("000000"), BufferHelper.createByteArray(buffer0)); // handle some stuff in address buffer0.clear(); ChannelBufferUtil.writeAddress(buffer0, new Address((byte) 0x01, (byte) 0x02, "")); Assert.assertArrayEquals(HexUtil.toByteArray("010200"), BufferHelper.createByteArray(buffer0)); buffer0.clear(); ChannelBufferUtil.writeAddress(buffer0, new Address((byte) 0x01, (byte) 0x02, "ABC")); Assert.assertArrayEquals(HexUtil.toByteArray("010241424300"), BufferHelper.createByteArray(buffer0)); }
From source file:com.comphenix.protocol.compat.netty.independent.IndependentNetty.java
License:Open Source License
@Override public WrappedByteBuf buffer() { return new NettyByteBuf(Unpooled.buffer()); }
From source file:com.comphenix.protocol.injector.netty.WirePacket.java
License:Open Source License
/** * Serializes this packet into a byte buffer * @return The buffer */ public ByteBuf serialize() { ByteBuf buffer = Unpooled.buffer(); writeFully(buffer); return buffer; }
From source file:com.corundumstudio.socketio.handler.PacketHandlerTest.java
License:Apache License
private void testHandler(PacketHandler handler, Queue<Packet> packets) throws Exception { int size = packets.size(); ByteBuf buffer = Unpooled.buffer(); encoder.encodePackets(packets, buffer, UnpooledByteBufAllocator.DEFAULT); handler.channelRead0(null, new PacketsMessage(client, buffer)); Assert.assertEquals(size, invocations.get()); }
From source file:com.corundumstudio.socketio.parser.EncoderAckPacketTest.java
License:Apache License
@Test public void testEncode() throws IOException { Packet packet = new Packet(PacketType.ACK); packet.setAckId(140L);// w w w . j ava 2s . c om ByteBuf result = Unpooled.buffer(); // encoder.encodePacket(packet, result); Assert.assertEquals("6:::140", result.toString(CharsetUtil.UTF_8)); }
From source file:com.corundumstudio.socketio.parser.EncoderAckPacketTest.java
License:Apache License
@Test public void testEncodeWithArgs() throws IOException { Packet packet = new Packet(PacketType.ACK); packet.setAckId(12L);/*w ww . ja v a 2 s .c o m*/ // packet.setArgs(Arrays.<Object>asList("woot", "wa")); ByteBuf result = Unpooled.buffer(); // encoder.encodePacket(packet, result); Assert.assertEquals("6:::12+[\"woot\",\"wa\"]", result.toString(CharsetUtil.UTF_8)); }
From source file:com.corundumstudio.socketio.parser.EncoderConnectionPacketTest.java
License:Apache License
@Test public void testEncodeDisconnection() throws IOException { Packet packet = new Packet(PacketType.DISCONNECT); packet.setNsp("/woot"); ByteBuf result = Unpooled.buffer(); // encoder.encodePacket(packet, result); Assert.assertEquals("0::/woot", result.toString(CharsetUtil.UTF_8)); }
From source file:com.corundumstudio.socketio.parser.EncoderConnectionPacketTest.java
License:Apache License
@Test public void testEncode() throws IOException { Packet packet = new Packet(PacketType.CONNECT); packet.setNsp("/tobi"); ByteBuf result = Unpooled.buffer(); // encoder.encodePacket(packet, result); Assert.assertEquals("1::/tobi", result.toString(CharsetUtil.UTF_8)); }
From source file:com.corundumstudio.socketio.parser.EncoderConnectionPacketTest.java
License:Apache License
@Test public void testEncodePacketWithQueryString() throws IOException { Packet packet = new Packet(PacketType.CONNECT); packet.setNsp("/test"); // packet.setQs("?test=1"); ByteBuf result = Unpooled.buffer(); // encoder.encodePacket(packet, result); Assert.assertEquals("1::/test:?test=1", result.toString(CharsetUtil.UTF_8)); }
From source file:com.corundumstudio.socketio.parser.EncoderErrorPacketTest.java
License:Apache License
@Test public void testEncode() throws IOException { Packet packet = new Packet(PacketType.ERROR); ByteBuf result = Unpooled.buffer(); encoder.encodePacket(packet, result); Assert.assertEquals("7::", result.toString(CharsetUtil.UTF_8)); }