def writeUVARI(v, theS):
    """Side effects s by writing v (an integer) to s using UVARI (big-endian)
    format. theS must have write(bytes) implemented."""
    by = bytearray()
    l = 0
    if v > 127:
        if v > 16383:
            l = 4
            by.append(192 | v >> 24 & 63)
            by.append(v >> 16 & 255)
            by.append(v >> 8 & 255)
            by.append(v & 255)
        else:
            l = 2
            by.append(128 | v >> 8 & 127)
            by.append(v & 255)
    else:
        l = 1
        by.append(v & 127)
    theS.write(by)
