public static byte[] encode(byte[] message) {
		int length = message.length - 1;
		byte[] len;

		if (length < 128) {
			len = new byte[] { (byte) length };
		} else {
			int count = 0;

			while (32 << (count + 1 << 3) <= length) {
				count++;
			}

			count++;
			len = new byte[count + 1];
			len[0] = (byte) (count << 5 | 0x80 | length & 0x1F);

			for (int i = 1; i < len.length; i++) {
				len[i] = (byte) (length >>> 8 * (i - 1) + 5);
			}
		}

		byte[] buffer = new byte[len.length + message.length];
		System.arraycopy(len, 0, buffer, 0, len.length);
		System.arraycopy(message, 0, buffer, len.length, message.length);
		return buffer;
	}