A byte stream data conversion method, device, equipment and storage medium
By using an automated byte stream data conversion method to obtain and set model attributes, and to read and assign data based on length information, the problem of large code volume and errors caused by manual coding is solved, thus improving conversion efficiency and accuracy.
Patent Information
- Application Number
- CN202111521880.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2041-12-13
AI Technical Summary
In existing technologies, manual encoding methods involve a large amount of code, a heavy workload, and are prone to errors, resulting in low efficiency and poor accuracy in byte stream data conversion.
By obtaining the attribute list of the byte stream data packet, determining the attributes and setting the model attributes, and reading and assigning data according to the length information, the automatic deserialization and serialization process is realized.
It improves program development efficiency, reduces the probability of errors, enhances program robustness and fault tolerance, and reduces maintenance costs.
Smart Images

Figure CN114169292B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a byte stream data conversion method, apparatus, device, and storage medium. Background Technology
[0002] In software development, it's often necessary to convert byte stream data packets sent from the server into business model classes. Currently, this conversion is generally done manually. Traditional manual encoding requires developers to sequentially read the corresponding length of byte stream data from the data packet based on the data type and size of each attribute, and then assign the values of the byte stream data to the model class. However, this manual encoding method results in a large amount of code, a significant workload, and is prone to encoding errors. Summary of the Invention
[0003] This application provides a byte stream data conversion method, apparatus, device, and storage medium to address the issues of large code volume, heavy coding workload, and easy coding errors in the existing manual coding method, thereby improving the conversion efficiency and accuracy of byte stream data conversion.
[0004] In a first aspect, embodiments of this application provide a byte stream data conversion method, including:
[0005] Obtain the first type of attribute list of the byte stream data packet, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list;
[0006] Set the second attribute contained in the first model according to the first attribute;
[0007] Determine the first length information corresponding to each of the first attributes;
[0008] Based on the first length information, first byte data of the corresponding length of each of the first attributes is read from the byte stream data packet, and the value corresponding to the first byte data is assigned to the corresponding second attribute.
[0009] In a second aspect, embodiments of this application provide a byte stream data conversion device, including a first attribute acquisition module, a first model configuration module, a first length acquisition module, and a first data conversion module, wherein:
[0010] The first attribute acquisition module is used to acquire a first type of attribute list of byte stream data packets, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list;
[0011] The first model configuration module is used to set the second attribute contained in the first model according to the first attribute;
[0012] The first length acquisition module is used to determine the first length information corresponding to each of the first attributes;
[0013] The first data conversion module is used to read the first byte data of the corresponding length of each of the first attributes from the byte stream data packet according to the first length information, and assign the value corresponding to the first byte data to the corresponding second attribute.
[0014] This application embodiment obtains a first type of attribute list of byte stream data packets, determines the first attributes contained in the first type of attribute list, sets the second attributes contained in the first model according to the first attributes, reads the first byte data of the corresponding length from the byte stream data packets according to the first length information corresponding to each first attribute, and determines the value of each second attribute in the first model according to the first byte data, thus completing the automatic deserialization process of the byte stream data packets. It eliminates the need to manually write deserialization code, improves program development efficiency, reduces the probability of errors by developers, enhances program robustness and fault tolerance, and reduces the maintenance cost of program code.
[0015] In a third aspect, embodiments of this application provide another byte stream data conversion method, including:
[0016] Obtain the second category of attribute list of the second model, traverse the second category of attribute list, and determine the third attribute contained in the second category of attribute list;
[0017] Determine the second length information corresponding to each of the third attributes;
[0018] Based on the second length information, model data of the corresponding length of each of the third attributes is read from the second model, and the binary data corresponding to the model data is written to the cache area;
[0019] Generate byte stream data packets based on the binary data in the cache area.
[0020] In a fourth aspect, embodiments of this application provide another byte stream data conversion apparatus, including a second attribute acquisition module, a second length acquisition module, a second data conversion module, and a data packet generation module, wherein:
[0021] The second attribute acquisition module is used to acquire the second type of attribute list of the second model, traverse the second type of attribute list, and determine the third attribute contained in the second type of attribute list;
[0022] The second length acquisition module is used to determine the second length information corresponding to each of the third attributes;
[0023] The second data conversion module is used to read model data of the corresponding length of each of the third attributes from the second model according to the second length information, and write the binary data corresponding to the model data to the cache area;
[0024] The data packet generation module is used to generate byte stream data packets based on the binary data in the cache area.
[0025] In a fifth aspect, embodiments of this application provide a byte stream data conversion device, including: a memory and one or more processors;
[0026] The memory is used to store one or more programs;
[0027] When the one or more programs are executed by the one or more processors, the one or more processors implement the byte stream data conversion method as described in the first or third aspect.
[0028] In a sixth aspect, embodiments of this application provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the byte stream data conversion method as described in the first or third aspect.
[0029] This application embodiment obtains a second type of attribute list of byte stream data packets, determines the third attribute contained in the second type of attribute list, reads model data of the corresponding length from the second model according to the second length information corresponding to each third attribute, writes the binary data corresponding to the model data to the buffer area, and generates byte stream data packets based on the binary data in the buffer area, thus completing the automatic serialization process of byte stream data packets. It eliminates the need to manually write serialization code, improves program development efficiency, reduces the probability of errors by developers, enhances program robustness and fault tolerance, and reduces the maintenance cost of program code. Attached Figure Description
[0030] Figure 1 This is a flowchart of a byte stream data conversion method provided in an embodiment of this application;
[0031] Figure 2 This is a flowchart of another byte stream data conversion method provided in the embodiments of this application;
[0032] Figure 3 This is a schematic diagram of the structure of a byte stream data conversion device provided in an embodiment of this application;
[0033] Figure 4 This is a flowchart of another byte stream data conversion method provided in the embodiments of this application;
[0034] Figure 5 This is a schematic diagram of another byte stream data conversion device provided in an embodiment of this application;
[0035] Figure 6 This is a schematic diagram of the structure of a byte stream data conversion device provided in an embodiment of this application. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0037] Figure 1 A flowchart of a byte stream data conversion method provided in this application embodiment is given. The byte stream data conversion method provided in this application embodiment can be executed by a byte stream data conversion device, which can be implemented by hardware and / or software and integrated into a byte stream data conversion device.
[0038] The following description uses a byte stream data conversion device to perform a byte stream data conversion method as an example. (Reference) Figure 1 The byte stream data conversion method includes:
[0039] S101: Obtain the first type of attribute list of the byte stream data packet, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list.
[0040] It needs to be explained that after receiving the byte stream data packet (ByteBuffer) sent by the server, the value corresponding to the binary byte stream data packet needs to be mapped into the model, that is, the byte stream data packet is deserialized (equivalent to the process of unpacking the byte stream data packet).
[0041] For example, after receiving a byte stream data packet, this solution obtains the first type of attribute list of the byte stream data packet (e.g., the attribute list of a Swift class based on the iOS system) through runtime tools. This first type of attribute list records the attributes contained in the byte stream data packet and the type information of each attribute (numeric type, built-in type, custom type, and collection type, etc.). Further, the first type of attribute list is traversed to determine the first attribute contained within it.
[0042] The data type corresponding to the first attribute includes one or more combinations of numeric types, built-in types, custom types, and collection types. Custom types can contain one or more combinations of numeric types and built-in types. Collection types can be one or more combinations of numeric types (e.g., Int8, Int32, Float, Double, etc.), built-in types (e.g., String, Data, etc.), and custom types (custom object types, CustomClassType). This solution provides collection types that support deep nesting of different data types, and the basic data types (including numeric types, built-in types, and custom types) extend the serialization and deserialization processes. Furthermore, the model provided in this embodiment supports obtaining the number of characters occupied by various data types, has the ability to fill its own data into a given data buffer, and read data from a given data buffer into the model itself.
[0043] S102: Set the second attribute contained in the first model according to the first attribute.
[0044] For example, upon receiving a byte stream data packet and needing to map it into a model, a first model is created. After determining the first attributes included in the first category attribute list, the second attributes included in the first model are set in the order they appear in the first category attribute list. It is understood that the values of each second attribute in the first model are default values at this time. The first model can be established after receiving the byte stream data packet from the server or before reading the first byte of data from the byte stream data packet; this solution does not impose any limitations.
[0045] S103: Determine the first length information corresponding to each first attribute.
[0046] In this byte stream data packet, the various types of byte stream data are stored according to a defined data storage protocol. That is, the storage method and data structure of the data corresponding to each attribute are saved according to the defined data storage structure. The byte stream data packet includes a header and a body. The header consists of a 4-byte total packet length, a 4-byte protocol number (reflecting the data storage protocol followed by the byte stream data packet), and a 2-byte response code. The body stores the data corresponding to each attribute sequentially according to the data storage rules defined by the data storage protocol.
[0047] For example, after determining the first attribute contained in the first category attribute list, the first length information of the corresponding data is further calculated according to the data storage rules corresponding to each first attribute in the first category attribute list.
[0048] S104: Based on the first length information, read the first byte data of the corresponding length of each first attribute from the byte stream data packet, and assign the value corresponding to the first byte data to the corresponding second attribute.
[0049] For example, after determining the first length information corresponding to each first attribute, the first byte data is sequentially obtained from the byte stream data packet according to the order of each first attribute in the first attribute list, and the value corresponding to the first byte data is assigned to the corresponding second attribute in the first model. The length of the first byte data is consistent with the first length information of the corresponding first attribute; that is, what is extracted from the byte stream data packet is the data corresponding to the first attribute.
[0050] As described above, by obtaining the first type of attribute list of the byte stream data packet, determining the first attribute contained in the first type of attribute list, setting the second attribute contained in the first model according to the first attribute, reading the first byte data of the corresponding length from the byte stream data packet according to the first length information corresponding to each first attribute, and determining the value of each second attribute in the first model according to the first byte data, the automatic deserialization process of the byte stream data packet is completed. There is no need to manually write deserialization code, which improves the development efficiency of the program, reduces the error probability of developers, improves the robustness and fault tolerance of the program, and reduces the maintenance cost of the program code.
[0051] Based on the above embodiments, Figure 2 A flowchart of another byte stream data conversion method provided in an embodiment of this application is given, which is a specific embodiment of the above-described byte stream data conversion method. (Reference) Figure 2 The byte stream data conversion method includes:
[0052] S201: Obtain the first type of attribute list of the byte stream data packet, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list.
[0053] S202: Set the second attribute contained in the first model according to the first attribute.
[0054] S203: Determine the first length information corresponding to each first attribute.
[0055] The data type corresponding to the first attribute provided in this embodiment can be one or more combinations of numeric type, built-in type, custom type and collection type. Since different data types have different access rules in byte stream data packets, it is necessary to deserialize the byte data corresponding to different first attributes according to the specific data type.
[0056] Specifically, each first attribute in the first attribute list is traversed in the order of the first attribute in the first attribute list to determine the data type corresponding to each first attribute, and the first length information corresponding to each first attribute is determined according to the data access rules corresponding to the data type. Based on this, this embodiment includes at least one of the following when determining the first length information corresponding to each first attribute:
[0057] S2031: When the first attribute is a numeric type, obtain the first length information corresponding to the first attribute through memory layout.
[0058] When the data type of the first attribute is numeric, the first length information corresponding to the first attribute is obtained through memory layout. Since the memory usage of numeric types is fixed, this solution can use the data size (size) acquisition method provided by the system's memory layout tool to obtain the size of the data corresponding to the first attribute in bytes within the byte stream data packet. This size of bytes occupied is the first length information corresponding to the first attribute.
[0059] S2032: When the first attribute is a built-in type, determine the first length information corresponding to the first attribute based on the data length and the identifier length corresponding to the first attribute.
[0060] Specifically, when the first attribute is a built-in type, the data length and the identifier length (i.e., the value that identifies the data length, for example, the identifier length of string and data types is generally 2) of the data corresponding to the first attribute are determined. The sum of the data length and the identifier length is the first length information corresponding to the first attribute.
[0061] S2033: When the first attribute is a custom type, determine the first data length corresponding to the data type contained in the first attribute, and determine the first length information corresponding to the first attribute based on the first data length.
[0062] The custom type includes one or more combinations of the numeric type and built-in type mentioned above. Specifically, when the data type of the first attribute is a custom type, since the data types contained in the custom type are composed of the numeric type and / or built-in type provided above, the first data length of each data type can be obtained according to the data length acquisition method of the corresponding data type. The sum of all the first data lengths is the first length information corresponding to the first attribute.
[0063] S2034: When the first attribute is a collection type, determine the second data length corresponding to the data type contained in the first attribute, and determine the first length information corresponding to the first attribute based on the second data length.
[0064] The collection type includes one or more combinations of the numeric type, built-in type, and custom type mentioned above, and supports deep nesting of different data types. Specifically, when the data type of the first attribute is a collection type, since the data types contained in the collection type are composed of one or more of the numeric type, built-in type, and custom type provided above, each data type in the collection type can be traversed, and the second data length of each data type can be obtained by using the corresponding data length acquisition method. The sum of all the second data lengths is the first length information corresponding to the first attribute.
[0065] S204: Based on the first length information, allocate memory space in the first model for the corresponding second attribute to store the value corresponding to the first byte of data.
[0066] Understandably, after creating the first model and setting the second attributes contained in the first model, since the attribute information of each second attribute is a default value, this solution allocates memory space of the corresponding length for the corresponding second attribute according to the first length information after determining the length information of each first attribute, so as to facilitate the storage of the value corresponding to the first byte of data in the future.
[0067] Specifically, after determining the first length information of each first attribute, according to the correspondence between each second attribute and the first attribute in the first model, memory space is allocated for each second attribute according to the first length information to store the value corresponding to the first byte of data extracted subsequently.
[0068] S205: Based on the first length information, read the first byte data of the corresponding length of each first attribute from the byte stream data packet, and assign the value corresponding to the first byte data to the corresponding second attribute.
[0069] Specifically, following the order of the first attributes in the first attribute list, each first attribute in the first attribute list is traversed, and the first byte of data corresponding to the length of each first attribute is read sequentially from the byte stream data packet. The value corresponding to the first byte of data is then assigned to the corresponding second attribute. Based on this, this embodiment, when determining the value of each second attribute based on the first byte data, specifically includes:
[0070] S2051: When the first attribute is a numeric type or a built-in type, assign the first value corresponding to the first byte of data to the corresponding second attribute.
[0071] S2052: When the first property is a custom type or a collection type, iterate through the second values corresponding to the data types contained in the first property, and assign the second values to the data types corresponding to the second property in turn.
[0072] Specifically, when the data type of the first attribute is a numeric type or a built-in type, the first number corresponding to the extracted first byte data can be directly assigned to the corresponding second attribute in the first model.
[0073] When the data type of the first attribute is a custom type, since the data types contained in the custom type are composed of the numeric types and / or built-in types provided above, the second value corresponding to the numeric type or built-in type contained in the custom type can be calculated respectively, and the second value can be assigned to the numeric type or built-in type in the second attribute respectively.
[0074] When the data type of the first attribute is a collection type, since the data types contained in the collection type consist of one or more of the numeric types, built-in types and custom types provided above, the second value corresponding to the numeric type, built-in type or custom type contained in the collection type can be calculated respectively, and the second value can be assigned to the numeric type, built-in type or custom type in the second attribute respectively.
[0075] The collection types provided in this embodiment are generally for collections such as arrays and dictionaries. Each element in the collection satisfies the data storage protocol set in this solution, thus the collection type has the ability to automatically deserialize. Each element in the collection type is one of the numeric type, built-in type, and user-defined type. These data types all have read and write caching capabilities. Therefore, for the collection type, by traversing the elements inside the collection and calling the corresponding data deserialization method based on the data storage protocol of the element, the deserialization function of the entire collection can be realized. For example, for the array Array[Int], traversing the array Array, each element in the array Array is an Int type, and based on the set Int type read and write methods, the corresponding data can be read from the corresponding cache space.
[0076] After assigning the second value corresponding to each first attribute to the second attribute, the mapping transformation from byte stream data packet to model is completed, and the model can be applied to the next step of the workflow.
[0077] The above describes an automatic deserialization process for byte stream data packets. By obtaining a list of first-class attributes from the byte stream data packet, determining the first attributes contained within that list, setting the second attributes contained in the first model based on the first attributes, and reading the first byte data of the corresponding length from the byte stream data packet according to the first length information corresponding to each first attribute, the system determines the values of each second attribute in the first model based on the first byte data. This allows developers to focus on business logic without manually writing deserialization code, improving development efficiency, reducing the probability of errors, enhancing program robustness and fault tolerance, and alleviating maintenance costs. Furthermore, by calculating the first data length in the byte stream data packet based on the data storage rules corresponding to the data type of the first attribute, the system more accurately extracts the first byte data of the corresponding length from the byte stream data packet. Finally, by determining the assignment method for the second attribute based on the data type of the first attribute, the system more accurately assigns the first byte data in the byte stream data packet to the corresponding data type.
[0078] Figure 3 This is a schematic diagram of the structure of a byte stream data conversion device provided in an embodiment of this application. (Reference) Figure 3 The byte stream data conversion device includes a first attribute acquisition module 31, a first model configuration module 32, a first length acquisition module 33, and a first data conversion module 34.
[0079] The first attribute acquisition module 31 is used to acquire a first type of attribute list of the byte stream data packet, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list; the first model configuration module 32 is used to set the second attribute contained in the first model according to the first attribute; the first length acquisition module 33 is used to determine the first length information corresponding to each first attribute; and the first data conversion module 34 is used to read the first byte data of the length corresponding to each first attribute from the byte stream data packet according to the first length information, and assign the value corresponding to the first byte data to the corresponding second attribute.
[0080] As described above, by obtaining the first type of attribute list of the byte stream data packet, determining the first attribute contained in the first type of attribute list, setting the second attribute contained in the first model according to the first attribute, reading the first byte data of the corresponding length from the byte stream data packet according to the first length information corresponding to each first attribute, and determining the value of each second attribute in the first model according to the first byte data, the automatic deserialization process of the byte stream data packet is completed. This allows developers to focus on business logic without having to manually write deserialization code, improving program development efficiency, reducing the probability of errors by developers, enhancing program robustness and fault tolerance, and reducing the maintenance cost of program code.
[0081] Figure 4 A flowchart of another byte stream data conversion method provided in the embodiments of this application is given. The byte stream data conversion method provided in the embodiments of this application can be executed by a byte stream data conversion device, which can be implemented by hardware and / or software and integrated into a byte stream data conversion device.
[0082] The following description uses a byte stream data conversion device to perform a byte stream data conversion method as an example. (Reference) Figure 4 The byte stream data conversion method includes:
[0083] S301: Obtain the list of second-class attributes of the second model, traverse the list of second-class attributes, and determine the third attribute contained in the list of second-class attributes.
[0084] It needs to be explained that when data from the model needs to be sent to the server, the data in the model needs to be packaged into a binary data packet. That is, the model needs to be serialized (equivalent to the archiving process of the model) to obtain a binary byte stream data packet, and then the byte stream data packet is sent to the server.
[0085] For example, a second model that needs to provide data to the server is determined. A second-class attribute list (e.g., the attribute list of a Swift class based on the iOS system) is obtained using runtime tools. This second-class attribute list records the attributes contained in the second model and the type information of each attribute. Further, the third attribute contained in the second-class attribute list is determined by traversing the second-class attribute list.
[0086] The data type corresponding to the third attribute includes one or more combinations of numeric types, built-in types, custom types, and collection types. Custom types can contain one or more combinations of numeric types and built-in types, and collection types can be one or more combinations of numeric types, built-in types, and custom types. The collection types provided in this solution support deep nesting of different data types, and the basic data types (including numeric types, built-in types, and custom types) extend the serialization and deserialization processes. Furthermore, the model provided in this embodiment supports obtaining the number of characters occupied by various data types, has the ability to fill its own data into a given data cache range, and read data from a given data cache range into the model itself.
[0087] S302: Determine the second length information corresponding to each third attribute.
[0088] In the second model, the model data of each type is stored according to the set data storage protocol, that is, the storage method and data structure of the data corresponding to various attributes are saved according to the set data storage structure.
[0089] For example, after determining the third attribute contained in the second category of attribute list, the second length information of the corresponding model data is further calculated according to the data storage rules corresponding to each third attribute in the second category of attribute list.
[0090] The data type corresponding to the third attribute provided in this embodiment can be one or more combinations of numeric type, built-in type, custom type and collection type. Since the access rules of different data types in the second model are different, it is necessary to serialize the model data corresponding to different third attributes according to the specific data type.
[0091] Specifically, each third attribute in the second category of attribute list is traversed in the order of the third attributes in the second category of attribute list to determine the data type corresponding to each third attribute, and the second length information corresponding to each third attribute is determined according to the data access rules corresponding to the data type. Based on this, this embodiment includes at least one of the following when determining the second length information corresponding to each third attribute:
[0092] S3021: When the third attribute is a numeric type, obtain the second length information corresponding to the third attribute through memory layout.
[0093] When the data type of the first attribute is numeric, the first length information corresponding to the first attribute is obtained through memory layout. Since the memory usage of numeric types is fixed, this solution can use the data size acquisition method provided by the system's memory layout tool to obtain the size of the data corresponding to the first attribute in bytes within the byte stream data packet. This size of bytes occupied is the first length information corresponding to the first attribute.
[0094] S3022: When the third attribute is a built-in type, determine the second length information corresponding to the third attribute based on the data length and the identifier length corresponding to the third attribute.
[0095] Specifically, when the third attribute is a built-in type, the data length and identifier length (i.e., the numerical value of the identifier data length) of the model data corresponding to the third attribute are determined. For example, the identifier length of string type and data type data is generally 2. Then, the sum of the data length and the identifier length is the second length information corresponding to the third attribute.
[0096] S3023: When the third attribute is a custom type, determine the third data length corresponding to the data type contained in the third attribute, and determine the second length information corresponding to the third attribute based on the third data length.
[0097] The custom type includes one or more combinations of the numeric types and built-in types mentioned above. Specifically, when the data type of the third attribute is a custom type, since the data types contained in the custom type are composed of the numeric types and / or built-in types provided above, the third data length of each data type can be obtained according to the data length acquisition method of the corresponding data type. The sum of all the third data lengths is the first length information corresponding to the third attribute.
[0098] S3024: When the third attribute is a collection type, determine the fourth data length corresponding to the data type contained in the third attribute, and determine the second length information corresponding to the third attribute based on the fourth data length.
[0099] The collection type includes one or more combinations of the numeric type, built-in type, and custom type mentioned above, and supports deep nesting of different data types. Specifically, when the data type of the third attribute is a collection type, since the data types contained in the collection type are composed of one or more of the numeric type, built-in type, and custom type provided above, each data type in the collection type can be traversed, and the fourth data length of each data type can be obtained by using the corresponding data length acquisition method. The sum of all the fourth data lengths is the first length information corresponding to the third attribute.
[0100] S303: Based on the second length information, read the model data corresponding to the length of each third attribute from the second model, and write the binary data corresponding to the model data to the cache area.
[0101] For example, after determining the second length information corresponding to each third attribute, model data is obtained from the second model, and the binary data corresponding to the model data is written to a designated buffer area (ByteBuffer). The length of the read model data is consistent with the second length information of the corresponding third attribute; that is, what is extracted from the second model is the model data corresponding to the third attribute.
[0102] Specifically, in this embodiment, when reading the model data of the corresponding length for each third attribute and writing the corresponding binary data of the model data to the cache area, the process includes:
[0103] S3031: Based on the second length information corresponding to each third attribute, read the model data corresponding to the length of each third attribute from the second model in sequence.
[0104] S3032: Determine the binary data corresponding to the model data and write the binary data to the cache area.
[0105] Specifically, the process iterates through each third attribute in the second category of attribute list, retrieving model data from the second model sequentially according to the order of the third attributes in the second category of attribute list. After reading the model data corresponding to the third attribute, the corresponding binary data is determined and written to a designated buffer area. After traversing the entire second category of attribute list, the model data corresponding to each second attribute in the second model is serialized into the buffer area.
[0106] In one embodiment, after writing model data to the cache area, the pointer of the cache area is moved backward by a data distance corresponding to the second length information of the model data, in order to wait for the next model data to be written.
[0107] S304: Generate byte stream data packets based on binary data in the buffer area.
[0108] After iterating through each third attribute in the second category attribute list and writing the extracted model data corresponding to the binary data to the cache area, the binary data stored in the cache area is packaged into a byte stream data packet. After obtaining the byte stream data packet, it can be sent to the server for subsequent business processing.
[0109] As described above, by obtaining the second type of attribute list of the byte stream data packet, the third attribute contained in the second type of attribute list is determined. Based on the second length information corresponding to each third attribute, model data of the corresponding length is read from the second model. The binary data corresponding to the model data is written to the buffer area, and a byte stream data packet is generated based on the binary data in the buffer area. This completes the automatic serialization process of the byte stream data packet, eliminating the need to manually write serialization code. This improves program development efficiency, reduces the probability of errors by developers, enhances program robustness and fault tolerance, and reduces program code maintenance costs. Simultaneously, based on the data storage rules corresponding to the data type of the third attribute, the second data length of the corresponding data in the byte stream data packet is calculated, allowing for more accurate extraction of model data of the corresponding length from the second model.
[0110] Figure 5 This is a schematic diagram of another byte stream data conversion device provided in an embodiment of this application. (Reference) Figure 5 The byte stream data conversion device includes a second attribute acquisition module 51, a second length acquisition module 52, a second data conversion module 53, and a data packet generation module 54.
[0111] The second attribute acquisition module 51 is used to acquire the second type of attribute list of the second model, traverse the second type of attribute list, and determine the third attribute contained in the second type of attribute list; the second length acquisition module 52 is used to determine the second length information corresponding to each third attribute; the second data conversion module 53 is used to read the model data of the corresponding length of each third attribute from the second model according to the second length information, and write the binary data corresponding to the model data to the buffer area; the data packet generation module 54 is used to generate byte stream data packets based on the binary data in the buffer area.
[0112] As described above, by obtaining the second type of attribute list of the byte stream data packet, determining the third attribute contained in the second type of attribute list, reading the corresponding length of model data from the second model according to the second length information corresponding to each third attribute, writing the binary data corresponding to the model data to the buffer area, and generating the byte stream data packet based on the binary data in the buffer area, the automatic serialization process of the byte stream data packet is completed. There is no need to manually write serialization code, which improves the development efficiency of the program, reduces the error probability of developers, improves the robustness and fault tolerance of the program, and reduces the maintenance cost of the program code.
[0113] This application also provides a byte stream data conversion device, which can integrate the byte stream data conversion apparatus provided in this application. Figure 6 This is a schematic diagram of the structure of a byte stream data conversion device provided in an embodiment of this application. (Reference) Figure 6The byte stream data conversion device includes: an input device 63, an output device 64, a memory 62, and one or more processors 61; the memory 62 is used to store one or more programs; when one or more programs are executed by one or more processors 61, the one or more processors 61 implement the byte stream data conversion method provided in the above embodiments. The byte stream data conversion device, apparatus, and computer provided above can be used to execute the byte stream data conversion method provided in any of the above embodiments, and have corresponding functions and beneficial effects.
[0114] This application also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the byte stream data conversion method provided in the above embodiments. Of course, the computer-executable instructions in the storage medium containing computer-executable instructions provided in this application are not limited to the byte stream data conversion method provided above, and can also perform related operations in the byte stream data conversion method provided in any embodiment of this application. The byte stream data conversion apparatus, device, and storage medium provided in the above embodiments can execute the byte stream data conversion method provided in any embodiment of this application. Technical details not described in detail in the above embodiments can be found in the byte stream data conversion method provided in any embodiment of this application.
[0115] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application. The scope of this application is determined by the scope of the claims.
Claims
1. A byte stream data conversion method, characterized in that, include: Obtain the first type of attribute list of the byte stream data packet, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list; Create a first model, and set the included second attributes in the first model according to the order of each of the first attributes in the first class attribute list; The method involves determining the first length information corresponding to each of the first attributes, and allocating memory space in the first model for the corresponding second attribute based on the first length information to store the value corresponding to the first byte data. The method of determining the first length information corresponding to each of the first attributes includes: when the first attribute is a collection type, determining the second data length corresponding to the data type contained in the first attribute, and determining the first length information corresponding to the first attribute based on the second data length. The collection type includes one or more combinations of numeric type, built-in type and custom type. Based on the first length information, first byte data of the corresponding length of each of the first attributes is read from the byte stream data packet, and the value corresponding to the first byte data is assigned to the corresponding second attribute.
2. The byte stream data conversion method according to claim 1, characterized in that, Determining the first length information corresponding to each of the first attributes further includes at least one of the following: When the first attribute is a numeric type, the first length information corresponding to the first attribute is obtained through memory layout. When the first attribute is a built-in type, the first length information corresponding to the first attribute is determined according to the data length and the identifier length corresponding to the first attribute. When the first attribute is a custom type, the first data length corresponding to the data type contained in the first attribute is determined, and the first length information corresponding to the first attribute is determined according to the first data length. The custom type includes one or more combinations of numeric type and built-in type.
3. The byte stream data conversion method according to claim 1, characterized in that, Determining the values of each of the second attributes based on the first byte of data includes: When the first attribute is a numeric type or a built-in type, the first value corresponding to the first byte of data is assigned to the corresponding second attribute; When the first attribute is a custom type or a collection type, iterate through the second values corresponding to the data types contained in the first attribute, and assign the second values to the data types corresponding to the second attribute in turn.
4. A byte stream data conversion device, characterized in that, It includes a first attribute acquisition module, a first model configuration module, a first length acquisition module, and a first data conversion module, wherein: The first attribute acquisition module is used to acquire a first type of attribute list of byte stream data packets, traverse the first type of attribute list, and determine the first attribute contained in the first type of attribute list; The first model configuration module is used to create a first model and set the included second attributes in the first model according to the order of each first attribute in the first class attribute list; The first length acquisition module is used to determine the first length information corresponding to each of the first attributes, and allocate memory space in the first model for the corresponding second attribute according to the first length information, for storing the value corresponding to the first byte data. The determination of the first length information corresponding to each of the first attributes includes: when the first attribute is a collection type, determining the second data length corresponding to the data type contained in the first attribute, and determining the first length information corresponding to the first attribute according to the second data length. The collection type includes one or more combinations of numeric type, built-in type and custom type. The first data conversion module is used to read the first byte data of the corresponding length of each of the first attributes from the byte stream data packet according to the first length information, and assign the value corresponding to the first byte data to the corresponding second attribute.
5. A byte stream data conversion method, characterized in that, include: Obtain the second category of attribute list of the second model, traverse the second category of attribute list, and determine the third attribute contained in the second category of attribute list; Determining the second length information corresponding to each of the third attributes, the determination of the second length information corresponding to each of the third attributes includes: when the third attribute is a collection type, determining the fourth data length corresponding to the data type contained in the third attribute, and determining the second length information corresponding to the third attribute based on the fourth data length, wherein the collection type includes one or more combinations of numeric type, built-in type and custom type; Based on the second length information corresponding to each of the third attributes, model data of each length corresponding to the third attribute is sequentially read from the second model; the binary data corresponding to the model data is determined, and the binary data is written to the cache area; Generate byte stream data packets based on the binary data in the cache area.
6. The byte stream data conversion method according to claim 5, characterized in that, The determination of the second length information corresponding to each of the third attributes further includes at least one of the following: When the third attribute is a numeric type, the second length information corresponding to the third attribute is obtained through memory layout. When the third attribute is a built-in type, the second length information corresponding to the third attribute is determined according to the data length and the identifier length corresponding to the third attribute. When the third attribute is a custom type, the third data length corresponding to the data type contained in the third attribute is determined, and the second length information corresponding to the third attribute is determined according to the third data length. The custom type includes one or more combinations of numeric type and built-in type.
7. A byte stream data conversion device, characterized in that, It includes a second attribute acquisition module, a second length acquisition module, a second data conversion module, and a data packet generation module, wherein: The second attribute acquisition module is used to acquire the second type of attribute list of the second model, traverse the second type of attribute list, and determine the third attribute contained in the second type of attribute list; The second length acquisition module is used to determine the second length information corresponding to each of the third attributes. The determination of the second length information corresponding to each of the third attributes includes: when the third attribute is a collection type, determining the fourth data length corresponding to the data type contained in the third attribute, and determining the second length information corresponding to the third attribute based on the fourth data length. The collection type includes one or more combinations of numeric type, built-in type and custom type. The second data conversion module is used to sequentially read model data of each length corresponding to the third attribute from the second model according to the second length information corresponding to each third attribute; determine the binary data corresponding to the model data, and write the binary data to the cache area; The data packet generation module is used to generate byte stream data packets based on the binary data in the cache area.
8. A byte stream data conversion device, characterized in that, include: Memory and one or more processors; The memory is used to store 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 byte stream data conversion method as described in any one of claims 1-3 or 5-6.
9. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the byte stream data conversion method as described in any one of claims 1-3 or 5-6.
Citation Information
Patent Citations
Method and system for utilizing xml to realize generalization data exchange
CN103699633A