@Override
    protected int onReadPacketHeader( ByteBuffer in )
    {
        if (in.remaining() < HEADER_SIZE)
        {
            return ON_READ_REWIND;
        }

        int magicNumber = in.getInt();
        
        if (magicNumber != protocol.getMagicNumber())
        {
            return ON_READ_CLOSE;
        }
        
        long packetTime = in.getLong();
        long receivedTime = in.getLong();
        int packetSize = in.getInt();
        
        if (in.remaining() < packetSize)
        {
            return ON_READ_REWIND;
        }
        
        pingTime = System.nanoTime() - receivedTime;
        lastReceivedPacketSize = packetSize;
        lastReceivedPacketTime = packetTime;

        return packetSize;
    }