Package be.demmel.jgws.packets.serialization.reflection

Examples of be.demmel.jgws.packets.serialization.reflection.ReflectionPacketSerializer$SerializeAction


      int header = extractHeader(packetClass);

      PacketSerializer packetSerializer = packetSerializers.get(packetClass);

      if (packetSerializer == null) {
        packetSerializer = new ReflectionPacketSerializer(header, packetClass);
        packetSerializers.put(packetClass, packetSerializer);
      } else {
        LOGGER.error("Duplicate packet (header {})", header);
      }
    }
View Full Code Here


public class ReflectionPacketSerializerTest {

    @Test
    public void serializesCorrectly() throws IOException, Exception {
        // create a new serializer
        ReflectionPacketSerializer packetSerializer = new ReflectionPacketSerializer(8, P008_TestPacket.class);

        // create a new empty TestIncomingPacket
        P008_TestPacket testIncomingPacket = new P008_TestPacket();
        testIncomingPacket.setUnsignedInteger1(1);
        testIncomingPacket.setUnsignedInteger2(2);
        testIncomingPacket.setUnsignedShort1(3);
        testIncomingPacket.setConstantUnsignedByteArray1(new short[]{20});
        testIncomingPacket.setConstantUnsignedByteArray2(new short[]{21, 22});
        testIncomingPacket.setConstantUnsignedByteArray3(new short[]{23, 24, 25});
        testIncomingPacket.setString1("toto");
        testIncomingPacket.setUnsignedShort2(4);
        testIncomingPacket.setConstantUnsignedByteArray4(new short[]{26, 27, 28, 29});
        testIncomingPacket.setUnsignedInteger3(5);
        testIncomingPacket.setVariableUnsignedByteArray1(new short[]{30, 31, 32, 33, 34});
        testIncomingPacket.setUnsignedByte1((short) 6);
        testIncomingPacket.setUnsignedInteger4(7);
        testIncomingPacket.setString2("titi");

        // build the buffer that will contain all the correct output data inserted manually
        ByteBuf neededOutputBytes = Unpooled.buffer(65);
        neededOutputBytes = neededOutputBytes.order(ByteOrder.LITTLE_ENDIAN);

        String output = "8 0 1 0 0 0 2 0 0 0 3 0 20 21 22 23 24 25 4 0 116 0 111 0 116 0 111 0 4 0 26 27 28 29 5 0 0 0 5 0 30 31 32 33 34 6 7 0 0 0 4 0 116 0 105 0 116 0 105 0";
        String[] bytes = output.split("\\s");
        for (String byteString : bytes) {
            neededOutputBytes.writeByte(Byte.parseByte(byteString));
        }
       
        // build the buffer that will contain all the generated output data
        ByteBuf generatedOutputBytes = Unpooled.buffer(65);
        generatedOutputBytes = generatedOutputBytes.order(ByteOrder.LITTLE_ENDIAN);
        // serialize the given packet
        packetSerializer.serialize(testIncomingPacket, generatedOutputBytes);

        // compare the size of each bufffer
        assertEquals(neededOutputBytes.writerIndex(), generatedOutputBytes.writerIndex());
       
        int writerIndex = generatedOutputBytes.writerIndex();
View Full Code Here

TOP

Related Classes of be.demmel.jgws.packets.serialization.reflection.ReflectionPacketSerializer$SerializeAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.