def text_to_bytes(text, encoding='UTF-8', size=None):
    """
    Encode some text or string to a byte array
    :param text: text to encode to bytes
    :param encoding: optional encoding of the passed string. default to utf-8.
    :param size: optional, if given the text will be padded with 0x00 to the right size
    :return: a bytes object
    """
    res = str(text).encode(encoding)
    if size:
        res = res.rjust(size, b'\x00')
    return res