def decode(raw: bytes):
    """Read a varint from `raw` bytes, return the remainder"""
    if raw is None or len(raw) == 0:
        return 0
    result = 0
    data = raw
    while True:
        i, data = ord(data[:1]), data[1:]
        result = result << 7
        result += i & 127
        if i < 128:
            break
    return result, data
