@Test
public void testSerialize() throws Exception {

    PacketParser parser = new HandshakePacket().getParser();
    HandshakePacket.Flags flags = new HandshakePacket.Flags();
    flags.setRegistered(true);
    flags.setHandshakeRequest(true);
    flags.setRequestsReturnService(true);
    byte[] buffer = new byte[] {
            (byte) PACKETS.HANDSHAKE_OPEN.ordinal(), 0,2,4,8,16,32,64,2,4,8,16,32,64,2,4,8,16,32,64,2,4,8,16,32,64,2,4,8,16,32,64,0, flags.toByte()
    };
    HandshakePacket packet = (HandshakePacket) parser.parse(new PacketBuffer().write(buffer), null);
    byte[] bytes = packet.getParser().serialize();
    assertArrayEquals(buffer, bytes);
}