# Scene Equipment Saving and Loading Method for Digital Twin Workshop
## 3 Materials and Methods
### Workshop Scene Equipment Saving and Loading Method
#### 3.2.2 Scene Equipment Saving and Loading Method Implementation  
In the obtaining data stage, the main tasks are to specify the file name and path and assign the data to the temporary object; in the loading data stage, the DT workshop object is rebuilt in the service software, and the workshop state is reset. Figure 4 shows the flowchart for obtaining or loading data. As shown in Figure 4a, after a workshop administrator gives a saving command, the system begins by obtaining the archive name specified by the administrator; if the archive name is not specified, the default name is used. If the archive file already exists, subsequent saving operations will overwrite the existing data in the file. Once the archive file has been created, the multi-threaded task begins. Using multi-threaded asynchronous operations, it can speed up processing and avoid thread blocking, thus improving the performance. Three objects are created to temporarily store saved information. The element object is used to temporarily store information related to the equipment, such as the equipment name, location information, subassembly information, etc. The viewer object is used to temporarily store data, such as viewer position and rotation information, and the info object is used to temporarily store information such as the file name, timestamp, username, etc. Assigning data to the above three kinds of staging objects can help to classify the scattered data into groups and facilitate the serialization of object data into the memory. As shown in Figure 4b, the rebuild operation is performed on the DT workshop object when the saved data are loaded into the memory to be used by the workshop software. After the rebuild is complete, the workshop state is restored, mainly by restoring the workshop script data, initializing the state of each component, etc. Once the above operation has been successfully completed, a signal is broadcast to prompt other modules to destroy the object, free memory and perform other operations. If the operation fails, the error information is reported to the workshop software so that it can be addressed by the workshop administrator. (2) Serialization or deserialization of data  
The temporary objects are processed using serialization and compression functions and subsequently stored in the memory as dynamic arrays; the dynamic arrays in the memory can be deserialized to temporary objects using deserialization and decompression functions. Figure 5 shows the flowchart for serialization or deserialization information. As shown in Figure 5a, when serializing data, first use the pointer to the workshop staging object as the input parameter and determine the legality of the staging object indicated by the pointer to be used for saving operations, including verifying whether the pointer is empty, whether the object has been destroyed, whether the object supports serialization, etc. If the object can be legally used for serialization, it will be serialized into memory. The principle is to create an in-memory archive object that will be used to serialize data into memory. This archive proxy object will take on additional operations for serialization, such as compressing data. The serialization command is given by the archive agent and delegated to the in-memory archive object, which serializes the data in the staging object into a new data segment in memory, waiting for the compression operation. When the data are compressed, no changes are made to the original data in memory, but a new segment is opened in the memory to write the compressed data. The compress manager compresses the data, and the archive system assigns the compressed data contents to write to the newly opened memory segment. As shown in Figure 5b, when deserializing data in the memory data stage, the dynamic array in the memory is first obtained as an input parameter, and the data contained in this array are decompressed. The decompressed data will exist in the newly opened memory space in the form of bytes.