def unpack_varint(data, pointer=0):
    """
    Unpacks a variable length integer.
    """
    integer, shift = 0, 0
    while True:
        integer |= (data[pointer] & 127) << shift
        if not data[pointer] & 128:
            break
        pointer += 1
        shift += 7
    return pointer + 1, integer
