def encode(data):
    """
    Encode string to byte in utf-8
    :param data: Byte or str
    :return: Encoded byte data
    :raises: TypeError
    """
    if isinstance(data, bytes):
        return data
    elif isinstance(data, str):
        return str.encode(data)
    else:
        return bytes(data)