private static void encodeHandShakeStart (ByteBuffer buffer, HandShakeStart msg) {
        // Protocol
        buffer.put((byte) msg.getProtocolName().length());
        buffer.put(msg.getProtocolName().getBytes(ISO_8859_1));

        // Reserved Bits
        byte[] bits = new byte[8];
        BitSet flags = msg.getFlags();
        for (int i = 0; i < 64; i++) {
            if (flags.get(i)) {
                int bInd = 7 - (i / 8);
                int bMask = 1 << (i % 8);
                bits[bInd] |= bMask;
            }
        }
        buffer.put(bits);

        // Hash
        buffer.put(msg.getHash().getBytes());
    }