def varint_encode(num):
    """Convert number into varint bytes

    :param num: number to encode

    """
    buf = b''
    while True:
        towrite = num & 127
        num >>= 7
        if num:
            buf += bytes((towrite | 128,))
        else:
            buf += bytes((towrite,))
            break
    return buf
