Serialization and deserialization methods and devices, equipment and readable storage medium
By introducing serialization and deserialization methods in the Hongmeng system, and using type factory generation adapters to process data, the problem of high complexity of cross-device and cross-process data transmission is solved, and the consistency of data format and transmission efficiency are improved.
Patent Information
- Application Number
- CN202411808759.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-21
AI Technical Summary
The Hongmeng system is more complex when cross-device data transmission or cross-process data transmission, and the existing technology is difficult to effectively solve the problem of inconsistent data formats.
By introducing serialization and deserialization methods, the data is processed using a type factory generation adapter to realize unified format conversion of data. The specific steps include obtaining type factory and memory data, parsing and extracting operation elements, generating adapters for data structure judgment and serialization adjustment, and finally forming serialized characters.
It realizes the convenience and efficiency of cross-device and cross-process data transmission, ensures the consistency of data formats, reduces development problems, and improves the security and efficiency of data transmission.
Smart Images

Figure CN119669128A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and more specifically, to a serialization and deserialization method, apparatus, device, and readable storage medium. Background Art
[0002] Hongmeng OS aims to build a smart world where everything is connected, and realize the interconnection of smart phones, tablets, smart wearable devices, smart home products, etc. However, there are many differences in functions, performance, and hardware architecture among these devices, which makes Hongmeng OS more complicated when performing cross-device data transmission or cross-process data transmission.
[0003] Serialization can convert complex data objects generated by different applications or different devices into a unified and standard format, helping complex data to circulate among different devices. Deserialization, on the other hand, corresponds to serialization and plays a key role in restoring the original appearance of data, helping devices store received complex data.
[0004] Therefore, in order to solve the problem of cross-device data transmission in the Hongmeng system, we can try to introduce serialization means in each of the above-mentioned devices to process device data, so as to facilitate cross-device data transmission and cross-process data transmission. Correspondingly, we can also try to introduce deserialization means in each device to process the received serialized data, so as to facilitate the device to persistently store the received data. On this basis, how to introduce serialization and deserialization means in the Hongmeng system has become the focus of technical personnel in this field. Summary of the invention
[0005] In view of this, the present application provides a serialization and deserialization method, apparatus, device and readable storage medium for introducing serialization means and deserialization means in the Hongmeng system.
[0006] In order to achieve the above objectives, the proposed solution is as follows:
[0007] A serialization method, comprising:
[0008] Get the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized;
[0009] Parse the Hongmeng memory data and extract operation elements;
[0010] Determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory;
[0011] Using the target adapter, generating a target key value matching the operation element, and assigning a value to the target key value based on the operation element to obtain a preliminary serialization result;
[0012] Determining whether the target adapter corresponds to a preset basic adapter;
[0013] If not, the preliminary serialization result is disassembled to obtain a disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned to execute, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element;
[0014] If yes, each preliminary serialization result is encrypted and combined to form a serialized character.
[0015] Optionally, determining the data structure type of the operation element, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element, includes:
[0016] When it is determined that the data structure type of the operation element belongs to the object type, using the type factory, an object adapter is generated as a target adapter matching the operation element;
[0017] Using the target adapter, generating a target key value matching the operation element, and assigning the target key value based on the operation element to obtain a preliminary serialization result, including:
[0018] Using the target adapter, create a target object that matches the operation element and contains multiple target key values;
[0019] The target adapter is used to traverse the operation elements, determine multiple sub-item values from the operation elements, map and distribute each sub-item value to each target key value, and the distributed target object is the preliminary serialization result.
[0020] Optionally, determining the data structure type of the operation element, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element, includes:
[0021] When it is determined that the data structure type of the operation element belongs to the list type, using the type factory, a list adapter is generated as a target adapter matching the operation element;
[0022] Using the target adapter, generating a target key value matching the operation element, and assigning the target key value based on the operation element to obtain a preliminary serialization result, including:
[0023] Using the target adapter, converting the operation element into an array object;
[0024] The array adapter is called to generate array key values matching the array object, and the parameter value corresponding to each array key value is determined based on the array object to generate a preliminary serialization result.
[0025] A serialization device, comprising:
[0026] The Hongmeng memory data acquisition module is used to obtain the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized;
[0027] An operation element reading module, used to parse the Hongmeng memory data and extract operation elements;
[0028] A target adapter generation module, used to determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory;
[0029] An operation element transformation module, used to generate a target key value matching the operation element by using the target adapter, and assign a value to the target key value based on the operation element to obtain a preliminary serialization result;
[0030] A serialization character generation module is used to determine whether the target adapter corresponds to a preset basic adapter; if so, the serialization character acquisition module is called; if not, the preliminary serialization result disassembly module is called;
[0031] A preliminary serialization result disassembly module is used to disassemble the preliminary serialization result to obtain a disassembly result, extract new operation elements from the disassembly result, and call the target adapter generation module;
[0032] The serialized character acquisition module is used to encrypt and combine various preliminary serialization results to form serialized characters.
[0033] A deserialization method, comprising:
[0034] Get the Hongmeng serialized data that needs to be deserialized, as well as the type factory used to generate different types of adapters;
[0035] Decrypt and parse the Hongmeng serialized data to generate an operation subject;
[0036] Determine the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory;
[0037] Utilizing the target adapter, extracting parameter values from the operation subject, and determining whether the extracted parameter values belong to an object type;
[0038] If yes, the parameter value belonging to the object type is used as a new operation subject, and the step of using the type factory to generate a target adapter matching the operation subject based on the data structure type of the operation subject is returned to be executed;
[0039] If not, the parameter value that does not belong to the object type is deserialized to generate a preliminary deserialization result, and each preliminary deserialization result is combined to form a deserialization character.
[0040] Optionally, extracting parameter values from the operation subject using the target adapter includes:
[0041] When the target adapter is an object adapter, the object adapter is used to traverse all target key values of the operation subject, and a corresponding parameter value is extracted from each target key value.
[0042] Optionally, extracting parameter values from the operation subject using the target adapter includes:
[0043] When the target adapter is an array adapter, the array adapter is used and the operation subject is used as a parameter value.
[0044] A deserialization device, comprising:
[0045] The Hongmeng serialization data acquisition module is used to obtain the Hongmeng serialization data that needs to be deserialized, and is used to generate type factories of different types of adapters;
[0046] An operation subject generation module, used to decrypt and parse the Hongmeng serialized data to generate an operation subject;
[0047] A data structure type judgment module, used to judge the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory;
[0048] A parameter value extraction module, used to extract parameter values from the operation subject using the target adapter, and determine whether the extracted parameter value belongs to the object type; if so, call the operation subject update module; if not, call the parameter value transformation module;
[0049] An operation subject updating module is used to take the parameter value belonging to the object type as a new operation subject and call the data structure type judgment module;
[0050] The parameter value transformation module is used to perform deserialization transformation on parameter values that do not belong to the object type, generate preliminary deserialization results, and combine the preliminary deserialization results to form deserialization characters.
[0051] A serialization or deserialization device, comprising a memory and a processor;
[0052] The memory is used to store programs;
[0053] The processor is used to execute the program to implement each step of the above-mentioned serialization or deserialization method.
[0054] A readable storage medium stores a computer program thereon, characterized in that when the computer program is executed by a processor, each step of the above-mentioned serialization or deserialization method is implemented.
[0055] It can be seen from the above technical scheme that the serialization method provided by the present application can obtain a type factory for generating different types of adapters, as well as the Hongmeng memory data that needs to be serialized; parse the Hongmeng memory data and extract the operation elements; judge the data structure type of the operation elements, and use the type factory to generate a target adapter that matches the operation elements based on the data structure type of the operation elements; use the target adapter to generate a target key value that matches the operation element, and assign the target key value based on the operation element to obtain a preliminary serialization result; based on this, the present application can perform targeted serialization transformation on the operation elements to avoid the logical confusion that may be caused by processing multiple data at the same time, which is helpful to the refinement and reliability of the entire serialization process; at the same time, in the serialization transformation process, the present application uses the type factory to generate a target key value that matches the operation element based on the data structure type of the operation element A target adapter that matches the operation element is formed, and the target adapter is used to perform serialization adjustment on the operation element, thereby providing different serialization adjustment processes for different data structures, realizing the conversion of the operation element from the original memory data state to the preliminary serialization requirement state, ensuring the accuracy and efficiency of the serialization transformation, thereby realizing the gradual conversion of complex and diverse data in the memory of the Hongmeng system into a data format that is convenient for data transmission; subsequently, it can be determined whether the target adapter corresponds to the preset basic adapter; if not, the preliminary serialization result is disassembled to obtain the disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned, and the step of generating a target adapter that matches the operation element based on the data structure type of the operation element by using the type factory; if so, each preliminary serialization result is encrypted and combined to form a serialized character. Based on this, the present application can recursively serialize Hongmeng memory data, ensuring that the serialization process can go deep into all levels and details of Hongmeng memory data, and can also perform complete and accurate serialization processing on complex nested data structures, so that the final generated serialization result can be finely processed, improving the integrity and accuracy of the serialization characters. At the same time, the serialization characters of the present application are encrypted to facilitate the security of the data transmission process. Therefore, the present application can realize the serialization of Hongmeng memory data through the above process, while ensuring the accuracy of the serialization characters, it improves the transmission security and efficiency of Hongmeng memory data; by providing a unified serialization method, it helps developers maintain the consistency of data formats between different devices or processes, reduces the development problems caused by inconsistent data formats, and improves development efficiency; through serialization methods, it can significantly reduce the amount of data during data transmission, and reduce the consumption of network bandwidth and storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0057] Figure 1 A flowchart of a serialization method disclosed in an embodiment of the present application;
[0058] Figure 2 A structural block diagram of a serialization device disclosed in an embodiment of the present application;
[0059] Figure 3 A flow chart of a deserialization method disclosed in an embodiment of the present application;
[0060] Figure 4 A structural block diagram of a deserialization device disclosed in an embodiment of the present application;
[0061] Figure 5 A hardware structure block diagram of a serialization or deserialization device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0062] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0063] The embodiment of the present application provides a serialization method, which can be applied to various Hongmeng systems or various computer terminals or smart terminals equipped with Hongmeng systems. The execution subject can be a processor or server of a computer terminal or a smart terminal. The method flow chart of the serialization method is as follows: Figure 1 As shown, specifically including:
[0064] Step S1: Obtain the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized.
[0065] Specifically, the type factory can be used to generate different types of adapters for data of different data structure types.
[0066] Different types of adapters can parse the attributes of data of corresponding data structure types, and serialize and adjust the matching data according to the corresponding data structure and grammatical rules.
[0067] HarmonyOS memory data can be composed of a nested combination of data of multiple different data structure types, or a nested combination of different data of the same data structure type.
[0068] There are many scenarios where the corresponding memory information needs to be serialized.
[0069] When memory information needs to be transmitted to other HarmonyOS devices, the memory information can be considered as HarmonyOS memory data that needs to be serialized.
[0070] When the memory information needs to be serialized and stored, the memory information can also be considered as HarmonyOS memory data that needs to be serialized.
[0071] Step S2: parse the Hongmeng memory data and extract operation elements.
[0072] Specifically, the HarmonyOS memory data can be parsed and pushed into the parsing stack so as to recursively serialize the HarmonyOS memory data.
[0073] The top element may be extracted from the parsing stack as an operation element, and the extracted top element may be removed from the parsing stack.
[0074] Step S3: determine the data structure type of the operation element, and use the type factory to generate a target adapter that matches the operation element based on the data structure type of the operation element.
[0075] Specifically, the type factory can be used to parse the operation element, determine the data structure type of the operation element, and generate a target adapter of a corresponding type for the operation element.
[0076] The data structure type may be an object type, a key-value pair type, a basic structure type, or an array type.
[0077] Integer int, single-precision floating point number float and string String can be used as basic structure types.
[0078] Step S4: using the target adapter to generate a target key value that matches the operation element, and assigning a value to the target key value based on the operation element to obtain a preliminary serialization result.
[0079] Specifically, the target adapter can be used to construct the target key value based on the structural target of the operation element, and each target key value can be assigned based on the operation element, and a preliminary serialization result can be obtained after the assignment.
[0080] For example, the structural target of the operation element may include Zhang San's data, Li Si's data, etc., and the target key value corresponding to Zhang San and the target key value corresponding to Li Si may be constructed. Based on the numerical value in the operation element, the two target key values may be assigned values to obtain a preliminary serialization result containing two target key values and their parameter values.
[0081] After assigning a value to each target key value, each target key value corresponds to a parameter value.
[0082] Step S5, determine whether the target adapter corresponds to the preset basic adapter. If not, execute step S6; if yes, execute step S7.
[0083] Specifically, if the latest operation element read is both the top element and the bottom element of the stack, and the latest operation element read is of the basic structure type, then step S7 is executed. Otherwise, step S6 is executed.
[0084] Step S6: disassemble the preliminary serialization result to obtain a disassembly result, extract a new operation element from the disassembly result, and return to execute step S3.
[0085] Specifically, the preliminary serialization result may be split, for example, the preliminary serialization result may be split into two target key values, and the two target key values are pushed into the parsing stack respectively, and the process returns to execute step S3.
[0086] Step S7: encrypt and combine the preliminary serialization results to form serialized characters.
[0087] Specifically, after the data structure type of the latest read operation element is the basic structure type, the target adapter corresponding to the operation element belongs to the basic adapter.
[0088] Using the target adapter, the newly read operation elements are serialized and transformed to obtain a preliminary serialization result.
[0089] A preset encryption method may be used to encrypt each preliminary serialization result, and the encrypted preliminary serialization results may be integrated to form a serialized character.
[0090] The serialized characters can be transmitted to other devices.
[0091] Among them, each preliminary serialization result can be encrypted by a variety of encryption methods.
[0092] For example, you can set multiple encryption algorithms and set serial numbers corresponding to different encryption algorithms;
[0093] A target encryption algorithm is randomly selected from a plurality of encryption algorithms, and any unencrypted preliminary serialization result is encrypted to obtain an encryption result, and a serial number corresponding to the target encryption algorithm is marked in the encryption result to obtain an encrypted preliminary serialization result;
[0094] The encrypted preliminary serialization results are integrated to obtain serialized characters.
[0095] For another example, a target encryption algorithm and a target encryption character may be set, each preliminary serialization result may be encrypted based on the target encryption algorithm and the target encryption character, and each encrypted preliminary serialization result may be integrated to obtain a serialization character after integration.
[0096] It can be seen from the above technical scheme that the serialization method provided by the present application can obtain a type factory for generating different types of adapters, as well as the Hongmeng memory data that needs to be serialized; parse the Hongmeng memory data and extract the operation elements; judge the data structure type of the operation elements, and use the type factory to generate a target adapter that matches the operation elements based on the data structure type of the operation elements; use the target adapter to generate a target key value that matches the operation element, and assign the target key value based on the operation element to obtain a preliminary serialization result; based on this, the present application can perform targeted serialization transformation on the operation elements to avoid the logical confusion that may be caused by processing multiple data at the same time, which is helpful to the refinement and reliability of the entire serialization process; at the same time, in the serialization transformation process, the present application uses the type factory to generate a target key value that matches the operation element based on the data structure type of the operation element A target adapter that matches the operation element is formed, and the target adapter is used to perform serialization adjustment on the operation element, thereby providing different serialization adjustment processes for different data structures, realizing the conversion of the operation element from the original memory data state to the preliminary serialization requirement state, ensuring the accuracy and efficiency of the serialization transformation, thereby realizing the gradual conversion of complex and diverse data in the memory of the Hongmeng system into a data format that is convenient for data transmission; subsequently, it can be determined whether the target adapter corresponds to the preset basic adapter; if not, the preliminary serialization result is disassembled to obtain the disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned, and the step of generating a target adapter that matches the operation element based on the data structure type of the operation element by using the type factory; if so, each preliminary serialization result is encrypted and combined to form a serialized character. Based on this, the present application can recursively serialize Hongmeng memory data, ensuring that the serialization process can go deep into all levels and details of Hongmeng memory data, and can also perform complete and accurate serialization processing on complex nested data structures, so that the final generated serialization result can be finely processed, improving the integrity and accuracy of the serialization characters. At the same time, the serialization characters of the present application are encrypted to facilitate the security of the data transmission process. Therefore, the present application can realize the serialization of Hongmeng memory data through the above process, while ensuring the accuracy of the serialization characters, it improves the transmission security and efficiency of Hongmeng memory data; by providing a unified serialization method, it helps developers maintain the consistency of data formats between different devices or processes, reduces the development problems caused by inconsistent data formats, and improves development efficiency; through serialization methods, it can significantly reduce the amount of data during data transmission, and reduce the consumption of network bandwidth and storage space.
[0097] In some embodiments of the present application, considering that different types of target adapters may correspond to different data structure types, and similarly, in the case of different target adapters, different assignment processes may correspond to them. Based on this, the above step S3, judging the data structure type of the operation element, using the type factory, generating a target adapter matching the operation element based on the data structure type of the operation element, and step S4, using the target adapter, generating a target key value matching the operation element, and assigning the target key value based on the operation element, to obtain different execution processes of the preliminary serialization result are described in detail, and the steps are as follows:
[0098] The first one,
[0099] S30. When it is determined that the data structure type of the operation element belongs to an object type, use the type factory to generate an object adapter as a target adapter that matches the operation element.
[0100] Specifically, the type factory can be used to determine the data structure type of the operation element. When it is determined that the data structure type of the operation element is an object type, an object adapter can be generated as a target adapter for serializing and transforming the operation element.
[0101] S40. Using the target adapter, create a target object that matches the operation element and contains multiple target key values.
[0102] Specifically, when the target adapter is an object adapter, the object adapter can determine multiple structural targets corresponding to the operation element and generate a target key value uniquely corresponding to each structural target; each target key value constitutes a target object corresponding to the operation element.
[0103] S41. Using the target adapter, traverse the operation elements, determine multiple sub-item values from the operation elements, map and distribute each sub-item value to each target key value, and the target object after distribution is a preliminary serialization result.
[0104] Specifically, the object adapter can be used to traverse the operation elements, extract the characters corresponding to each structural target as sub-item values, and based on the correspondence between each sub-item value and each structural target, as well as the correspondence between each structural target and each target key value, map and distribute each sub-item value to each target key value. The target object after assignment is the preliminary serialization result.
[0105] The second type
[0106] S30. When it is determined that the data structure type of the operation element belongs to a key-value pair type, using the type factory, generate a key-value pair adapter as a target adapter matching the operation element.
[0107] Specifically, the type factory can be used to determine the data structure type of the operation element. When it is determined that the data structure type of the operation element is a key-value pair type, a key-value pair adapter can be generated as a target adapter for serializing and transforming the operation element.
[0108] S40. Using the target adapter, create a target object that matches the operation element and contains multiple target key values.
[0109] Specifically, during the serialization transformation process, the transformation process of the key-value pair adapter and the object adapter can be the same. Therefore, when the target adapter is a key-value pair adapter, the key-value pair adapter can determine the multiple structural targets corresponding to the operation element, and generate multiple target key values corresponding to each structural target one by one; each target key value can be combined to form a target object corresponding to the operation element.
[0110] S41. Using the target adapter, traverse the operation elements, determine multiple sub-item values from the operation elements, map and distribute each sub-item value to each target key value, and the target object after distribution is a preliminary serialization result.
[0111] Specifically, the key-value pair adapter can be used to traverse the operation elements, extract the characters corresponding to each structure target in turn, and obtain multiple sub-item values;
[0112] Based on the correspondence between each sub-item value and each structure target, and the correspondence between each structure target and each target key value, each sub-item value is assigned to the matching target key value, and the assigned target object is the preliminary serialization result.
[0113] The third type
[0114] S30. When it is determined that the data structure type of the operation element belongs to the list type, using the type factory, generate a list adapter as a target adapter matching the operation element.
[0115] Specifically, the type factory can be used to determine the data structure type of the operation element. When it is determined that the data structure type of the operation element is a list type, a list adapter can be generated as a target adapter for serializing and transforming the operation element.
[0116] S40. Using the target adapter, convert the operation element into an array object.
[0117] Specifically, the list adapter can be used to convert the internal logic of the operation elements and convert the operation elements into array objects that can be processed by the array adapter.
[0118] S41. Calling an array adapter, generating an array key value matching the array object, and determining a parameter value corresponding to each array key value based on the array object to generate a preliminary serialization result.
[0119] Specifically, you can use the type factory to generate an array adapter based on the array object, and use the array adapter to build the array key value;
[0120] Based on the array object, the array key values can be assigned, and the assigned array key values form the preliminary serialization results.
[0121] The fourth type
[0122] S30. When it is determined that the data structure type of the operation element belongs to a basic data structure type, using the type factory, generate a basic adapter as a target adapter matching the operation element.
[0123] Specifically, the type factory can be used to determine the data structure type of the operation element. When the data structure type of the operation element is determined to be the basic data structure type, a basic adapter can be generated as a target adapter for serializing and transforming the operation element.
[0124] S40. Based on the target adapter, create a target key value that matches the operation element, and based on the target adapter, assign the target key value to generate a preliminary serialization result.
[0125] Specifically, the basic adapter can be used to determine the structural target of the operation element, generate a target key value that matches the structural target, and assign the target key value based on the operation element to obtain a preliminary serialization result after the assignment.
[0126] Fifth,
[0127] S30. When it is determined that the data structure type of the operation element belongs to an array type, using the type factory, generate an array adapter as a target adapter matching the operation element.
[0128] Specifically, the type factory can be used to determine the data structure type of the operation element. When it is determined that the data structure type of the operation element is an array type, an array adapter can be generated as a target adapter for serializing and transforming the operation element.
[0129] S40. Based on the target adapter, create an array key value that matches the operation element, and based on the target adapter, assign the array key value to generate a preliminary serialization result.
[0130] Specifically, the basic adapter can be used to determine the structural target of the operation element, generate array key values that match the structural target, and assign the array key values based on the operation element to obtain a preliminary serialization result after the assignment.
[0131] It can be seen from the above technical scheme that this embodiment provides five optional processes for executing data structure type judgment on the operation element, using the type factory to generate a target adapter that matches the operation element based on the data structure type of the operation element; using the target adapter to generate a target key value that matches the operation element, and assigning the target key value based on the operation element to obtain a preliminary serialization result. Through the above process, different serialization transformation processes can be provided for operation elements of different data structure types, supporting the serialization of complex collection objects including ArrayList, List, Map, etc., to improve type extensibility; allowing the access end to flexibly control the serialization type, realizing a generic mapping mechanism, and improving the wide application of the present application; adding exception detection and bottom-up processing to ensure safe and effective return processing of data that does not conform to the serialization specification.
[0132] Next, we will combine Figure 2 The serialization device provided in the present application is introduced in detail. The serialization device provided below can be compared with the serialization method provided above.
[0133] See also Figure 2 It can be found that the serialization device may include:
[0134] The Hongmeng memory data acquisition module 10 is used to obtain the type factory used to generate different types of adapters, and the Hongmeng memory data that needs to be serialized;
[0135] An operation element reading module 20 is used to parse the Hongmeng memory data and extract operation elements;
[0136] A target adapter generation module 30, configured to determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory;
[0137] The operation element transformation module 40 is used to generate a target key value matching the operation element by using the target adapter, and assign a value to the target key value based on the operation element to obtain a preliminary serialization result;
[0138] The serialization character generation module 50 is used to determine whether the target adapter corresponds to the preset basic adapter; if so, the serialization character acquisition module 70 is called; if not, the preliminary serialization result disassembly module 60 is called;
[0139] A preliminary serialization result disassembly module 60 is used to disassemble the preliminary serialization result to obtain a disassembly result, extract new operation elements from the disassembly result, and call the target adapter generation module 30;
[0140] The serialized character acquisition module 70 is used to encrypt and combine the various preliminary serialization results to form a serialized character.
[0141] Further, the target adapter generation module may include:
[0142] An object type determination unit, configured to generate an object adapter as a target adapter matching the operation element by using the type factory when determining that the data structure type of the operation element belongs to the object type;
[0143] Operational element transformation modules can include:
[0144] A target object creation unit, used to create a target object matching the operation element and containing multiple target key values by using the target adapter;
[0145] The sub-item value distribution unit is used to utilize the target adapter to traverse the operation elements, determine multiple sub-item values from the operation elements, map and distribute each sub-item value to each target key value, and the target object after distribution is the preliminary serialization result.
[0146] Further, the target adapter generation module may include:
[0147] a list type determination unit, configured to generate a list adapter as a target adapter matching the operation element by using the type factory when determining that the data structure type of the operation element belongs to the list type;
[0148] Operational element transformation modules can include:
[0149] An array object creation unit, used to convert the operation element into an array object by using the target adapter;
[0150] The array adapter calling unit is used to call the array adapter, generate array key values matching the array object, determine the parameter value corresponding to each array key value based on the array object, and generate a preliminary serialization result.
[0151] The embodiment of the present application provides a deserialization method, which can be applied to various Hongmeng systems or various computer terminals or smart terminals equipped with Hongmeng systems. The execution subject can be a processor or server of a computer terminal or a smart terminal. The method flow chart of the serialization method is as follows: Figure 3 As shown, specifically including:
[0152] Step S1: Obtain the Hongmeng serialized data that needs to be deserialized, as well as the type factory used to generate different types of adapters.
[0153] Specifically, in addition to serializing and adjusting the matching data, each adapter can also parse the data structure and grammatical rules of the matching data and deserialize the matching data.
[0154] There are many scenarios where the corresponding serialized information may need to be deserialized.
[0155] When receiving serialization information transmitted by other HarmonyOS devices, the serialization information can be considered as HarmonyOS serialization data that needs to be deserialized.
[0156] When the serialized information needs to be deserialized and stored, the serialized information can also be considered as HarmonyOS serialized data that needs to be deserialized.
[0157] Step S2: decrypt and parse the Hongmeng serialized data to generate an operation subject.
[0158] Specifically, the HarmonyOS serialized data may be encrypted character data, and thus, the HarmonyOS serialized data may be decrypted to obtain a decrypted result.
[0159] Among them, the corresponding target decryption algorithm and the corresponding decryption characters can be determined according to the encryption algorithm serial number of the HarmonyOS serialized data, and the HarmonyOS serialized data can be decrypted based on the target decryption algorithm and the corresponding decryption characters.
[0160] The decryption result can be parsed and recursively deserialized, so the source proxy object can be extracted from the Hongmeng serialized data as the operation subject.
[0161] Step S3: determine the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory.
[0162] Specifically, the type factory can be used to determine the data structure type of the operation subject, and a target adapter for deserializing and transforming the operation subject can be generated with reference to the data structure type of the operation subject.
[0163] Step S4: Utilize the target adapter to extract parameter values from the operation subject, and determine whether the extracted parameter values belong to the object type; if so, execute step S5; if not, execute step S6.
[0164] Specifically, the target adapter can be used to extract the parameter value of the operation subject;
[0165] Determine whether the parameter value has multiple object attributes. If so, execute step S5; if not, execute step S6.
[0166] Step S5: Use the parameter value belonging to the object type as a new operation subject, and return to execute step S3.
[0167] Specifically, the parameter value containing multiple object attributes can be used as a new operation subject, and the execution of step S3 can be returned to recursively parse the HarmonyOS serialized data.
[0168] Step S6: Deserialize the parameter values that do not belong to the object type to generate preliminary deserialization results, and combine the preliminary deserialization results to form a deserialization string.
[0169] Specifically, the target adapter corresponding to the operation subject can be used to perform deserialization adjustment on parameter values that do not belong to the object type, and a preliminary deserialization result is obtained after the adjustment.
[0170] The various preliminary deserialization results can be integrated to obtain the deserialized characters corresponding to the Hongmeng serialized data.
[0171] It can be seen from the above technical scheme that this embodiment provides a deserialization method, which can obtain the HarmonyOS serialized data that needs to be deserialized, as well as a type factory for generating different types of adapters; decrypt and parse the HarmonyOS serialized data to generate an operation subject; determine the data structure type of the operation subject, and use the type factory to generate a target adapter that matches the operation subject based on the data structure type of the operation subject; use the target adapter to extract parameter values from the operation subject; based on this, the present application can provide different target adapters for deserialization for operation subjects of different data structure types, thereby realizing flexible configuration according to data structure characteristics and improving The compatibility of the deserialization process with multiple data structure types can be determined. Subsequently, it can be determined whether the extracted parameter value belongs to the object type. If so, the parameter value belonging to the object type is used as the new operation subject, and the step of using the type factory to generate a target adapter that matches the operation subject based on the data structure type of the operation subject is returned. If not, the parameter value that does not belong to the object type is deserialized and transformed to generate a preliminary deserialization result. Each preliminary deserialization result is combined to form a deserialization character. Based on this, different processing methods can be used according to whether the parameter value belongs to the object type. When the parameter value belongs to the object type, it indicates that the parameter value contains more information, and the parameter value can be recursively processed. Therefore, through loop iteration, it is easy to process Hongmeng serialized data with complex nested structures, avoid missing any level of data in the deserialization process, and ensure the reliability and accuracy of the deserialized characters. On this basis, the support for deserialization types has been expanded to ensure that after the parameter key is matched successfully, JSON data can be seamlessly deserialized into collection types such as ArrayList, List, Map, etc.; the null value security has been enhanced, and the default value filling mechanism is used to ensure that all parameters of the target object are effectively initialized during the deserialization process; the exception detection and fallback mechanism have been strengthened to provide a safe and effective processing solution for data that does not comply with the serialization specification; type compatibility detection has been introduced. When the data structure type of the operation subject does not match the source data type parameter type, an intelligent type conversion is attempted, and it automatically falls back to the default value when the conversion fails, to ensure the stability and reliability of data processing.
[0172] In addition, this application can add enhanced null value processing and exception detection mechanisms, significantly reducing the risk of errors faced by developers during serialization and deserialization, and improving the robustness and fault tolerance of the code.
[0173] By providing flexible and general serialization and deserialization support, developers can easily operate on any type of data and accelerate the development process.
[0174] By optimizing the serialization and deserialization processes, data errors and anomalies can be effectively prevented, providing a solid guarantee for the stable operation of the system.
[0175] In some embodiments of the present application, considering that different types of target adapters have different parameter value extraction methods, on this basis, step S4, using the target adapter to extract parameter values for the operation subject, and determining whether the extracted parameter values belong to the object type, is described in detail, and the steps are as follows:
[0176] The first one,
[0177] S40: When the target adapter is an object adapter, use the object adapter to traverse all target key values of the operation subject, and extract a corresponding parameter value from each target key value.
[0178] Specifically, when the data structure type of the operation subject is an object type, an object adapter can be generated as a target adapter of the operation subject by using a type factory.
[0179] At this time, the object adapter can be used to traverse all target key values of the operation subject and extract the corresponding parameter value from each target key value.
[0180] The second type
[0181] S40. When the target adapter is an array adapter, use the array adapter and take the operation subject as a parameter value.
[0182] Specifically, when the data structure type of the operation subject is an array type, an array adapter can be generated as a target adapter of the operation subject by using the type factory.
[0183] At this time, you can use the array adapter to determine whether the operation subject contains a source object. If not, traverse the map to clone the operation subject as the parameter value.
[0184] The third type
[0185] S40: When the target adapter is a key-value pair adapter, use the key-value pair adapter and take the operation subject as a parameter value.
[0186] Specifically, when the data structure type of the operation subject is a key-value pair type, a key-value pair adapter can be generated as a target adapter of the operation subject by using a type factory.
[0187] At this point, you can use the key-value pair adapter to traverse the map cloning operation body as the parameter value.
[0188] The fourth type
[0189] S40: When the target adapter is a basic adapter, use the basic adapter and take the operation subject as a parameter value.
[0190] Specifically, when the data structure type of the operation subject is a basic type, a basic adapter can be generated as a target adapter of the operation subject by using a type factory.
[0191] At this time, you can use the basic adapter to take the operation subject as the parameter value.
[0192] Fifth,
[0193] S40. When the target adapter is a list adapter, use the list adapter to convert the operation subject into an array object, and call the array adapter with the operation subject as a parameter value.
[0194] Specifically, when the data structure type of the operation subject is a list type, a list adapter can be generated as a target adapter of the operation subject by using the type factory.
[0195] At this point, the list adapter can convert the internal logic of the operation body and convert the operation body into an array object that can be processed by the array adapter.
[0196] Use the array adapter to determine whether the operation subject contains a source object. If not, traverse the map to clone the operation subject as the parameter value.
[0197] It can be seen from the above technical solutions that this embodiment provides five optional methods of extracting parameter values from the operation subject using the target adapter, and the application scope of the present application can be further expanded through the above methods.
[0198] Next, we will combine Figure 4 The deserialization device provided in the present application is introduced in detail. The deserialization device provided below can be compared with the deserialization method provided above.
[0199] See also Figure 4 It can be found that the deserialization device can include:
[0200] The Hongmeng serialization data acquisition module 10 is used to obtain the Hongmeng serialization data that needs to be deserialized, and to generate type factories of different types of adapters;
[0201] An operation subject generation module 20, used to decrypt and parse the Hongmeng serialized data to generate an operation subject;
[0202] A data structure type judgment module 30 is used to judge the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory;
[0203] The parameter value extraction module 40 is used to extract the parameter value of the operation subject by using the target adapter, and determine whether the extracted parameter value belongs to the object type; if so, call the operation subject update module 50; if not, call the parameter value transformation module 60;
[0204] The operation subject updating module 50 is used to take the parameter value belonging to the object type as the new operation subject and call the data structure type judgment module;
[0205] The parameter value transformation module 60 is used to perform deserialization transformation on parameter values that do not belong to the object type, generate preliminary deserialization results, and combine the preliminary deserialization results to form deserialization characters.
[0206] Furthermore, the parameter value extraction module may include:
[0207] The object adapter utilizing unit is used for, when the target adapter is an object adapter, utilizing the object adapter to traverse all target key values of the operation subject and extract corresponding parameter values from each target key value.
[0208] Furthermore, the parameter value extraction module may include:
[0209] The array adapter utilizing unit is used to utilize the array adapter when the target adapter is an array adapter and use the operation subject as a parameter value.
[0210] The serialization device provided in the embodiment of the present application can be applied to serialization devices, such as PC terminals, cloud platforms, servers and server clusters. Similarly, the deserialization device provided in the embodiment of the present application can be applied to deserialization devices, such as PC terminals, cloud platforms, servers and server clusters. Optionally, Figure 5 The hardware structure diagram of the serialization device and the deserialization device is shown. Figure 5 , the hardware structure of the serialization device and the deserialization device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0211] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0212] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;
[0213] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), etc., such as at least one disk memory;
[0214] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:
[0215] Get the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized;
[0216] Parse the Hongmeng memory data and extract operation elements;
[0217] Determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory;
[0218] Using the target adapter, generating a target key value matching the operation element, and assigning a value to the target key value based on the operation element to obtain a preliminary serialization result;
[0219] Determining whether the target adapter corresponds to a preset basic adapter;
[0220] If not, the preliminary serialization result is disassembled to obtain a disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned to execute, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element;
[0221] If yes, each preliminary serialization result is encrypted and combined to form a serialized character.
[0222] or,
[0223] Get the Hongmeng serialized data that needs to be deserialized, as well as the type factory used to generate different types of adapters;
[0224] Decrypt and parse the Hongmeng serialized data to generate an operation subject;
[0225] Determine the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory;
[0226] Utilizing the target adapter, extracting parameter values from the operation subject, and determining whether the extracted parameter values belong to an object type;
[0227] If yes, the parameter value belonging to the object type is used as a new operation subject, and the step of using the type factory to generate a target adapter matching the operation subject based on the data structure type of the operation subject is returned to be executed;
[0228] If not, the parameter value that does not belong to the object type is deserialized to generate a preliminary deserialization result, and each preliminary deserialization result is combined to form a deserialization character.
[0229] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0230] The embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0231] Get the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized;
[0232] Parse the Hongmeng memory data and extract operation elements;
[0233] Determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory;
[0234] Using the target adapter, generating a target key value matching the operation element, and assigning a value to the target key value based on the operation element to obtain a preliminary serialization result;
[0235] Determining whether the target adapter corresponds to a preset basic adapter;
[0236] If not, the preliminary serialization result is disassembled to obtain a disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned to execute, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element;
[0237] If yes, each preliminary serialization result is encrypted and combined to form a serialized character.
[0238] or,
[0239] Get the Hongmeng serialized data that needs to be deserialized, as well as the type factory used to generate different types of adapters;
[0240] Decrypt and parse the Hongmeng serialized data to generate an operation subject;
[0241] Determine the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory;
[0242] Utilizing the target adapter, extracting parameter values from the operation subject, and determining whether the extracted parameter values belong to an object type;
[0243] If yes, the parameter value belonging to the object type is used as a new operation subject, and the step of using the type factory to generate a target adapter matching the operation subject based on the data structure type of the operation subject is returned to be executed;
[0244] If not, the parameter value that does not belong to the object type is deserialized to generate a preliminary deserialization result, and each preliminary deserialization result is combined to form a deserialization character.
[0245] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0246] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0247] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0248] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present application. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. The various embodiments of the present application can be combined with each other. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A serialization method, characterized in that: include: Get the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized; Parse the Hongmeng memory data and extract operation elements; Determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory; Using the target adapter, generating a target key value matching the operation element, and assigning a value to the target key value based on the operation element to obtain a preliminary serialization result; Determining whether the target adapter corresponds to a preset basic adapter; If not, the preliminary serialization result is disassembled to obtain a disassembly result, and a new operation element is extracted from the disassembly result, and the step of performing data structure type judgment on the operation element is returned to execute, and using the type factory to generate a target adapter matching the operation element based on the data structure type of the operation element; If yes, each preliminary serialization result is encrypted and combined to form a serialized character.
2. The serialization method according to claim 1, characterized in that: The data structure type of the operation element is judged, and a target adapter matching the operation element is generated based on the data structure type of the operation element by using the type factory, including: When it is determined that the data structure type of the operation element belongs to the object type, using the type factory, an object adapter is generated as a target adapter matching the operation element; Using the target adapter, generating a target key value matching the operation element, and assigning the target key value based on the operation element to obtain a preliminary serialization result, including: Using the target adapter, create a target object that matches the operation element and contains multiple target key values; The target adapter is used to traverse the operation elements, determine multiple sub-item values from the operation elements, map and distribute each sub-item value to each target key value, and the distributed target object is the preliminary serialization result.
3. The serialization method according to claim 1, characterized in that: The data structure type of the operation element is judged, and a target adapter matching the operation element is generated based on the data structure type of the operation element by using the type factory, including: When it is determined that the data structure type of the operation element belongs to the list type, using the type factory, a list adapter is generated as a target adapter matching the operation element; Using the target adapter, generating a target key value matching the operation element, and assigning the target key value based on the operation element to obtain a preliminary serialization result, including: Using the target adapter, converting the operation element into an array object; The array adapter is called to generate array key values matching the array object, and the parameter value corresponding to each array key value is determined based on the array object to generate a preliminary serialization result.
4. A serialization device, characterized in that: include: The Hongmeng memory data acquisition module is used to obtain the type factory used to generate different types of adapters, as well as the Hongmeng memory data that needs to be serialized; An operation element reading module, used to parse the Hongmeng memory data and extract operation elements; A target adapter generation module, used to determine the data structure type of the operation element, and generate a target adapter matching the operation element based on the data structure type of the operation element by using the type factory; An operation element transformation module, used to generate a target key value matching the operation element by using the target adapter, and assign a value to the target key value based on the operation element to obtain a preliminary serialization result; A serialization character generation module, used to determine whether the target adapter corresponds to a preset basic adapter; If so, call the serialized character acquisition module; If not, the preliminary serialization result disassembly module is called; A preliminary serialization result disassembly module is used to disassemble the preliminary serialization result to obtain a disassembly result, extract new operation elements from the disassembly result, and call the target adapter generation module; The serialized character acquisition module is used to encrypt and combine various preliminary serialization results to form serialized characters.
5. A deserialization method, characterized in that: include: Get the Hongmeng serialized data that needs to be deserialized, as well as the type factory used to generate different types of adapters; Decrypt and parse the Hongmeng serialized data to generate an operation subject; Determine the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory; Utilizing the target adapter, extracting parameter values from the operation subject, and determining whether the extracted parameter values belong to an object type; If yes, the parameter value belonging to the object type is used as a new operation subject, and the step of using the type factory to generate a target adapter matching the operation subject based on the data structure type of the operation subject is returned to be executed; If not, the parameter value that does not belong to the object type is deserialized to generate a preliminary deserialization result, and each preliminary deserialization result is combined to form a deserialization character.
6. The deserialization method according to claim 5, characterized in that: Utilizing the target adapter to extract parameter values from the operation subject includes: When the target adapter is an object adapter, the object adapter is used to traverse all target key values of the operation subject, and a corresponding parameter value is extracted from each target key value.
7. The deserialization method according to claim 5, characterized in that: Utilizing the target adapter to extract parameter values from the operation subject includes: When the target adapter is an array adapter, the array adapter is used and the operation subject is used as a parameter value.
8. A deserialization device, characterized in that: include: The Hongmeng serialization data acquisition module is used to obtain the Hongmeng serialization data that needs to be deserialized, and is used to generate type factories of different types of adapters; An operation subject generation module, used to decrypt and parse the Hongmeng serialized data to generate an operation subject; A data structure type judgment module, used to judge the data structure type of the operation subject, and generate a target adapter matching the operation subject based on the data structure type of the operation subject by using the type factory; A parameter value extraction module, used to extract parameter values from the operation subject using the target adapter, and determine whether the extracted parameter value belongs to the object type; if so, calling the operation subject update module; If not, the parameter value transformation module is called; An operation subject updating module is used to take the parameter value belonging to the object type as a new operation subject and call the data structure type judgment module; The parameter value transformation module is used to perform deserialization transformation on parameter values that do not belong to the object type, generate preliminary deserialization results, and combine the preliminary deserialization results to form deserialization characters.
9. A serialization or deserialization device, characterized in that: including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement the various steps of the serialization method according to any one of claims 1 to 3 or to implement the various steps of the deserialization method according to any one of claims 5 to 7.
10. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the serialization method according to any one of claims 1 to 3 is implemented or each step of the deserialization method according to any one of claims 5 to 7 is implemented.