from typing import Tuple


def decodeUleb128(buffer: bytes, readHead: int) -> Tuple[int, int]:
	"""Read a Uleb128 value.

	Args:
		buffer: The data source.
		readHead: The initial offset to read from.

	Returns:
		A tuple containing the result and the new read head.
	"""

	value = 0
	shift = 0

	while True:
		if readHead >= len(buffer):
			raise Exception("Uleb extends beyond buffer")

		byte = buffer[readHead]

		value |= (byte & 0x7f) << shift

		readHead += 1
		shift += 7

		if (byte & 0x80) == 0:
			break

	return (value, readHead)