def read_var_int(handle):
    """
	Read a variable-length integer from the given file handle.
	"""
    res = 0
    shift = 1
    while True:
        byte = handle.read(1)[0]
        res += (byte & 127) * shift
        if byte & 128:
            break
        shift <<= 7
        res += shift
    return res
