def unsigned_leb128_encode(value: int) -> bytes:
    """Encode number as into unsigned leb128 encoding

    .. doctest::

        >>> from ppci.utils.leb128 import unsigned_leb128_encode
        >>> unsigned_leb128_encode(42)
        b'*'
    """
    if not isinstance(value, int):
        raise TypeError("Expected int but got {}".format(type(value)))

    if value < 0:
        raise ValueError("Cannot encode negative number as unsigned leb128")

    data = []  # ints, really
    while True:
        byte = value & 0x7F
        value >>= 7
        if value == 0:
            # We are done!
            data.append(byte)
            break
        else:
            data.append(byte | 0x80)  # Append data and continuation marker
    return bytes(data)