<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_direct(self, target, var_id, var_type, data):
 """Directly add a config variable. This method is meant to be called from emulation scenarios that want to directly set config database entries from python. Args: target (SlotIdentifer):
 The target slot for this config variable. var_id (int):
 The config variable ID var_type (str):
 The config variable type data (bytes or int or str):
 The data that will be encoded according to var_type. """


        data = struct.pack("<H", var_id) + _convert_to_bytes(var_type, data)

        if self.data_size - self.data_index < len(data):
            raise DataError("Not enough space for data in new conig entry", needed_space=len(data), actual_space=(self.data_size - self.data_index))

        new_entry = ConfigEntry(target, var_id, data)

        for entry in self.entries:
            if entry.target == new_entry.target and entry.var_id == new_entry.var_id:
                entry.valid = False

        self.entries.append(new_entry)
        self.data_index += new_entry.data_space()