A method and apparatus for object serialization processing
By using data type conversion and compression techniques, the problem of low serialization performance has been solved, resulting in faster serialization speeds and smaller byte array lengths, thereby reducing data storage and transmission costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JINGDONG TECH HLDG CO LTD
- Filing Date
- 2022-01-27
- Publication Date
- 2026-05-15
AI Technical Summary
Existing serialization technologies suffer from issues such as long serialization times and large byte array lengths, especially when serializing large data objects, where performance drops significantly and cannot meet usage requirements.
By converting the data type of the object to be serialized and compressing the data, and by utilizing the mapping relationship of the serialization class factory, the conversion and compression of data type can be achieved, thereby reducing the length of the serialized byte array.
It improves the speed of serialization, reduces the cost of data storage and network transmission, and increases the efficiency of serialization.
Smart Images

Figure CN116561202B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for object serialization processing. Background Technology
[0002] Serialization is the process of converting the state information of an object into a form that can be stored or transmitted. It primarily serializes an object into a binary byte stream, allowing for reading and writing operations on the streamed object, as well as transmission and communication. Currently, major serialization technologies include Protostuff, Kryo, Hessian, and JDK.
[0003] In the process of realizing this invention, the inventors discovered the following problems in the prior art:
[0004] While existing serialization technologies each have their own characteristics, they suffer from performance issues such as long serialization time and large serialized byte array lengths. In particular, when serializing large data objects, the performance of serialization drops significantly, failing to meet usage requirements. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and apparatus for object serialization processing. Based on the serialization class of the object to be serialized, the method effectively reduces the number of data types to be serialized, improves the serialization speed, and reduces the length of the serialized byte array by converting the data type of the object to be serialized and compressing the data, thereby reducing the cost of data storage and network transmission.
[0006] To achieve the aforementioned objective, according to one aspect of the present invention, a method for object serialization processing is provided, comprising:
[0007] Based on the received serialization request, obtain the object to be serialized and the data type of the object;
[0008] Based on the data type of the object, the serialization class of the object is obtained from the serialization class factory, wherein the serialization class factory stores the mapping relationship between data types and serialization classes;
[0009] According to the serialization class of the object, each attribute information of the object is serialized in sequence, wherein the serialization process includes: data type conversion and data compression, and the attribute information includes attributes and attribute values.
[0010] Optionally, after obtaining the object to be serialized and the data type of the object, the method further includes: setting the starting position of the serialization result of the object in the storage unit; verifying the initial data in the storage unit and setting the initial length of the storage unit; after serializing each attribute information, the method further includes: saving the serialization result corresponding to each attribute information to the storage unit in sequence according to the starting position.
[0011] Optionally, the method further includes: if the serialization class of the object cannot be obtained from the serialization class factory, creating a serialization class corresponding to the object according to the data type of the object and saving it to the serialization class factory.
[0012] Optionally, creating a serialization class corresponding to the object based on the object's data type includes: obtaining the object's attributes; encapsulating the object's attributes and corresponding attribute value accessors to create a serialization class corresponding to the object.
[0013] Optionally, after obtaining the serialization class of the object from the serialization class factory, the method further includes: determining whether the object needs to circularly reference the serialization class.
[0014] Optionally, the data types include: Boolean type, byte type, character type, short integer type, integer type, floating-point type, long integer type, and double-precision type; the data type conversion includes: converting Boolean type to byte type, converting short integer type to character type, converting floating-point type to integer type, and converting double-precision type to long integer type.
[0015] Optionally, the data compression includes: obtaining the data length of intermediate data after data type conversion, and determining the data length range to which the data length belongs, wherein the data length range is set based on the converted data type; determining the storage length required for storing the intermediate data in the storage unit according to a preset mapping relationship between the data length range and the storage length; and storing the intermediate data in the storage unit for data compression.
[0016] Optionally, before storing the intermediate data in the storage unit, the method further includes: determining whether the storage unit needs to be expanded based on the storage length required for storing the intermediate data in the storage unit and the available storage space of the storage unit; and increasing the capacity of the storage unit if expansion is required.
[0017] According to a second aspect of the present invention, an apparatus for object serialization processing is provided, comprising:
[0018] The object acquisition module is used to obtain the object to be serialized and the data type of the object based on the received serialization request;
[0019] The serialization class acquisition module is used to obtain the serialization class of the object from the serialization class factory according to the data type of the object, wherein the serialization class factory stores the mapping relationship between data types and serialization classes;
[0020] The serialization processing module is used to serialize each attribute information of the object sequentially according to the object's serialization class. The serialization processing includes data type conversion and data compression. The attribute information includes attributes and attribute values.
[0021] According to a third aspect of the present invention, a mobile electronic device terminal is provided, characterized in that it comprises:
[0022] One or more processors;
[0023] Storage device for storing one or more programs.
[0024] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiments of the present invention.
[0025] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.
[0026] One embodiment of the invention has the following advantages or beneficial effects: by obtaining the object to be serialized and its data type according to the received serialization request; obtaining the object's serialization class from the serialization class factory according to the object's data type, wherein the serialization class factory stores the mapping relationship between data types and serialization classes; and performing serialization processing on each attribute information of the object sequentially according to the object's serialization class, wherein the serialization processing includes: data type conversion and data compression, and the attribute information includes attributes and attribute values. This technical solution realizes data type conversion and data compression based on the serialization class of the object to be serialized, effectively reducing the number of serialized data types, improving the serialization speed, and reducing the length of the serialized byte array, thereby reducing the cost of data storage and network transmission. Attached Figure Description
[0027] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0028] Figure 1This is a schematic diagram of the main flow of the object serialization processing method according to an embodiment of the present invention;
[0029] Figure 2 This is a schematic diagram of data compression according to an embodiment of the present invention;
[0030] Figure 3 This is a schematic diagram of the initialization of the serialization framework Jse according to an embodiment of the present invention;
[0031] Figure 4 This is a schematic diagram of the serialization process based on the JSE serialization framework in an embodiment of the present invention;
[0032] Figures 5(a), (b), (c), and (d) are schematic diagrams comparing the serialization performance based on the Jse serialization framework in the embodiments of the present invention;
[0033] Figure 6 This is a schematic diagram of the main modules of an object serialization processing apparatus according to an embodiment of the present invention;
[0034] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0035] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0036] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0037] While current serialization technologies each have their own characteristics, they all suffer from performance issues such as long serialization time and large serialized byte array lengths. In particular, when serializing large data objects, the performance of serialization drops significantly, failing to meet the needs of practical applications.
[0038] To address the aforementioned problems in the existing technology, this invention proposes a method for object serialization. Based on the serialization class of the object to be serialized, this method effectively reduces the number of data types to be serialized, improves the serialization speed, and reduces the length of the serialized byte array by converting the data type of the object and compressing the data, thereby reducing the cost of data storage and network transmission.
[0039] In the description of the embodiments of the present invention, the terms involved and their meanings are as follows:
[0040] Protostuff: A flexible and efficient protocol for serializing data;
[0041] Kryo: A mature Java object graphical serialization framework;
[0042] Hessian: A network protocol that supports dynamic typing, cross-language communication, and object-based transport.
[0043] JDK: A Java Development Kit that includes serialization functionality;
[0044] Byte[]: A data type that encapsulates a byte array (byte[]);
[0045] Jse: Java Serializer, a serialization framework proposed in this invention.
[0046] Figure 1 This is a schematic diagram of the main flow of the object serialization processing method according to an embodiment of the present invention, as shown below. Figure 1 As shown, the object serialization processing method of this embodiment of the invention includes the following steps S101 to S103.
[0047] Step S101: Based on the received serialization request, obtain the object to be serialized and the data type of the object.
[0048] According to one embodiment of the present invention, the data types include: Boolean type, byte type, character type, short integer type, integer type, floating-point type, long integer type, and double precision type.
[0049] According to another embodiment of the present invention, after obtaining the object to be serialized and the data type of the object, the method further includes: setting the starting position of the serialization result of the object in the storage unit; verifying the initial data in the storage unit and setting the initial length of the storage unit.
[0050] Specifically, after the external serialization interface obtains the object to be serialized and its corresponding data type based on the received serialization request, it sets the starting position of the serialization result of the object to be serialized in the storage unit according to business needs. For example, the storage unit for storing the serialization result is set to a byte array byte[], and the serialization result is stored starting from the 5th position of this array byte[]. The context component of the serialization platform verifies whether the initial data in the storage unit byte[] is empty and sets the initial length of the storage unit byte[] to facilitate the storage of subsequent serialization results.
[0051] Step S102: Based on the data type of the object, obtain the serialization class of the object from the serialization class factory, wherein the serialization class factory stores the mapping relationship between data types and serialization classes.
[0052] Specifically, the context component of the serialization platform obtains the serialization class of the object from the serialization class factory according to the data type of the object. The serialization class factory encapsulates the serialization classes of the data types supported by the serialization platform, and establishes a key-value pair mapping table based on the data type and the corresponding serialization class, with the data type as the key and the corresponding serialization class as the value, so as to realize serialization support for specific classes and encapsulation of serialization classes.
[0053] According to one embodiment of the present invention, if the serialization class of the object cannot be obtained from the serialization class factory, a serialization class corresponding to the object is created according to the data type of the object and saved to the serialization class factory.
[0054] Specifically, the serialization class factory is called through the class registration of the serialization platform. The serialization class of the object to be serialized is searched in the key-value pair mapping table of the serialization class factory. For objects to be serialized without serialization history, there is no serialization class stored in the serialization class factory. It is necessary to create a serialization class corresponding to the object according to the data type of the object and save it in the serialization class factory.
[0055] According to another embodiment of the present invention, creating a serialization class corresponding to the object based on the data type of the object includes: obtaining the attributes of the object; encapsulating the attributes of the object and the corresponding attribute value accessors to create a serialization class corresponding to the object.
[0056] Specifically, the serialization class factory of the serialization platform obtains the attributes of the object to be serialized. For example, if the object to be serialized is an order, its attributes include user ID, order number, order event, etc. The attributes of the object and the attribute value accessors used to access the attribute values are encapsulated, and a serialization class corresponding to the object is created to realize the concrete serialization class of the encapsulated class attributes.
[0057] According to another embodiment of the present invention, after obtaining the serialization class of the object from the serialization class factory, the method further includes: determining whether the object needs to circularly reference the serialization class.
[0058] Specifically, the context component of the serialization platform determines whether the object to be serialized is a circular reference by checking the serialization history of the attribute objects in the object to be serialized. For example, if an object contains a reference to itself, and it is a circular reference, the serialization platform's circular reference mechanism is invoked to obtain the attribute information of the object to be serialized.
[0059] Step S103: According to the serialization class of the object, serialize each attribute information of the object in sequence, wherein the serialization process includes: data type conversion and data compression, and the attribute information includes attributes and attribute values.
[0060] Specifically, according to the serialization class of the object, each attribute information of the object to be serialized is serialized sequentially, and the attribute information includes the attribute and the attribute value.
[0061] According to one embodiment of the present invention, the data type conversion includes: converting a boolean type to a byte type, converting a short integer type to a character type, converting a floating-point type to an integer type, and converting a double-precision type to a long integer type.
[0062] Specifically, the data types include Boolean, byte, character, short integer, integer, floating-point, long integer, and double-precision types. Boolean and byte types have a byte length of 1, character and short integer types have a byte length of 2, integer and floating-point types have a byte length of 4, and long integer and double-precision types have a byte length of 8. Based on occupying the same byte length, data types can be divided into four categories: byte / Boolean, character / short integer, integer / floating-point, and long integer / double-precision. Correspondingly, when serializing these data types, only these four data types need to be processed. By converting Boolean to byte, short integer to character, floating-point to integer, and double-precision to long integer, the number of data types is halved, significantly reducing the amount of code, processing complexity, and improving serialization efficiency.
[0063] In addition, the above data type conversion also supports the conversion of special types. It can convert the Byte[] data type to the byte[] type according to business needs, so that the method of the present invention can be applied to personalized serialization needs and the serialization function is more comprehensive.
[0064] According to another embodiment of the present invention, the data compression includes: obtaining the data length of intermediate data after data type conversion, and determining the data length range to which the data length belongs, wherein the data length range is set based on the converted data type; determining the storage length required for storing the intermediate data in the storage unit according to a preset mapping relationship between the data length range and the storage length; and storing the intermediate data in the storage unit for data compression.
[0065] According to another embodiment of the present invention, before storing the intermediate data in the storage unit, the method further includes: determining whether the storage unit needs to be expanded based on the storage length required for storing the intermediate data in the storage unit and the available storage space of the storage unit; if expansion is required, increasing the capacity of the storage unit. The available storage space of the storage unit can be obtained by subtracting the current total storage space of the storage unit from the already stored space.
[0066] Specifically, based on the data type conversions described above, the converted data types are byte type, character type, integer type, and long integer. The maximum data length range for long integers is 8 bytes. Starting from the 8-byte range (the maximum range), the length decreases by 1 byte sequentially until a 1-byte range is reached, resulting in a total of 8 different data length ranges. Since the serialization result is ultimately stored as a byte type, byte type data does not require compression. Similarly, boolean types can be represented using 0 / 1 and can be directly converted to byte types, so byte / boolean types do not require compression. Therefore, the effective data types after data type conversion are only three: integer type, character type, and long integer. The process involves obtaining the data length of the intermediate data after data type conversion, determining the data length range to which the intermediate data belongs based on the eight different data length ranges mentioned above, establishing a mapping relationship between data length ranges and storage lengths based on the byte lengths corresponding to the eight different data length ranges, and determining the actual storage length required for the intermediate data to be stored in the serialization result storage unit. Based on the required storage length for the intermediate data in the storage unit, and considering the available storage space of the storage unit, if the available storage space cannot meet the required storage length for the intermediate data, the storage unit is expanded to meet the storage requirements of the intermediate data. Finally, the intermediate data is stored in the storage unit for data compression.
[0067] The data compression described above further reduces the types of data being serialized, effectively shortens the length of the serialized byte array, reduces serialization time, and improves serialization performance.
[0068] Figure 2This is a data compression diagram according to an embodiment of the present invention. According to this embodiment, after data type conversion, only integer type `int`, character type `char`, and long integer type `long` need to be compressed. The `byteArray` interface defines the attributes and access permissions related to the serialization result storage unit `byte[]` array. `InternalbyteArray` completes the serialization data compression work for integer type `int`, character type `char`, and long integer type `long`, and stores the serialization result in the byte array of `byteArray`. In the diagram, the range of `i` represents the data length interval. Different data length intervals correspond to different storage lengths, which is the preset mapping relationship between data length intervals and storage lengths. The longest storage length is 8 bytes, and the shortest storage length is 1 byte. For the `int` type, the longest storage length is 4 bytes. Based on the data length of the intermediate data, the data length interval to which the intermediate data belongs is determined, thereby determining the storage length required for the intermediate data to be stored in the storage unit. The same applies to the `long` and `char` types, which will not be elaborated further here. For example, if the intermediate data is of type int and the data value is 201, the value of i represents the numerical range corresponding to the data length of 8, 16, 24, and 32 bits respectively. The data value 201 belongs to i<=255, so 2 bytes can be used as the storage length.
[0069] According to another embodiment of the present invention, after serializing each attribute information, the method further includes: saving the serialization result corresponding to each attribute information to the storage unit in sequence according to the starting position.
[0070] Specifically, after serializing each attribute information, the serialization result of each attribute information needs to be saved in the serialization result storage unit. Based on the starting position of the serialization result of the object in the storage unit, the serialization result corresponding to each attribute information is saved sequentially according to the order of appearance of each attribute information within the object. Preferably, the serialization result of each attribute information is stored in the serialization result storage unit contiguously with the serialization results of the attribute information preceding and following it. For example, if the serialized object includes attribute information 1, attribute information 2, and attribute information 3, then the corresponding serialization result storage attributes are serialization sub-result 1, serialization sub-result 2, and serialization sub-result 3.
[0071] Typically, the serialization methods described above are implemented based on serialization frameworks on serialization platforms. This invention uses the independently developed serialization framework Jse for serialization. Furthermore, the Jse serialization framework not only supports serialization of objects to be serialized but also supports deserialization of byte streams. The execution of deserialization is similar to the above process; the deserialization result can be obtained by performing the reverse process of data compression and data type conversion during serialization.
[0072] Figure 3 This is a schematic diagram of the initialization of the JSE serialization framework according to an embodiment of the present invention. The JSE framework includes several modules such as the JSE interface, JSE context, serialization class factory, and class registration. JSE initialization is implemented through the JSE interface, which initializes the JSE context. The serialization class factory is mainly responsible for supporting the serialization of specific classes and encapsulating serialization classes. It initializes the serialization class table, encapsulating the supported serialization classes into the table. The serialization class table uses data type as the key and serialization class as the value. The initialization process is concise, efficient, and easily expandable for subsequent initialization. Following the completion of the serialization class factory initialization... The initialization class registration is mainly responsible for the encapsulation and abstraction of the specific serialization class of the class to be serialized. It constructs a class container for specific serialization methods of data types supported by the JSE framework through a mapping interface. The class registration obtains the serialization class from the serialization class factory according to the initialization result of the serialization class factory to match the specific serialization class of the object to be serialized. If the serialization class of the object to be serialized is not found in the serialization class table of the serialization class factory, a mapping interface is created according to the object to be serialized to encapsulate the attributes and attribute value accessors of the serialization class corresponding to the object to be serialized. The encapsulation of the attributes of the class to be serialized is completed by a third-party JAR toolkit.
[0073] Figure 4This is a schematic diagram of the serialization process based on the JSE serialization framework in an embodiment of the present invention. The serialization interface JSE determines whether the object to be serialized is empty according to the user's serialization request. If the object to be serialized is not empty, it sets the starting position of the serialization result of the object to be serialized in the storage unit byte[]. As the serialization platform, the JSE context, which coordinates the relationship between the serialization class factory and the class registration, verifies the byte[] array parameter and obtains the mapping interface of the class registration. If the mapping interface of the class registration is not successfully obtained, and there is no serialization class in the serialization class table, the serialization class is initialized according to the type to be serialized, the mapping interface is created to obtain the specific serialization class of the object to be serialized, and it is determined whether the object to be serialized is a circular reference. Here, a non-circular reference is used for explanation. The logic for circular reference is the same. For the case of non-circular reference, the serialization index is stored according to the starting position of the byte[] set by the serialization interface. The attribute information of the object to be serialized is obtained in a loop, and the attribute information of the object to be serialized is started. Through data type conversion and data compression, the serialization result of the object to be serialized is obtained, and the task is completed.
[0074] Figures 5(a), (b), (c), and (d) are schematic diagrams comparing the serialization performance of the JSE serialization framework according to embodiments of the present invention. Figures 5(a) and (b) compare the size and serialization speed of the serialized bitstream for small data objects, respectively, while Figures 5(c) and (d) compare the size and serialization speed of the serialized bitstream for large data objects, respectively. The comparison shows that serialization based on the JSE serialization framework not only produces smaller serialized bitstreams but also achieves faster serialization speeds, outperforming existing serialization frameworks. Especially for the serialization of large data objects, serialization based on the JSE serialization framework exhibits a greater performance advantage.
[0075] Figure 6 This is a schematic diagram of the main modules of an object serialization processing apparatus according to an embodiment of the present invention. Figure 6 As shown, the object serialization processing device 600 mainly includes an object acquisition module 601, a serialization class acquisition module 602, and a serialization processing module 603.
[0076] The object acquisition module 601 is used to acquire the object to be serialized and the data type of the object according to the received serialization request;
[0077] The serialization class acquisition module 602 is used to acquire the serialization class of the object from the serialization class factory according to the data type of the object, wherein the serialization class factory stores the mapping relationship between data types and serialization classes;
[0078] The serialization processing module 603 is used to serialize each attribute information of the object sequentially according to the serialization class of the object, wherein the serialization processing includes: data type conversion and data compression, and the attribute information includes attributes and attribute values.
[0079] Specifically, the object serialization processing apparatus 600 further includes an initial setting module (not shown in the figure), used to set the starting position of the serialization result of the object in the storage unit after obtaining the object to be serialized and the data type of the object; verify the initial data in the storage unit and set the initial length of the storage unit; and specifically, the object serialization processing apparatus 600 also includes a result storage module (not shown in the figure), used to: after serializing each attribute information, sequentially save the serialization result corresponding to each attribute information into the storage unit according to the starting position.
[0080] Specifically, the object serialization processing apparatus 600 may further include a serialization class creation module (not shown in the figure), used to: create a serialization class corresponding to the object according to the data type of the object and save it to the serialization class factory if the serialization class of the object cannot be obtained from the serialization class factory.
[0081] Specifically, the serialization class creation module (not shown in the figure) can also be used to: obtain the attributes of the object; encapsulate the attributes of the object and the corresponding attribute value accessors, and create a serialization class corresponding to the object.
[0082] Specifically, the object serialization processing apparatus 600 may further include a loop determination module (not shown in the figure) for determining whether the object should circularly reference the serialization class after obtaining the serialization class of the object from the serialization class factory.
[0083] Specifically, the data types include: Boolean type, byte type, character type, short integer type, integer type, floating-point type, long integer type, and double-precision type; the data type conversions include: converting Boolean type to byte type, converting short integer type to character type, converting floating-point type to integer type, and converting double-precision type to long integer type.
[0084] Specifically, the data compression includes: obtaining the data length of intermediate data after data type conversion, and determining the data length range to which the data length belongs, wherein the data length range is set based on the converted data type; determining the storage length required for storing the intermediate data in the storage unit according to a preset mapping relationship between the data length range and the storage length; and storing the intermediate data in the storage unit for data compression.
[0085] Specifically, the object serialization processing apparatus 600 may further include a capacity determination module (not shown in the figure), used to: before storing the intermediate data in the storage unit, determine whether the storage unit needs to be expanded based on the storage length required for storing the intermediate data in the storage unit and the available storage space of the storage unit; if expansion is required, increase the capacity of the storage unit.
[0086] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied.
[0087] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0088] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as serialization applications and serialization processing applications (for example only).
[0089] Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0090] Server 705 can be a server providing various services, such as a background management server (for example only) supporting serialization performed by users using terminal devices 701, 702, and 703. The background management server can obtain the object to be serialized and its data type based on the received serialization request; based on the object's data type, it obtains the object's serialization class from a serialization class factory, where the serialization class factory stores the mapping relationship between data types and serialization classes; based on the object's serialization class, it sequentially performs serialization processing on each attribute information of the object, where the serialization processing includes data type conversion and data compression, the attribute information includes the processing of attributes and attribute values, and feeds back the processing result (e.g., serialization result – for example only) to the terminal device.
[0091] It should be noted that the object serialization processing method provided in the embodiments of the present invention is generally executed by server 705, and correspondingly, the object serialization processing device is generally set in server 705.
[0092] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0093] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing terminal devices or servers of the present invention. Figure 8 The terminal device or server shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0094] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0095] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0096] In particular, according to embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.
[0097] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wireline, optical fiber, RF, etc., or any suitable combination thereof.
[0098] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0099] The units described in the embodiments of the present invention can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor can be described as including: an object acquisition module, a serialization class acquisition module, and a serialization processing module.
[0100] In some cases, the names of these modules do not constitute a limitation on the module itself. For example, the object acquisition module can also be described as "a module for acquiring the object to be serialized and the data type of the object based on the received serialization request".
[0101] On the other hand, the present invention also provides a computer-readable medium, which may be included in the device described in the embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: obtaining an object to be serialized and the data type of the object according to a received serialization request; obtaining the serialization class of the object from a serialization class factory according to the data type of the object, wherein the serialization class factory stores a mapping relationship between data types and serialization classes; and sequentially serializing each attribute information of the object according to the serialization class of the object, wherein the serialization process includes: data type conversion and data compression, and the attribute information includes attributes and attribute values.
[0102] According to the technical solution of the present invention, the following advantages or beneficial effects are achieved: by obtaining the object to be serialized and the data type of the object according to the received serialization request; obtaining the serialization class of the object from the serialization class factory according to the data type of the object, wherein the serialization class factory stores the mapping relationship between data types and serialization classes; and performing serialization processing on each attribute information of the object in sequence according to the serialization class of the object, wherein the serialization processing includes: data type conversion and data compression, and the attribute information includes attributes and attribute values. This technical solution realizes data type conversion and data compression based on the serialization class of the object to be serialized, effectively reducing the number of serialized data types, improving the serialization speed, reducing the length of the serialized byte array, thereby reducing the cost of data storage and network transmission.
[0103] The specific embodiments described herein do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for object serialization processing, characterized in that, include: Based on the received serialization request, obtain the object to be serialized and the data type of the object; Based on the data type of the object, the serialization class of the object is obtained from the serialization class factory, wherein the serialization class factory stores the mapping relationship between data types and serialization classes; According to the serialization class of the object, each attribute information of the object is serialized in sequence, wherein the serialization process includes: data type conversion and data compression, and the attribute information includes attributes and attribute values; The data types include: Boolean type, byte type, character type, short integer type, integer type, floating-point type, long integer type, and double precision type; the data type conversions include: converting Boolean type to byte type, short integer type to character type, floating-point type to integer type, and double precision type to long integer type; The data compression includes: obtaining the data length of intermediate data after data type conversion, and determining the data length range to which the data length belongs, wherein the data length range is set based on the converted data type; determining the storage length required for storing the intermediate data in the storage unit according to the preset mapping relationship between the data length range and the storage length; storing the intermediate data in the storage unit for data compression; wherein, byte types do not need to be compressed.
2. The method according to claim 1, characterized in that, After obtaining the object to be serialized and the data type of the object, the process also includes: Set the starting position of the serialization result of the object in the storage unit; Verify the initial data within the storage unit and set the initial length of the storage unit; After serializing each attribute information, the process also includes: The serialization results corresponding to each attribute information are sequentially saved to the storage unit according to the starting position.
3. The method according to claim 1, characterized in that, The method further includes: If the serialization class of the object cannot be obtained from the serialization class factory, a serialization class corresponding to the object is created according to the data type of the object and saved to the serialization class factory.
4. The method according to claim 3, characterized in that, Create a serialization class corresponding to the object based on the object's data type, including: Get the properties of the object; The object's attributes and corresponding attribute value accessors are encapsulated to create a serialization class corresponding to the object.
5. The method according to claim 1, characterized in that, After obtaining the serialization class of the object from the serialization class factory, the process also includes: Determine whether the object should circularly reference the serialized class.
6. The method according to claim 1, characterized in that, Before storing the intermediate data in the storage unit, the method further includes: Based on the storage length required for the intermediate data to be stored in the storage unit and the available storage space of the storage unit, determine whether the storage unit needs to be expanded; If expansion is required, the capacity of the storage unit shall be increased.
7. An apparatus for object serialization processing, characterized in that, include: The object acquisition module obtains the object to be serialized and the data type of the object based on the received serialization request; The serialization class acquisition module obtains the serialization class of the object from the serialization class factory according to the data type of the object, wherein the serialization class factory stores the mapping relationship between data types and serialization classes; The serialization processing module serializes each attribute information of the object sequentially according to the object's serialization class. The serialization processing includes data type conversion and data compression. The attribute information includes attributes and attribute values. The data types include: Boolean type, byte type, character type, short integer type, integer type, floating-point type, long integer type, and double precision type; the data type conversions include: converting Boolean type to byte type, short integer type to character type, floating-point type to integer type, and double precision type to long integer type; The data compression includes: obtaining the data length of intermediate data after data type conversion, and determining the data length range to which the data length belongs, wherein the data length range is set based on the converted data type; determining the storage length required for storing the intermediate data in the storage unit according to the preset mapping relationship between the data length range and the storage length; storing the intermediate data in the storage unit for data compression; wherein, byte types do not need to be compressed.
8. A mobile electronic device terminal, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-6.
9. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.