protected static long decodeLength(byte[] input, int off, int len)
			throws IOException {
		int first = input[off] & 0xFF;

		if (len >= 1 && first < 192) {
			return first;
		} else if (len >= 2 && first >= 192 && first <= 223) {
			int second = input[off + 1] & 0xFF;
			return (((first - 192) << 8) | second) + 192;
		} else if (len >= 2 && first == 255) {
			// used long to prevent overflow (unsigned int would be used in c)
			return (((long) (input[off + 1] & 0xFF)) << 24)
					| (((long) (input[off + 2] & 0xFF)) << 16)
					| (((long) (input[off + 3] & 0xFF)) << 8)
					| ((long) (input[off + 4] & 0xFF));
		}

		throw new IOException("Unable to decode packet length");
	}