use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.
the class EncoderEventPacketTest method testEncode.
@Test
public void testEncode() throws IOException {
Packet packet = new Packet(PacketType.EVENT);
packet.setName("woot");
ByteBuf result = Unpooled.buffer();
// encoder.encodePacket(packet, result);
Assert.assertEquals("5:::{\"name\":\"woot\"}", result.toString(CharsetUtil.UTF_8));
}
use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.
the class EncoderEventPacketTest method testEncodeWithMessageIdAndAck.
@Test
public void testEncodeWithMessageIdAndAck() throws IOException {
Packet packet = new Packet(PacketType.EVENT);
// packet.setId(1L);
// packet.setAck(Packet.ACK_DATA);
packet.setName("tobi");
ByteBuf result = Unpooled.buffer();
// encoder.encodePacket(packet, result);
Assert.assertEquals("5:1+::{\"name\":\"tobi\"}", result.toString(CharsetUtil.UTF_8));
}
use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.
the class EncoderEventPacketTest method testEncodeWithData.
@Test
public void testEncodeWithData() throws IOException {
Packet packet = new Packet(PacketType.EVENT);
packet.setName("edwald");
// packet.setArgs(Arrays.asList(Collections.singletonMap("a", "b"), 2, "3"));
ByteBuf result = Unpooled.buffer();
// encoder.encodePacket(packet, result);
Assert.assertEquals("5:::{\"name\":\"edwald\",\"args\":[{\"a\":\"b\"},2,\"3\"]}", result.toString(CharsetUtil.UTF_8));
}
use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.
the class PayloadTest method testDecodingNewline.
@Test
public void testDecodingNewline() throws IOException {
Packet packet = decoder.decodePacket("3:::\n", null);
Assert.assertEquals(PacketType.MESSAGE, packet.getType());
Assert.assertEquals("\n", packet.getData());
}
use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.
the class PayloadTest method testPayloadDecode.
@Test
public void testPayloadDecode() throws IOException {
ByteBuf buffer = Unpooled.wrappedBuffer("�5�3:::5�7�3:::53d�3�0::".getBytes());
List<Packet> payload = new ArrayList<Packet>();
while (buffer.isReadable()) {
Packet packet = decoder.decodePackets(buffer, null);
payload.add(packet);
}
Assert.assertEquals(3, payload.size());
Packet msg1 = payload.get(0);
Assert.assertEquals(PacketType.MESSAGE, msg1.getType());
Assert.assertEquals("5", msg1.getData());
Packet msg2 = payload.get(1);
Assert.assertEquals(PacketType.MESSAGE, msg2.getType());
Assert.assertEquals("53d", msg2.getData());
Packet msg3 = payload.get(2);
Assert.assertEquals(PacketType.DISCONNECT, msg3.getType());
}
Aggregations