CN114117992B - Serialization and deserialization method and device and electronic equipment - Google Patents

Serialization and deserialization method and device and electronic equipment Download PDF

Info

Publication number
CN114117992B
CN114117992B CN202111414771.1A CN202111414771A CN114117992B CN 114117992 B CN114117992 B CN 114117992B CN 202111414771 A CN202111414771 A CN 202111414771A CN 114117992 B CN114117992 B CN 114117992B
Authority
CN
China
Prior art keywords
data information
json array
memory object
level
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111414771.1A
Other languages
Chinese (zh)
Other versions
CN114117992A (en
Inventor
冯刚义
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Likong Yuantong Technology Co ltd
Original Assignee
Beijing Likong Yuantong Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Likong Yuantong Technology Co ltd filed Critical Beijing Likong Yuantong Technology Co ltd
Priority to CN202111414771.1A priority Critical patent/CN114117992B/en
Publication of CN114117992A publication Critical patent/CN114117992A/en
Application granted granted Critical
Publication of CN114117992B publication Critical patent/CN114117992B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/30Circuit design
    • G06F30/39Circuit design at the physical level
    • G06F30/392Floor-planning or layout, e.g. partitioning or placement
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/30Circuit design
    • G06F30/39Circuit design at the physical level
    • G06F30/394Routing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/30Circuit design
    • G06F30/39Circuit design at the physical level
    • G06F30/398Design verification or optimisation, e.g. using design rule check [DRC], layout versus schematics [LVS] or finite element methods [FEM]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/004Artificial life, i.e. computing arrangements simulating life
    • G06N3/006Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/044Recurrent networks, e.g. Hopfield networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/12Computing arrangements based on biological models using genetic models
    • G06N3/126Evolutionary algorithms, e.g. genetic algorithms or genetic programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N7/00Computing arrangements based on specific mathematical models
    • G06N7/01Probabilistic graphical models, e.g. probabilistic networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N7/00Computing arrangements based on specific mathematical models
    • G06N7/08Computing arrangements based on specific mathematical models using chaos models or non-linear system models
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2111/00Details relating to CAD techniques
    • G06F2111/04Constraint-based CAD
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2111/00Details relating to CAD techniques
    • G06F2111/06Multi-objective optimisation, e.g. Pareto optimisation using simulated annealing [SA], ant colony algorithms or genetic algorithms [GA]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2111/00Details relating to CAD techniques
    • G06F2111/08Probabilistic or stochastic CAD
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2119/00Details relating to the type or aim of the analysis or the optimisation
    • G06F2119/06Power analysis or power optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2119/00Details relating to the type or aim of the analysis or the optimisation
    • G06F2119/08Thermal analysis or thermal optimisation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a serialization and deserialization method, a device and electronic equipment, wherein the serialization method comprises the following steps: acquiring a target memory object and realizing a serialization interface; and serializing the target memory object with the deleted key value into a target file through a serialization interface in a data format of a JSON array. According to the technical scheme provided by the invention, under the condition of deleting the key of the metadata key value pair, the data is stored in the JSON array format, the preset data structure of the data is ensured to be unchanged, the required information can be inquired according to the preset sequence during deserialization, and the data volume of the serialized file is reduced on the premise of ensuring that the data information is not lost.

Description

Serialization and deserialization method and device and electronic equipment
Technical Field
The invention relates to the field of data processing, in particular to a serialization and deserialization method, a serialization and deserialization device and electronic equipment.
Background
In object-oriented programming, some data generated when an application program is written is stored in a memory, and usually, according to the actual needs of a user, the data is converted into a byte stream to be written into a certain file for storage or transmitted to another computer in a network to realize communication. The above process of converting program data into a format that can be stored and transmitted is called "serialization", and its reverse process may be called "deserialization". Common serialized data formats include binary, XML, JSON objects and the like, and the formats have the advantages and the disadvantages and can be flexibly selected according to different application scenes. However, the file generated by using the existing data format for serialization is large, occupies more storage resources, and has slow serialization speed and transmission speed. Therefore, how to reduce the data size of the serialized files on the premise of ensuring that the data information is not lost is an urgent problem to be solved.
Disclosure of Invention
In view of this, embodiments of the present invention provide a serialization and deserialization method, apparatus, and electronic device, so that the data volume of a serialized file is reduced.
According to a first aspect, the present invention provides a method of serialization, the method comprising: acquiring a target memory object and realizing a serialization interface; serializing the target memory object with the deleted key value into a target file through the serialization interface in a data format of a JSON array.
Optionally, if the target memory object has multi-level nesting, serializing the target memory object with the delete key value into a target file through the serialization interface includes: and sequentially writing the data information of each level of the target memory object with the key value deleted into a target JSON array through a stack, converting the target JSON array into a byte stream and storing the byte stream in the target file so as to complete a serialization process.
Optionally, sequentially writing the data information of each level of the target memory object, from which the key value is deleted, into the target JSON array through the stack, including: creating a JSON array for storing data information in the target memory object, and writing the data information of the outermost level of the target memory object into the JSON array; when the data information writing of the nested object of the next level comes, pressing the JSON array of the current level into a stack, and creating the JSON array of the next level in the JSON array of the current level; writing data information in the nested object of the next level into the JSON array of the next level; repeating the steps from the step of pressing the JSON array of the current level into a stack and creating the JSON array of the next level in the JSON array of the current level to the step of writing the data information in the nested object of the next level into the JSON array of the next level until all the nested objects in the target memory object are written into the corresponding JSON arrays when the data information writing of the nested object of the next level is performed; and taking out the JSON array of the previous level of the current nested object from the stack after the data information in the nested object is written, and continuously writing the residual data information of the previous level into the JSON array of the previous level until all the data information in the target memory object is written into the target JSON array formed by the JSON arrays of the levels.
Optionally, before the implementing the serialized interface, the method further comprises: if the class of the target memory object is not preset, declaring and realizing a serialized interface of the class of the target memory object based on an auxiliary tool in a development environment; and if the class of the target memory object is preset, returning to the step of realizing the serialization interface.
Optionally, the development environment is a C + + environment, the auxiliary tool is defined by a macro, and declaring and implementing the serialization interface of the class based on the auxiliary tool in the development environment includes: performing serialization interface declaration on the class of the target memory object through a macro decode _ SERIAL; the declared serialization interface is validated by macro IMPLEMENT _ SERIAL to complete the serialization interface implementation.
According to a second aspect, the present invention provides a method of deserialization, the method comprising: creating a JSON array, and loading a target file obtained by any one of the methods in the first aspect into the JSON array; and deserializing the JSON array into a memory through a serialization interface to generate a target memory object, and acquiring data information corresponding to a target key value according to the sequence of the data information in the target memory object.
Optionally, if the JSON array has a multi-level nest, the loading the target file obtained by the method according to any one of the first aspects into the JSON array includes: and sequentially writing the data information of each level of the JSON array into the target memory object through a stack so as to complete the deserializing process.
Optionally, the sequentially writing the data information of each level of the JSON array into the target memory object through a stack includes: creating a memory object for storing data information in the JSON array, and writing the data information of the outermost level of the JSON array into the memory object; when the data information writing of the nested array of the next level is in turn, the memory object of the current level is pressed into a stack, and the memory object of the next level is created in the memory object of the current level; writing data information in the JSON array of the next level into the memory object of the next level; when the data information writing is performed on the nested array of the next level from the current turn, the memory object of the current level is pressed into the stack, the memory object of the next level is created in the memory object of the current level, and the data information in the JSON array of the next level is written into the memory object of the next level until all the nested arrays in the JSON array are written into the corresponding memory objects; and taking out the memory object of the previous level of the current nested array from the stack after the data information in the nested array is written, and continuously writing the residual data information of the previous level into the memory object of the previous level until all the data information in the JSON array is written into the target memory object formed by the memory objects of the different levels.
According to a third aspect, the present invention provides a serialization apparatus comprising: the initialization module is used for acquiring a target memory object and realizing a serialization interface; and the serialization module is used for serializing the target memory object of the deleted key value into a target file through the serialization interface in a data format of a JSON array.
According to a fourth aspect, the present invention provides an deserializing apparatus comprising: a loading module, configured to create a JSON array, and load a target file obtained by any one of the methods in the first aspect into the JSON array; and the deserializing module is used for deserializing the JSON array into a memory through a serializing interface to generate a target memory object and acquiring data information corresponding to a target key value according to the sequence of the data information in the target memory object.
According to a fifth aspect, an embodiment of the present invention provides an electronic device, including: a memory and a processor, the memory and the processor being communicatively coupled to each other, the memory having stored therein computer instructions, and the processor being configured to execute the computer instructions to perform the method of the first aspect, the second aspect, any one of the alternative embodiments of the first aspect, or any one of the alternative embodiments of the second aspect.
According to a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores computer instructions for causing a computer to execute the method according to the first aspect, the second aspect, any one of the optional implementations of the first aspect, or any one of the optional implementations of the second aspect.
The technical scheme provided by the application has the following advantages:
according to the serialization method provided by the application, the key values of the key value pair form data in the memory object are deleted, the remaining values corresponding to the key values are reserved, and the key values are serialized into the target file in the JSON array format according to the preset sequence, so that the data volume of the serialized file is greatly reduced, and the physical storage resources are saved.
In addition, aiming at the multi-level nested memory objects, data of each layer is written into the JSON array in a mode that a data structure is unchanged through the characteristics of the stack, and the accuracy of the data sequence in the JSON array is further guaranteed. And if the class of the target memory object is not preset in the development environment, declaring and realizing the serialization interface of the class of the target memory object based on an auxiliary tool in the development environment, so that the memory objects of any self-defined class can use the serialization method provided by the technical means, and the expansibility of the method is improved.
According to the deserialization method, firstly, data information in a target file is loaded into a JSON array, and then the data information in the JSON array is written into a target memory object, so that the obtained data information is absolutely consistent with the information sequence during storage, and the value corresponding to a target key value can be found through the preset sequence.
Drawings
The features and advantages of the present invention will be more clearly understood by reference to the accompanying drawings, which are illustrative and not to be construed as limiting the invention in any way, and in which:
FIG. 1 is a schematic diagram illustrating the steps of a serialization method in accordance with an embodiment of the present invention;
FIG. 2 is a diagram illustrating an example of an application for stack-based serialization in an embodiment of the present invention;
FIG. 3 is a schematic diagram illustrating the steps of a deserialization process in one embodiment of the present invention;
FIG. 4 is a schematic diagram of a serialization apparatus in accordance with an embodiment of the present invention;
FIG. 5 is a schematic diagram of an deserializing apparatus in one embodiment of the invention;
fig. 6 shows a schematic structural diagram of an electronic device in an embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings of the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without inventive step based on the embodiments of the present invention, are within the scope of the present invention.
Referring to fig. 1, in one embodiment, a serialization method includes the following steps:
step S101: and acquiring a target memory object and realizing a serialization interface.
Step S102: and serializing the target memory object with the deleted key value into a target file through a serialization interface in a data format of a JSON array.
Specifically, in object-oriented programming, before serializing object data stored in a memory, that is, memory objects, a serialization interface needs to be implemented in a development environment, that is, a function library for implementing a serialization function corresponding to the development environment is called. In object-oriented programming, object members are all stored in the form of key-value pairs (key-values). For example, a memory object is a student, and its internal object members include: "age:15; name: tom; counter: XX ", where age, name and count are key values (key), and 15, tom and XX are values (value) corresponding to the key values, which are collectively called key-value pairs. Then, in order to reduce the file size of the serialized file, the embodiment deletes the key value in the memory object, and only retains the data value, that is, "15"; tom; XX ", in the JSON data format, the data of the JSON object is unordered, while the data of the JSON array is ordered, starting and ending with middle brackets when written. Therefore, the data values of the deleted key values are serialized into the target file in the JSON array data format, the size of the target file can be reduced, the storage and transmission efficiency is improved, and the absolute invariance of the data storage sequence can be ensured. Although the stored data does not have the key value, when the data is obtained in the deserialization mode, the data value corresponding to the target key value can be obtained according to the additionally stored preset sequence, and therefore the accuracy of the data is guaranteed.
Specifically, in an embodiment, if the target memory object has multiple levels of nesting, the step S102 specifically includes the following steps:
the method comprises the following steps: and sequentially writing the data information of each hierarchy of the target memory object with the key value deleted into the target JSON array through the stack, converting the target JSON array into a byte stream, and storing the byte stream in a target file to complete the serialization process. Specifically, as shown in fig. 2, when the target memory object has multiple levels of nesting, in order to ensure that the structure of data serialization is completely the same as the original data structure, the order of data serialization is ensured. Therefore, by combining the 'first-in last-out' characteristic of the stack, the memory objects nested layer by layer are sequentially written into the JSON array, so that the structure of the serialized data information is not changed, the original data sequence is kept, and the accuracy of acquiring data in the subsequent deserialization is improved.
Specifically, in an embodiment, the step one specifically includes the following steps:
step two: and creating a JSON array for storing the data information in the target memory object, and writing the data information of the outermost level of the target memory object into the JSON array.
Step three: and when the data information writing of the nested object of the next level is performed, pressing the JSON array of the current level into the stack, and creating the JSON array of the next level in the JSON array of the current level.
Step four: and writing the data information in the nested object of the next level into the JSON array of the next level.
Step five: and repeating the third step to the fourth step until all the nested objects in the target memory object are written into the corresponding JSON array.
Step six: and taking out the JSON array of the previous level of the current nested object from the stack after the data information in the nested object is written, and continuously writing the residual data information of the previous level into the JSON array of the previous level until all the data information in the target memory object is written into the target JSON array formed by the JSON arrays of the levels.
Specifically, the data information in the target memory object is written into the JSON array, starting with the outermost layer of the target memory object. For example: as shown in fig. 2, int in the memory object a is first: 1 and double:1.0 is written into the first JSON array, when writing into the object B, the data information is judged to be a nested memory object, then the first JSON array is pressed into a stack to store the current progress of writing information, then a second JSON array is created in the first JSON array, the data information of the object B is continuously written into the second JSON array, if the nested memory object still exists in the object B, the operation is executed in a circulating reciprocating mode until the data information of the nested objects of all levels of the target memory object is written into the corresponding JSON array. And when all the data information of one nested object is written, taking the JSON array of the previous level of the nested object out of the stack, and continuously finishing writing the residual data information of the previous level. For example: and after all the data information of the Object B is written, taking the Object A out of the stack, and if other data information follows the Object, continuing writing the rest data information into the first JSON array. Therefore, through the steps, the original data structure of the memory object can be completely and invariably written into the JSON array, the data sequence is ensured, and the data accuracy is improved.
Specifically, in an embodiment, before the step S101, the following steps are further included:
step seven: if the class of the target memory object is not preset, declaring and realizing the serialized interface of the class based on an auxiliary tool in the development environment.
Step eight: and if the class of the target memory object is preset, returning to the step of realizing the serialization interface.
Specifically, in object-oriented programming, some data classes are preset in the development environment, but some self-defined classes exist, for example, a self-defined Class person, and are not preset in the internal development environment, so that the memory objects under the classes cannot be serialized by using the methods of steps S101 to S102. In order to improve the expansibility of the method, the self-defined class can be declared through an auxiliary tool provided by a development environment, and the serialization interface is enabled to take effect. The method of steps S101 to S102 provided in the embodiment of the present invention can be used for any self-defined class to perform serialization. In a specific embodiment, the adopted development environment is a C + + environment, the auxiliary tool is a macro definition in the C + + environment, and a serialization interface declaration is first performed on a class of a target memory object through a macro decode _ SERIAL; the declared serialization interface is validated by macro IMPLEMENT _ SERIAL to complete the serialization interface implementation. Therefore, the method of the steps S101 to S102 can be used for any self-defining class in the C + + environment, and the expansibility of the method is improved.
Referring to fig. 3, in another embodiment, a deserialization method specifically includes the following steps:
step S201: and creating a JSON array, and loading the target file obtained by the serialization method provided by the embodiment of the invention into the JSON array.
Step S202: and deserializing the JSON array into the memory through the serialization interface to generate a target memory object, and acquiring data information corresponding to the target key value according to the sequence of the data information in the target memory object.
Specifically, the target file obtained through serialization is loaded into the JSON array, and then the data information in the JSON array is written into the memory object, so that the data information stored in the preset data structure can be obtained, the data value corresponding to the target key value is accurately inquired according to the sequence of the data, and the accuracy of the data is guaranteed.
Specifically, in an embodiment, the step S202 specifically includes the following steps:
step nine: and sequentially writing the data information of each level of the JSON array into the target memory object through the stack so as to complete the deserialization process. Specifically, the detailed principle is the same as that of the first step in the serialization process, and is the reverse process of the serialization process, and reference may be made to the description of the first step, which is not repeated herein.
Specifically, in an embodiment, the step nine specifically includes the following steps:
step ten: and creating a memory object for storing the data information in the JSON array, and writing the data information of the outermost level of the JSON array into the memory object.
Step eleven: and when the data information writing of the nested array of the next level is in turn performed, the memory object of the current level is pressed into the stack, and the memory object of the next level is created in the memory object of the current level.
Step twelve: and writing the data information in the JSON array of the next level into the memory object of the next level.
Step thirteen: and repeating the step eleven to the step twelve until all nested arrays in the JSON array are written into the corresponding memory objects.
Fourteen steps: and (4) taking out the memory object of the previous level of the current nested array from the stack after the data information in the nested array is written, and continuously writing the residual data information of the previous level into the memory object of the previous level until all the data information in the JSON array is written into the target memory object formed by the memory objects of the different levels.
Specifically, the detailed principle is the same as that of step two to step six in the serialization process, and is the reverse process of the serialization process, and reference may be made to the description of step two to step six, which is not described herein again.
Through the steps, according to the serialization method provided by the application, the key values of the key value pair form data in the memory object are deleted, the rest data values are reserved, and the key values are serialized into the target file according to the preset sequence in the JSON array format, so that the data volume of the serialized file is greatly reduced, and the physical storage resources are saved.
In addition, aiming at the multi-level nested memory objects, data of each layer is written into the JSON array in a mode that a data structure is unchanged through the characteristics of the stack, and the accuracy of the data sequence in the JSON array is further guaranteed. And if the class of the target memory object is not preset in the development environment, declaring and realizing the serialization interface of the class of the target memory object based on an auxiliary tool in the development environment, so that the memory objects of any self-defined class can use the serialization method provided by the technical means, and the expansibility of the method is improved.
According to the deserialization method, firstly, data information in a target file is loaded into a JSON array, and then the data information in the JSON array is written into a target memory object, so that the obtained data information is absolutely consistent with the information sequence during storage, and the value corresponding to a target key value can be found through the preset sequence.
As shown in fig. 4, an embodiment of the present invention further provides a serialization apparatus, including:
the initialization module 101 is configured to obtain a target memory object and implement a serialization interface. For details, refer to the related description of step S101 in the above method embodiment, and no further description is provided here.
The serialization module 102 is configured to serialize the target memory object with the key value deleted into a target file through a serialization interface in a data format of a JSON array. For details, refer to the related description of step S102 in the above method embodiment, and no further description is provided here.
The serialization apparatus provided in the embodiment of the present invention is used for executing the serialization method provided in the above embodiment, and the implementation manner and the principle thereof are the same, and details are referred to the related description of the above method embodiment and are not described again.
As shown in fig. 5, an embodiment of the present invention further provides an deserializing apparatus, including:
the loading module 201 is configured to create a JSON array, and load a target file obtained by using the serialization method provided in the embodiment of the present invention into the JSON array. For details, refer to the related description of step S201 in the above method embodiment, and no further description is provided here.
And the deserializing module 202 is configured to deserialize the JSON array into the memory through the serialization interface to generate a target memory object, and acquire data information corresponding to the target key value according to the sequence of the data information in the target memory object. For details, refer to the related description of step S201 in the above method embodiment, and no further description is provided here.
The deserializing device provided by the embodiment of the invention is used for executing the deserializing method provided by the embodiment, the implementation manner and the principle are the same, and the details refer to the relevant description of the embodiment of the method and are not repeated.
Through the cooperative cooperation of the components, the key values of the key value pair form data in the memory object are deleted, the rest data values are reserved, and the key values are serialized into the target file in the JSON array format according to the preset sequence, so that the data volume of the serialized file is greatly reduced, and the physical storage resource is saved.
In addition, aiming at the multi-level nested memory objects, data of each layer is written into the JSON array in a mode that a data structure is unchanged through the characteristics of the stack, and the accuracy of the data sequence in the JSON array is further guaranteed. And if the class of the target memory object is not preset in the development environment, declaring and realizing the serialization interface of the class of the target memory object based on an auxiliary tool in the development environment, so that the memory objects of any self-defined class can use the serialization method provided by the technical means, and the expansibility of the method is improved.
According to the deserialization device, the data information in the target file is loaded into the JSON array, and then the data information in the JSON array is written into the target memory object, so that the obtained data information is absolutely consistent with the information sequence during storage, and the value corresponding to the target key value can be found through the preset sequence.
Fig. 6 shows an electronic device according to an embodiment of the present invention, where the device includes a processor 901 and a memory 902, which may be connected by a bus or by other means, and fig. 6 illustrates an example of a connection by a bus.
Processor 901 may be a Central Processing Unit (CPU). The Processor 901 may also be other general purpose processors, digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, or combinations thereof.
The memory 902, which is a non-transitory computer-readable storage medium, may be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions/modules corresponding to the methods in the above-described method embodiments. The processor 901 executes various functional applications and data processing of the processor by executing non-transitory software programs, instructions and modules stored in the memory 902, that is, implements the methods in the above-described method embodiments.
The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created by the processor 901, and the like. Further, the memory 902 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory 902 may optionally include memory located remotely from the processor 901, which may be connected to the processor 901 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
One or more modules are stored in the memory 902, which when executed by the processor 901 performs the methods in the above-described method embodiments.
The specific details of the electronic device may be understood by referring to the corresponding related descriptions and effects in the above method embodiments, and are not described herein again.
Those skilled in the art will understand that all or part of the processes in the methods of the embodiments described above may be implemented by instructing the relevant hardware through a computer program, and the implemented program may be stored in a computer-readable storage medium, and when executed, may include the processes of the embodiments of the methods described above. The storage medium may be a magnetic Disk, an optical Disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a Flash Memory (Flash Memory), a Hard Disk (Hard Disk Drive, abbreviated as HDD), a Solid State Drive (SSD), or the like; the storage medium may also comprise a combination of memories of the kind described above.
Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations fall within the scope defined by the appended claims.

Claims (8)

1. A method of serialization, the method comprising:
acquiring a target memory object and realizing a serialization interface;
serializing the target memory object with the key value deleted into a target file through the serialization interface in a data format of a JSON array;
if the target memory object has multi-level nesting, serializing the target memory object with the deleted key value into a target file through the serialization interface, including: sequentially writing the data information of each level of the target memory object with the key value deleted into a target JSON array through a stack, converting the target JSON array into a byte stream, and storing the byte stream in the target file to complete a serialization process;
the sequentially writing the data information of each level of the target memory object with the key value deleted into the target JSON array through the stack comprises the following steps: creating a JSON array for storing data information in the target memory object, and writing the data information of the outermost level of the target memory object into the JSON array; when the data information writing of the nested object of the next level is performed, pressing the JSON array of the current level into a stack, and creating the JSON array of the next level in the JSON array of the current level; writing data information in the nested object of the next level into the JSON array of the next level; repeating the steps from the step of pressing the JSON array of the current level into a stack and creating the JSON array of the next level in the JSON array of the current level to the step of writing the data information in the nested object of the next level into the JSON array of the next level until all the nested objects in the target memory object are written into the corresponding JSON arrays when the data information writing of the nested object of the next level is performed; and taking out the JSON array of the previous level of the current nested object from the stack after the data information in the nested object is written, and continuously writing the residual data information of the previous level into the JSON array of the previous level until all the data information in the target memory object is written into the target JSON array formed by the JSON arrays of the levels.
2. The method of claim 1, wherein prior to the implementing the serialized interface, the method further comprises:
if the class of the target memory object is not preset, declaring and realizing a serialized interface of the class of the target memory object based on an auxiliary tool in a development environment;
and if the class of the target memory object is preset, returning to the step of realizing the serialization interface.
3. The method of claim 2, wherein the development environment is a C + + environment, the accessibility tools are defined macros, and the declaring and implementing the serialized interfaces of the classes based on the accessibility tools in the development environment comprises:
performing serialization interface declaration on the class of the target memory object through a macro decode _ SERIAL;
the declared serialization interface is validated by macro IMPLEMENT _ SERIAL to complete the serialization interface implementation.
4. A method of deserializing, the method comprising:
creating a JSON array, and loading a target file obtained by the method of any one of claims 1-3 into the JSON array;
and deserializing the JSON array into a memory through a serialization interface to generate a target memory object, and acquiring data information corresponding to a target key value according to the sequence of the data information in the target memory object.
5. The method according to claim 4, wherein if the JSON array has multi-level nesting, the loading the target file obtained by the method according to any one of claims 1 to 3 into the JSON array comprises:
and sequentially writing the data information of each level of the JSON array into the target memory object through a stack to complete the deserialization process.
6. The method as claimed in claim 5, wherein said sequentially writing the data information of each level of said JSON array into said target memory object through a stack comprises:
creating a memory object for storing data information in the JSON array, and writing the data information of the outermost level of the JSON array into the memory object;
when the data information writing of the nested array of the next level is in turn, the memory object of the current level is pressed into a stack, and the memory object of the next level is created in the memory object of the current level;
writing data information in the JSON array of the next level into the memory object of the next level;
when the data information writing is performed on the nested array of the next level from the current turn, the memory object of the current level is pressed into the stack, the memory object of the next level is created in the memory object of the current level, and the data information in the JSON array of the next level is written into the memory object of the next level until all the nested arrays in the JSON array are written into the corresponding memory objects;
and taking out the memory object of the previous level of the current nested array from the stack after the data information in the nested array is written, and continuously writing the residual data information of the previous level into the memory object of the previous level until all the data information in the JSON array is written into the target memory object formed by the memory objects of the different levels.
7. A serialization apparatus, comprising:
the initialization module is used for acquiring a target memory object and realizing a serialization interface;
the serialization module is used for serializing the target memory object of the deleted key value into a target file through the serialization interface in a data format of a JSON array;
if the target memory object has multi-level nesting, serializing the target memory object with the deleted key value into a target file through the serialization interface includes: sequentially writing the data information of each level of the target memory object with the key value deleted into a target JSON array through a stack, converting the target JSON array into a byte stream, and storing the byte stream in the target file to complete a serialization process;
the sequentially writing the data information of each level of the target memory object with the key value deleted into the target JSON array through the stack comprises the following steps: creating a JSON array for storing data information in the target memory object, and writing the data information of the outermost layer of the target memory object into the JSON array; when the data information writing of the nested object of the next level is performed, pressing the JSON array of the current level into a stack, and creating the JSON array of the next level in the JSON array of the current level; writing data information in a nested object of a next level into a JSON array of the next level; repeating the steps from the step of pressing the JSON array of the current level into a stack and creating the JSON array of the next level in the JSON array of the current level to the step of writing the data information in the nested object of the next level into the JSON array of the next level until all the nested objects in the target memory object are written into the corresponding JSON arrays when the data information writing of the nested object of the next level is performed; and taking out the JSON array of the last level of the current nested object from the stack after the data information in the nested object is written, and continuously writing the residual data information of the last level into the JSON array of the last level until all the data information in the target memory object is written into the target JSON array formed by the JSON arrays of the levels.
8. An deserializing apparatus, comprising:
a loading module, configured to create a JSON array, and load a target file obtained by the method according to any one of claims 1 to 3 into the JSON array;
and the deserializing module is used for deserializing the JSON array into a memory through a serializing interface to generate a target memory object and acquiring data information corresponding to a target key value according to the sequence of the data information in the target memory object.
CN202111414771.1A 2021-11-25 2021-11-25 Serialization and deserialization method and device and electronic equipment Active CN114117992B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111414771.1A CN114117992B (en) 2021-11-25 2021-11-25 Serialization and deserialization method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111414771.1A CN114117992B (en) 2021-11-25 2021-11-25 Serialization and deserialization method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN114117992A CN114117992A (en) 2022-03-01
CN114117992B true CN114117992B (en) 2023-03-24

Family

ID=80375576

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111414771.1A Active CN114117992B (en) 2021-11-25 2021-11-25 Serialization and deserialization method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN114117992B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115237415B (en) * 2022-09-22 2022-12-16 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113553033A (en) * 2021-06-24 2021-10-26 厦门正航软件科技有限公司 Object serialization and deserialization method, device and computer readable storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7207002B2 (en) * 2003-11-13 2007-04-17 International Business Machines Corporation Serialization and preservation of objects
US9460198B1 (en) * 2012-07-26 2016-10-04 Google Inc. Process for serializing and deserializing data described by a schema
CN103605518B (en) * 2013-11-19 2017-12-19 北京国双科技有限公司 Object unserializing method and apparatus
CN103593194B (en) * 2013-11-21 2017-12-22 北京国双科技有限公司 Object serialization method and apparatus
CN112433787A (en) * 2020-11-09 2021-03-02 北京达佳互联信息技术有限公司 Target object serialization method and device, electronic device and storage medium
CN113138755A (en) * 2021-04-19 2021-07-20 上海逸动医学科技有限公司 JSON serialization and deserialization optimization method and system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113553033A (en) * 2021-06-24 2021-10-26 厦门正航软件科技有限公司 Object serialization and deserialization method, device and computer readable storage medium

Also Published As

Publication number Publication date
CN114117992A (en) 2022-03-01

Similar Documents

Publication Publication Date Title
EP3667496B1 (en) Distributed computing system, data transmission method and device in distributed computing system
CN106570018B (en) Serialization and deserialization method, device and system and electronic equipment
WO2020118608A1 (en) Deconvolutional neural network hardware acceleration method, apparatus, and electronic device
KR102111871B1 (en) Method and apparatus for generating random string
CN107330014B (en) Data table creating method and device
CN112783974A (en) Data conversion method, device, equipment and storage medium
CN114117992B (en) Serialization and deserialization method and device and electronic equipment
WO2020224380A1 (en) Blockchain-based data processing method and device
CN109213745B (en) Distributed file storage method, device, processor and storage medium
CN112667593B (en) Method and device for ETL (extract transform and load) process to execute hbase fast loading
WO2021013047A1 (en) File management method and apparatus
CN113407254A (en) Form generation method and device, electronic equipment and storage medium
CN110555522B (en) Data processing method, data processing device, computer equipment and storage medium
CN117234582A (en) Project code processing method and device, electronic equipment and storage medium
CN110647981B (en) Data processing method, data processing device, computer equipment and storage medium
CN111309424A (en) Page restoration method and related equipment
US20190147124A1 (en) Operation model generator and operation model generation method
US10810165B2 (en) Distributed storage server, server device included therein, and method of operating server device
CN114327660B (en) Initialization method of external memory based on FPGA
CN112860412B (en) Service data processing method and device, electronic equipment and storage medium
CN113434149B (en) Application program generating and loading method, device and medium
WO2008054790A2 (en) Systems and methods for optimized serialization
CN107229564B (en) Pressure simulation method and device
JP6333370B2 (en) Method for implementing dynamic array data structures in cache lines
US20180232205A1 (en) Apparatus and method for recursive processing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant