def varintdecode(data):
    """Varint decoding."""
    shift = 0
    result = 0
    for c in data:
        b = ord(c)
        result |= (b & 127) << shift
        if not b & 128:
            break
        shift += 7
    return result
