public static HandShakeStart decodeHandShakeStartFromBuffer (ByteBuffer buffer) {
        // Protocol name
        int pNameLen = (buffer.get()) & 0xFF;

        byte[] pNameBytes = new byte[pNameLen];
        buffer.get(pNameBytes);

        String pName = new String(pNameBytes, ISO_8859_1);

        // Reserved bits
        byte[] resBitsArr = new byte[8];
        buffer.get(resBitsArr);
        BitSet flags = new BitSet();
        for (int i = 0; i < 64; i++) {
            int bInd = 7 - (i / 8);
            int bMask = 1 << (i % 8);
            if ((resBitsArr[bInd] & bMask) != 0) {
                flags.set(i);
            }
        }

        // Hash
        byte[] hashBytes = new byte[20];
        buffer.get(hashBytes);
        Sha1Hash hash = new Sha1Hash(hashBytes);

        // Return
        return new HandShakeStart(pName, flags, hash);
    }