Data encoding method and device, and data decoding method and device
By bit-width encoding of each field in the data packet and splicing to generate a complete binary bit stream, the problems of code redundancy and difficulty in maintenance are solved, and the refined processing and efficient encoding of the data are realized.
Patent Information
- Application Number
- CN202510052654.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-04-15
AI Technical Summary
During the protocol testing process, redundant code data is difficult to maintain, and the prior art cannot achieve refined processing of information.
By obtaining a data packet with the first data format, encode each field based on its bit width, a corresponding binary bit stream is generated, and the binary bit streams of multiple fields are spliced into a complete binary bit stream.
It realizes refined data processing, provides a more flexible and accurate package grouping method, improves data encoding and transmission efficiency, reduces system code redundancy, and simplifies the maintenance process.
Smart Images

Figure CN119835339A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology applications, and in particular to an encoding method, a decoding method and a device. Background Art
[0002] Packaging and unpacking are key links in the process of information transmission. Correct packaging and unpacking methods can ensure the accuracy and integrity of information transmission. Common packaging and unpacking tools such as Protocol Buffers have obvious advantages in simplifying development and improving cross-platform compatibility, but they cannot achieve refined processing of information. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide an encoding method, a decoding method and a device for solving the problem of redundant code data and difficulty in maintaining data during protocol testing.
[0004] In order to achieve the above objectives, the present application embodiment adopts the following technical solutions: In a first aspect, an embodiment of the present application provides a data encoding method, comprising: Acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; For each field, based on a bit width corresponding to the field, encode the field value of the field into a corresponding first binary bit stream; The first binary bit streams corresponding to the multiple fields are concatenated to obtain a second binary bit stream.
[0005] In a second aspect, an embodiment of the present application provides a data decoding method, including: Receive a second binary bit stream, where the second binary bit stream is obtained based on the data encoding method according to the first aspect; Determine a plurality of fields corresponding to the first data format; For each field, extracting a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field; Based on the data type corresponding to the field, the third binary bit stream is decoded to obtain the field value of the field.
[0006] In a third aspect, an embodiment of the present application provides a data encoding device, including: An acquiring unit, configured to acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; an encoding unit, configured to encode, for each field, a field value of the field into a corresponding first binary bit stream based on a bit width corresponding to the field; The splicing unit is used to splice the first binary bit streams corresponding to the multiple fields to obtain a second binary bit stream.
[0007] In a fourth aspect, an embodiment of the present application provides a data decoding device, including: A receiving unit, configured to receive a second binary bit stream, where the second binary bit stream is obtained by the data encoding method according to the first aspect; A determination unit, configured to determine a plurality of fields corresponding to the first data format; an extraction unit, configured to extract, for each field, a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field; A decoding unit is used to decode the third binary bit stream based on the data type corresponding to the field to obtain the field value of the field.
[0008] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the method described in the first aspect or the second aspect.
[0009] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the method described in the first aspect or the second aspect.
[0010] At least one of the above technical solutions adopted in the embodiment of the present application can achieve the following beneficial effects: by obtaining a data packet with a first data format, the data packet includes field values of multiple fields, for each field, based on the bit width corresponding to the field, the field value of the field is encoded, and the first binary bit stream corresponding to the field is obtained, so as to realize the packet processing of bit-level operation on the data, and the data can be processed in a refined manner, and a more flexible and accurate packetization method can be provided. In particular, when processing fields of different bit widths, the bit width of the field can be flexibly adjusted according to the application scenario, and each field can be finely controlled, so that the data encoding process is more efficient and customizable. By splicing the first binary bit streams corresponding to multiple fields to obtain the second binary bit stream, it is possible to flexibly encode and generate a binary bit stream that meets the requirements of the first data format, thereby improving the efficiency of data encoding, thereby improving the performance of data transmission, and making data communication and storage more accurate, flexible and efficient. In addition, there is no need to write complex code to implement packetization, avoid system code redundancy, and facilitate later maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 A flowchart of a data encoding method provided for one embodiment of the present application; Figure 2 A flowchart of a data decoding method provided for one embodiment of the present application; Figure 3A A flowchart of an assignment method provided for an embodiment of the present application; Figure 3B A schematic diagram of a flow chart of another data encoding method provided for one embodiment of the present application; Figure 3C A flowchart of another data decoding method provided for one embodiment of the present application; Figure 4 A schematic diagram of the structure of a data encoding device provided for one embodiment of the present application; Figure 5 A schematic diagram of the structure of a data decoding device provided in one embodiment of the present application; Figure 6 A schematic diagram of the structure of an electronic device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0012] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0013] The terms "first", "second", etc. in this specification and claims are used to distinguish similar objects, and are not used to describe a particular order or precedence. It should be understood that the terms used in this way can be interchanged where appropriate so that the embodiments of the present application are implemented in a sequence other than those illustrated or described herein. In addition, "and / or" in this specification and claims means at least one of the connected objects, and the character " / " generally means that the objects associated with each other are in an "or" relationship.
[0014] Packaging and unpacking are key links in the process of information transmission. Correct packaging and unpacking methods can ensure the accuracy and integrity of information transmission. Common packaging and unpacking tools such as Protocol Buffers have obvious advantages in simplifying development and improving cross-platform compatibility, but they cannot achieve refined processing of information.
[0015] In view of this, the embodiment of the present application provides a data encoding method, by obtaining a data packet with a first data format, the data packet includes field values of multiple fields, for each field, based on the bit width corresponding to the field, the field value of the field is encoded, and the first binary bit stream corresponding to the field is obtained, so as to realize the packet processing of bit-level operation on the data, and the data can be processed in a refined manner, and a more flexible and accurate packetization method can be provided. In particular, when processing fields of different bit widths, the bit width of the field can be flexibly adjusted according to the application scenario, and each field can be finely controlled, so that the data encoding process is more efficient and customizable. By splicing the first binary bit stream corresponding to multiple fields to obtain a second binary bit stream, it is possible to flexibly encode and generate a binary bit stream that meets the requirements of the first data format, thereby improving the efficiency of data encoding, thereby improving the performance of data transmission, and making data communication and storage more accurate, flexible and efficient. In addition, there is no need to write complex code to implement packetization, avoid system code redundancy, and facilitate later maintenance.
[0016] Accordingly, the embodiment of the present application provides a data decoding method, by receiving a second binary bit stream, the second binary bit stream is obtained based on the data encoding method provided by the embodiment of the present application, determining multiple fields corresponding to the first data format, for each field, based on the bit width corresponding to the field, extracting a third binary bit stream from the second binary bit stream, decoding the third binary bit stream based on the data type of the field, obtaining the field value of the field, realizing the unpacking processing of the data at the bit level, being able to perform fine processing on the data, providing a more flexible and accurate unpacking method, especially when processing fields of different bit widths, the bit width of the field can be flexibly adjusted according to the application scenario, and fine control is performed for each field, so that the data decoding process is more efficient and customizable. The received second binary bit stream is generated according to the above-mentioned encoding method, indicating that the encoding of the field has taken into account the bit width and encoding rules, ensuring the accurate representation of the data. By determining the bit width of each field, the third binary bit stream corresponding to each field can be accurately extracted from the binary stream. Based on the data type of the field, using specific decoding rules, the extracted binary bit stream is accurately converted into the field value of the corresponding field, which can not only restore the original data value of each field, but also ensure the accuracy and consistency of decoding, avoiding data loss or errors. In addition, there is no need to write complex code to achieve unpacking, avoiding system code redundancy and facilitating later maintenance.
[0017] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0018] See also Figure 1 , which is a flow chart of a data encoding method provided by an embodiment of the present application, may include the following steps: S102: Acquire a data packet having a first data format.
[0019] A data packet includes the field values of multiple fields. A data packet is the basic unit of data transmission. A field is a component of a data packet and is used to store certain specific information. The field value is the specific data content stored in the field. For example, a data packet includes fields such as the source Internet Protocol (IP) address and the destination IP address, as well as the field values of these fields. The field value of the "source IP address" field is "192.168.1.1", and the field value of the "destination IP address" field is "172.16.10.1".
[0020] The data format refers to the specifications and structures used when storing, processing and transmitting data, including the organization form and content definition of the data. The first data format refers to a specific data format. As an example, the first data format can be a data packet format determined by a protocol, such as: Transmission Control Protocol (TCP), User Datagram Protocol (UDP), Universal Flash Storage (UFS) protocol and other protocols.
[0021] In an embodiment of the present application, multiple fields in a data packet and field values of the fields are organized and represented according to a first data format. The first data format defines the fields contained in the data packet and characteristics of the fields, including characteristics such as the bit width and data type corresponding to the fields.
[0022] As an example, the above S102 can obtain a data packet having a first data format by receiving a data packet sent by a third party, such as a user, a device, a network, etc. For example, a data packet is received through a network interface, the data packet includes field values of multiple fields, and the data format of the data packet conforms to the first data format.
[0023] As an example, the above S102 can read a data packet from a file to obtain a data packet having a first data format. For example, a text file containing structured data, such as Comma-Separated Values (CSV) and JavaScript Object Notation (JSON), can be parsed to extract a data packet, which includes field values of multiple fields, and the data format of the data packet conforms to the first data format.
[0024] As an example, the data packet in the above S102 can be obtained by configuration by the user, including configuring fields with specific attributes and field values of the fields, as well as data formats representing the organization and representation of different field values.
[0025] The embodiment of the present application shows some implementation methods of the above S102. Of course, it should be understood that the above S102 can also be implemented in other ways, and the embodiment of the present application does not limit this.
[0026] S104: For each field, based on the bit width corresponding to the field, encode the field value of the field into a corresponding first binary bit stream.
[0027] The bit width refers to the number of binary bits of data. The bit width corresponding to a field refers to the number of binary bits required for the field in binary format. For example, the field "age" is an integer that can be represented by a 16-bit binary number, so the bit width corresponding to the field is 16. In the embodiment of the present application, the bit width corresponding to the field is determined according to the content defined in the first data format.
[0028] A binary bit stream is a continuous data stream composed of multiple binary bits, including two elements "0" and "1". In the embodiment of the present application, the field value of the field is encoded into binary form to obtain the first binary bit stream corresponding to the field. For example: the field value of the field "age" is "25", after encoding into binary form, 11001 is obtained, which is the first binary bit stream corresponding to the field.
[0029] As another optional implementation, when the multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field, before the above S104, the method may further include the following steps: S140, traverse multiple fields.
[0030] S142, based on the first parameter, execute the following steps on the traversed fields, where the first parameter is used to transfer user-defined data.
[0031] S144: If the traversed field is the first field, assign a value to the traversed field based on the value of the first parameter.
[0032] S146, if the traversed field is the second field, the traversed field is added to the first list, and after the traversal of multiple fields is completed, the fields in the first list are assigned values based on the field value of the first field in the multiple fields.
[0033] In the embodiment of the present application, the first field is usually a basic field in the data structure, and the field value of the first field can be directly determined according to actual needs. The second field depends on the first field, and the field value of the second field is determined based on the field value of the first field. For example: suppose the preferential policy given by the merchant is 30 off for orders over 100 and 10 off for orders over 50. If the field value of the first field "order amount" is "65", then the field value of the second field "discount amount" is "10". If the field value of the first field "order amount" is "110", then the field value of the second field "discount amount" is "30".
[0034] As an example, the field value of the second field is dynamically determined based on the field value of the first field, and can be parsed based on the field value of the first field and the preset rules or mapping relationship to find the subfields contained in the second field. For example: In the UFS protocol, the UFS Protocol Information Unit (UPIU) contains multiple fields, such as Transaction Type, Flags, Task Tag and other fields. The field Transaction Type indicates that the UPIU is one of the 12 types of UPIU defined in the UFS protocol, such as a command UPIU, i.e. Command, or a response UPIU, i.e. Response, etc. The field Flags specifies the properties of the UPIU, such as read commands, write commands, etc. The field Flags only works on command UPIU and response UPIU. Here, the field Transaction Type is equivalent to the first field, and the field Flags is equivalent to the second field. Assuming that the field Flags is stored in a dictionary-type data structure, when assigning values to multiple fields in UPIU, the field value of the field Transaction Type must be determined first to determine whether the UPIU is a command UPIU or a response UPIU. If not, the field value of the field Flags may default to None, which means that the field is empty. If it is, it is necessary to further determine which subfields the field Flags contains. If the field value of the field Transaction Type is 000001b, it means that the UPIU is a command UPIU, that is, Command. If the field value of the field Transaction Type is 100001b, it means that the UPIU is a response UPIU. When the field value of the field Transaction Type is 000001b, the field Flags includes subfields such as Operational Flags and Task Attribute. The subfield Operational Flags indicates that the command UPIU is one of the read and write operations. If the field value is 10, it indicates that the command UPIU is a read command operation. If the field value is 01, it indicates that the command UPIU is a write command operation. The subfield TaskAttribute indicates that the command UPIU is one of the following commands: simple, ordered, and Head of Queue. If the field value is 00, it indicates that the command UPIU is simple. If the field value is 01, it indicates that the command UPIU is ordered. If the field value is 10, it indicates that the command UPIU is Head of Queue.
[0035] Parameters are used to pass specific data, which are usually pre-defined. The value of the parameter is the specific data passed by the parameter. For example, A is a parameter and 1 is the value of the parameter. As an example, the value of the parameter can come from user input or from external system configuration.
[0036] In an embodiment of the present application, a user can configure a plurality of defined fields when a first data format is known. The user defines and sets specific data for each field according to actual needs, and transmits the data in the system by a first parameter. Before encoding the field values of the plurality of fields, the system can assign values to the plurality of fields according to the value of the first parameter, and then determine the field values of the plurality of fields. As an example, each field has a corresponding first parameter. For example: assuming there are a field "age" and a field "user type", when assigning a value to the field "age", the field value of the field "age" can be determined to be "20" according to the value "20" of the parameter "age"; when assigning a value to the field "user type", the field value of the field "user type" can be determined to be "VIP" according to the value "VIP" of the parameter "user type".
[0037] As another example, when configuring the field value of a field, the user can also define and set the field's value conditions, and use the first parameter to pass the specific value conditions. The system determines the data that meets the value conditions and assigns it to the field based on the value of the first parameter. For example: for the field "age", the user can set the age range to between 20 and 30 years old, and use the first parameter to pass such a value condition. Then, the system can randomly determine an age between 20 and 30 years old based on the value of the first parameter and assign it to the field "age", such as the field value of the field "age" is "26".
[0038] As an example, the traversed fields are assigned values based on the value of the first parameter. The value of the first parameter can be used as the field value of the traversed field, or specific data that meets the conditions described by the value of the first parameter can be determined based on the value of the first parameter and assigned to the traversed field.
[0039] The first list is a pre-set list for storing fields that need to be assigned values in a delayed manner, i.e., the second field. In an embodiment of the present application, when traversing multiple fields, when traversing to the second field, the second field will be added to the first list first, and after the traversal of multiple fields is completed, the fields in the first list will be assigned values based on the field value of the first field. For example: assuming that multiple fields include "order amount", "currency unit", "retain decimal places", "delivery cost", "cost", "profit", etc., when traversing to "profit", the "profit" field will be stored in the first list, and after the field values of the fields such as "order amount", "currency unit", "retain decimal places", "delivery cost", "cost" are determined, the profit is calculated according to the order amount, delivery cost and cost, and then the calculated profit amount is converted into the amount after the standard measurement currency according to the currency unit and the number of decimal places, or, first, according to the currency unit and the number of decimal places, the single amount, delivery cost and cost are converted into the amount after the unified standard measurement currency, and then the profit is calculated, and then the field value of the "profit" field is determined.
[0040] In an embodiment of the present application, when the user has not defined and set the field values of multiple fields, the default value pre-given by the system can be used to assign values to the fields based on the default value. As an example, in the above S144, when assigning values to the traversed fields based on the value of the first parameter, if the value of the first parameter is empty, the field value of the traversed field is the default value, and if the value of the first parameter is not empty, the traversed field is assigned based on the value of the first parameter. The empty value of the first parameter indicates that the user has not defined and set the field value of the field, and the non-empty value of the first parameter indicates that the user needs to define and set the field value of the field. For example: assuming that the field "nationality" is traversed, if the value of the first parameter is "None", that is, the value of the first parameter is empty, the default value "Han" is used as the field value of the field "nationality"; if the value of the first parameter is "Miao", the field value of the field "nationality" is "Miao".
[0041] As an example, the second parameter can be used to indicate the completion status of the assignment of the first field. For example, if the value of the second parameter is 0, it indicates that the first field has not yet completed the assignment. If the value of the second parameter is 1, it indicates that the first field has completed the assignment. When traversing multiple fields, if the currently traversed field is the second field, and the value of the second parameter indicates that the first field has not completed the assignment, the traversed field is added to the first list. If the currently traversed field is the second field, and the value of the second parameter indicates that the first field has completed the assignment, the field value of the traversed field can be determined based on the field value of the first field.
[0042] By introducing the first parameter, the embodiment of the present application can dynamically adjust the field assignment strategy according to the user-defined data or requirements, and can also automatically generate and adjust the field value of the second field according to the field value of the first field, thereby optimizing the data encoding process, ensuring that the dependencies between the fields can be accurately and consistently processed, and realizing the package grouping that supports dynamic data structures. At the same time, through traversal and parameter-based assignment strategies, the system can flexibly respond to the needs of different scenarios, improve the intelligence and automation level of data processing, and thus achieve more efficient operations and more accurate results in complex data encoding or transmission scenarios.
[0043] As an optional implementation, when the type of the second field includes a dictionary type, when assigning values to the fields in the first list based on the field value of the first field in the multiple fields in S146, the following steps may be included: traversing the fields in the first list; If the type of the traversed field is a dictionary type, then based on the field value of the first field, the subfields contained in the traversed field are determined; Determine the field value of the subfield from the value of the first parameter; Assign the field value of the subfield to the traversed field.
[0044] The dictionary type indicates that the type of the field is a data structure of a dictionary. A dictionary is a set consisting of at least one key-value pair. The subfields correspond to the key-value pairs in the dictionary one by one, the name of the subfield is the key of the corresponding key-value pair, and the field value of the subfield is the value of the corresponding key-value pair. In an embodiment of the present application, based on the field value of the first subfield, multiple subfields are determined, and then the specific data of the key is determined. Based on the value of the first parameter, the field values of multiple subfields are determined, and then the specific data of the value is determined, so that according to the key-value pairs for which the specific data is determined, a dictionary with actual data is generated, and the field value of the field in the first list is obtained. For example: in the UFS protocol, assuming that the field value of the Transaction Type field of UPIU is 000001b, then the field Flags includes sub-fields such as Operational Flags and Task Attribute. Assuming that the field Flags is stored in a data structure of the field type, then based on the field value of the field Transaction Type, it can be determined that the field Flags includes sub-fields such as Operational Flags and Task Attribute. The field identifier is used as the key, and the field value of the sub-field is determined based on the value of the first parameter. The field value of the sub-field is used as the value to generate key-value pairs corresponding to multiple fields. Assuming that the field value of the sub-field Operational Flags is 10, and the field value of the sub-field Task Attribute is 11, the generated key-value pairs are key (Operational Flags)-valve (10), key (Task Attribute)-valve (11), and then a dictionary including these key-value pairs is generated, and the generated dictionary is used as the field value of the field Flags.
[0045] In the embodiment of the present application, when the type of the second field can be a dictionary type, the field value is not limited to simple data types, such as integers, strings, etc., but can include multiple subfields, each of which has a different value. By traversing the field, if a dictionary type field is encountered, the subfield contained in the dictionary can be determined according to the field value of the first field, and the field value of the subfield can be extracted from the value of the first parameter for assignment. It can dynamically fill and update multiple subfields in the dictionary type field according to the specific field value, ensure the accurate transmission and assignment of the field value, not only improve the flexibility of data encoding, so that the dependency relationship between fields can be processed more finely, but also can adapt to more complex multi-level data structures, especially in scenarios where nested data or multi-dimensional data processing is required, it can achieve efficient data organization and precise control, and realize the group package supporting dynamic data structure, which helps to improve the scalability, maintainability and complexity management capabilities of the data structure during information transmission, while ensuring the accuracy and integrity of the data, especially for complex structures containing multiple nested fields, which can better meet the needs of practical applications.
[0046] As an optional implementation, when the type of the second field includes a list type, when assigning values to the fields in the first list based on the field value of the first field in the multiple fields in S146, the following steps may be included: traversing the fields in the first list; If the type of the traversed field is a list type, the number of entries in the traversed field is determined based on the field value of the first field; Based on the value of the first parameter, generate a second list of entries including the number of entries; Use the second list as the field values for the traversed fields.
[0047] The list type indicates that the field type is a list data structure, which contains multiple entries. Each entry corresponds to a data item or element. These data items may be data of the same type or different types. For example, multiple entries in a list can all be integers, or a mixture of simple data types such as integers and strings.
[0048] The number of entries refers to the number of elements or data items that a field of the list type can contain. When generating the second list of entries containing the number of entries based on the value of the first parameter, the number of entries that should be contained in the field traversed from the second list can be determined based on the field value of the first field, and a new list, namely the second list, is generated based on the value of the first parameter and the required number of entries. This list contains entries consistent with the number of entries, and the content of the entries is determined based on the value of the first parameter. Finally, the generated second list is used as the field value of the traversed field.
[0049] For example: In the UFS protocol, the Response UPIU returned by the Report LUNS command contains fields such as LUN LIST LENGTH and LUN RECORDs. The number of entries contained in the LUN RECORDs field is determined by the field value of the LUN LIST LENGTH field. The LUN LIST LENGTH field is the first field, and the LUN RECORDs field is the second field. When the field value of the LUN LIST LENGTH field is determined to be 24, it can be determined that the LUN RECORDs field contains 3 (24 / 8) entries, namely First LUN RECORD, Second LUN RECORD, and Third LUN RECORD. The length of each entry is 8 bytes. The data format of the data stored in these entries is the same. The data stored in the entry is the field value of the LUN RECORDs field.
[0050] The embodiment of the present application can dynamically generate a second list according to the value of the first input field, thereby realizing the automatic assignment operation of the list type field, and the dynamic association of the field value with the number of list elements, with high flexibility and scalability, and realizing the package grouping that supports dynamic data structures. By traversing the list field type and calculating the number of entries according to the first field value, the data structure can be adaptively adjusted so that the number of entries in the list is closely bound to the input parameters, thereby optimizing the data processing flow, and is suitable for application scenarios that require dynamic adjustment of field values, such as configuration generation, data conversion, and custom data processing. It can greatly enhance the flexibility and automation of the system when processing complex data, thereby improving efficiency and accuracy.
[0051] As an example, the above S104 can traverse multiple fields, take the traversed fields as target fields, encode the field values of the target fields based on the bit width corresponding to the target fields, and obtain the first binary bit stream corresponding to the target fields.
[0052] As an optional implementation manner, the above S104 may determine the first binary bit stream corresponding to the multiple fields in the following manner: obtain a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding to the multiple fields one by one, each tuple comprising an identifier and an encoding rule of the corresponding field; Traverse the tuples in the third list; Based on the identifier in the traversed tuple, determine the target field from multiple fields; Based on the bit width corresponding to the target field, the field value of the target field is encoded using the encoding rule in the traversed tuple to obtain a first binary bit stream corresponding to the target field.
[0053] The third list is pre-set for the first data format. The third list consists of multiple tuples, and the tuple is a data structure. In the embodiment of the present application, each tuple includes two components: an identifier and an encoding rule. The identifier is used to identify multiple fields, and the field represented by the identifier can be determined from multiple fields according to the identifier in the tuple. The encoding rule is a rule that defines how to encode the field value of the field, including a specific method or algorithm for encoding the field value of the field according to the data type of the field and the required output format, that is, binary form. For example: in the UFS protocol, for multiple fields in UPIU, such as: Transaction Type, Flags, Task Tag and other fields, create corresponding tuples, and the tuple includes the identifier and encoding rules of the field, such as: the tuple corresponding to the field Transaction Type is ["Transaction Type", "Encoding Rule A"], but when traversing to the tuple, the target field can be determined to be the field Transaction Type based on the identifier "TransactionType", and according to the bit width corresponding to the field Transaction Type, assuming it is 8 bits, the field value of the field Transaction Type is encoded by "Encoding Rule A" to obtain the corresponding first binary bit stream.
[0054] The embodiment of the present application provides a customizable encoding method for each field by accurately controlling the identification, encoding rules and bit width of the data field, so as to achieve efficient, flexible and accurate binary data stream generation, and support the group package of bit-level operation. By using the third list to map the field with the corresponding encoding rule, each field can be accurately processed to ensure that the encoding method of each field is consistent with the predetermined rule. By traversing these tuples, the system can dynamically find the target field according to the field identification, and perform appropriate encoding according to the bit width and encoding rule of the field, and generate the corresponding first binary bit stream, which can not only process different types of data fields, but also adapt to a variety of data formats and structures through flexible encoding rules, improve the flexibility and scalability of data encoding, optimize the efficiency of data storage and transmission, reduce redundancy, improve accuracy, ensure the correctness and consistency of data encoding, and be suitable for complex data exchange and storage scenarios. It also has good maintainability and is convenient for future expansion and adjustment.
[0055] S106, concatenating the first binary bit streams corresponding to the multiple fields to obtain a second binary bit stream.
[0056] In the embodiment of the present application, after splicing the first binary bit streams corresponding to multiple fields, a binary bit stream is obtained, that is, the second binary bit stream. For example: the bit width corresponding to the field "age" is 16 bits, the bit width corresponding to the field "whether to activate" is 1 bit, the field value of the field "age" is "25", which is encoded in binary format as "0000000000011001", that is, the first binary bit stream corresponding to the field "age", the field value of the field "whether to activate" is "1" (1 means activation, 0 means inactivation), converted to binary format as "1", that is, the first binary bit stream corresponding to the field "whether to activate", then, the first binary bit streams corresponding to the field "age" and the field "whether to activate" are spliced as "00000000000110011", that is, the second binary bit stream.
[0057] As an example, when the first binary bit streams corresponding to the multiple fields are spliced in the above S106, the first binary bit streams corresponding to the multiple fields can be spliced according to the preset order of the multiple fields to obtain the second binary bit stream. For example: assuming that the order of the multiple fields is as follows: field 1, field 2, field 3, the first binary bit stream corresponding to field 1 is "00000011", the first binary bit stream corresponding to field 2 is "00001000", and the first binary bit stream corresponding to field 3 is "10101000", then after splicing the first binary bit streams corresponding to these three fields, the second binary bit stream obtained is "000000110000100010101000".
[0058] As an example, the above S106 can determine the splicing order according to the order of traversing the tuples from the above third list, and splice the first binary bit streams corresponding to the multiple fields according to the splicing order to obtain the second binary bit stream. For example: the identifier of the first tuple traversed is the identifier of field 1, and the first binary bit stream corresponding to field 1 after encoding is "00000011", the identifier of the second tuple traversed is the identifier of field 2, and the first binary bit stream corresponding to field 1 after encoding is "00001000", the identifier of the third tuple traversed is the identifier of field 3, and the first binary bit stream corresponding to field 1 after encoding is "10101000", then, the first binary bit streams corresponding to these three fields are spliced, and the second binary bit stream obtained is "000000110000100010101000".
[0059] The embodiment of the present application shows some implementation methods of the above S106. Of course, it should be understood that the above S106 can also be implemented in other ways, and the embodiment of the present application does not limit this.
[0060] The embodiment of the present application obtains a data packet having a first data format, wherein the data packet includes field values of multiple fields, and for each field, encodes the field value of the field based on the bit width corresponding to the field, obtains the first binary bit stream corresponding to the field, realizes the packet processing of bit-level operation on the data, can perform fine processing on the data, and provide a more flexible and accurate packetization method. Especially when processing fields of different bit widths, the bit width of the field can be flexibly adjusted according to the application scenario, and fine control is performed for each field, so that the data encoding process is more efficient and customizable. By splicing the first binary bit stream corresponding to multiple fields to obtain the second binary bit stream, it is possible to flexibly encode and generate a binary bit stream that meets the requirements of the first data format, thereby improving the efficiency of data encoding, thereby improving the performance of data transmission, and making data communication and storage more accurate, flexible and efficient. In addition, there is no need to write complex code to implement packetization, avoid system code redundancy, and facilitate later maintenance.
[0061] and Figure 1 Corresponding to the data encoding method shown, an embodiment of the present application also provides a data decoding method, see Figure 2 , which is a flow chart of a data decoding method provided by an embodiment of the present application, may include the following steps: S202, receiving a second binary bit stream.
[0062] The second binary bit stream is based on Figure 1 The data encoding method shown is obtained.
[0063] S204: Determine a plurality of fields corresponding to the first data format.
[0064] The first data format is a specific data format, which is the same data format as the first data format in the above data encoding method.
[0065] S206: For each field, extract a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field.
[0066] The embodiment of the present application can determine the length of the bit stream to be extracted based on the bit width, and extract a sub-bit stream, that is, a third binary bit stream, from the second binary bit stream according to the determined length. For example: assuming that the bit width corresponding to the field is 8, and the second binary bit stream is "000000110000100010101000", then based on the bit width, the extracted third binary bit stream is "10101000".
[0067] S208, decoding the third binary bit stream based on the data type corresponding to the field to obtain the field value of the field.
[0068] Data types include but are not limited to integer, string, floating point, and other data types.
[0069] The embodiment of the present application receives a second binary bit stream, which is obtained based on the data encoding method provided by the embodiment of the present application, determines a plurality of fields corresponding to the first data format, extracts a third binary bit stream from the second binary bit stream based on the bit width corresponding to the field for each field, decodes the third binary bit stream based on the data type of the field, obtains the field value of the field, and realizes the unpacking processing of the data at the bit level, which can be refined to process the data, and provide a more flexible and accurate unpacking method, especially when processing fields of different bit widths, the bit width of the field can be flexibly adjusted according to the application scenario, and refined control is performed for each field, so that the data decoding process is more efficient and customizable. The received second binary bit stream is generated according to the above encoding method, indicating that the encoding of the field has taken into account the bit width and encoding rules, ensuring the accurate representation of the data. By determining the bit width of each field, the third binary bit stream corresponding to each field can be accurately extracted from the binary stream. Based on the data type of the field, a specific decoding rule is used to accurately convert the extracted binary bit stream into the field value of the corresponding field, which can not only restore the original data value of each field, but also ensure the accuracy and consistency of the decoding, and avoid data loss or error. In addition, there is no need to write complex code to implement unpacking, which avoids system code redundancy and facilitates later maintenance.
[0070] As an example, the above S206 can traverse multiple fields, take the traversed fields as target fields, extract the third binary bit stream from the second binary bit stream based on the bit width corresponding to the target field, and decode the extracted third binary bit stream based on the data type corresponding to the target field to obtain the field value of the target field.
[0071] As an optional implementation, the field values of the multiple fields may be determined in the following manner: obtaining a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding one-to-one to the multiple fields, each tuple comprising an identifier and a decoding rule of the corresponding field; Traverse the tuples in the third list; Based on the identifier in the traversed tuple, determine the target field from multiple fields; Determine, based on the bit width corresponding to the target field, a third binary bit stream corresponding to the target field from the second binary bit stream; Based on the data type corresponding to the target field, the third binary bit stream corresponding to the target field is decoded by using the encoding rules in the traversed tuple to obtain the field value of the target field.
[0072] The third list is pre-set for the first data format. The third list consists of multiple tuples, and a tuple is a data structure. In an embodiment of the present application, each tuple includes two components: an identifier and a decoding rule. The identifier is used to identify multiple fields, and the field represented by the identifier can be determined from multiple fields based on the identifier in the tuple. The decoding rule is a rule that defines how to decode the third binary bit stream corresponding to the field, including a specific method or algorithm for decoding the field value of the field according to the data type of the field. For example, in the UFS protocol, corresponding tuples are created for multiple fields in UPIU, such as Transaction Type, Flags, Task Tag, etc. The tuples include the identifier and decoding rules of the field. For example, the tuple corresponding to the field Transaction Type is ["Transaction Type", "Decoding Rule A"]. However, when traversing the tuple, the target field can be determined to be the field Transaction Type based on the identifier "Transaction Type". According to the bit width corresponding to the field Transaction Type, an 8-bit binary bit stream, i.e., the third binary bit stream, is extracted from the binary bit stream. The third binary bit stream corresponding to the field Transaction Type is decoded by "Decoding Rule A" to obtain the field value of the field Transaction Type.
[0073] The embodiment of the present application provides a customizable decoding method for each field by accurately controlling the identification, decoding rules and bit width of the data field, and realizes the unpacking processing of the data at the bit level, so as to realize the efficient, flexible and accurate decoding of the third binary bit stream, and obtain the data of the corresponding data type. By using the third list to map the field with the corresponding decoding rule, each field can be accurately processed to ensure that the decoding method of each field is consistent with the predetermined rule. By traversing these tuples, the system can dynamically find the target field according to the field identification, and according to the bit width of the field, from the acquired second binary bit stream to the bit stream to be decoded, that is, the third binary bit stream, and according to the decoding rules in the traversed tuple, appropriate encoding is performed to obtain the original data of the target field, that is, the field value, which can not only process fields of different data types and bit widths, but also adapt to a variety of data formats and structures through flexible decoding rules, improve the flexibility and scalability of data decoding, and optimize the efficiency of data storage and transmission, reduce redundancy, improve accuracy, ensure the correctness and consistency of data encoding, and be suitable for complex data exchange and storage scenarios. At the same time, it also has good maintainability, which is convenient for future expansion and adjustment.
[0074] As an optional implementation method, in a case where the multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field, the field values of the multiple fields may also be determined in the following manner: determining a third binary bit stream corresponding to each of the multiple fields based on a bit width corresponding to each of the multiple fields; Decoding a third binary bit stream corresponding to the first field to obtain a field value of the first field; Determine the data type corresponding to the second field based on the field value of the first field; Based on the data type corresponding to the second field, the third binary bit stream corresponding to the second field is decoded to obtain the field value of the second field.
[0075] As an example, in the case where multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field, the field values of the multiple fields can also be determined in the following manner: traverse the multiple fields, and perform the following steps on the traversed fields: if the traversed field is the first field, then based on the bit width corresponding to the traversed field, extract the third binary bit stream from the second binary bit stream, and decode the extracted third binary bit stream to obtain the field value of the traversed field; if the traversed field is the second field, add the traversed field to a preset list, and after the traversal of the multiple fields is completed, determine the field value of the field in the list based on the field value of the first field in the multiple fields. As an example, the field value of the second field is dynamically determined based on the field value of the first field, and can be parsed according to the field value of the first field and the preset rules or mapping relationship to determine the data type corresponding to the second field. For example: the field value of field_2 is determined based on the specific value of field_1. Field_2 is the second field, and field_1 is the first field. Assuming that the field value of field_1 is 01, it means that the data type corresponding to the second field field_2 should be an integer type. If the field value of field_1 is 10, it means that the data type corresponding to the second field field_2 should be a string type. If the field value of field_1 is 11, it means that the data type corresponding to the second field field_2 should be a floating point type.
[0076] The embodiment of the present application further improves the accuracy and flexibility of data decoding by introducing the dependency between the first field and the second field. The data type of the first field is determined according to the field value of the first field, and then the third binary bit stream corresponding to the second field is decoded to obtain the field value of the second field, so that the decoding process can dynamically adjust the decoding method of the second field according to the decoding result of the first field, and realize the unpacking supporting dynamic data structure. According to the bit width of each field, the binary bit stream corresponding to each field is determined, that is, the third binary bit stream, and then the specific data type of the second field is determined based on the field value of the first field, and the appropriate decoding rule is determined according to the data type, so as to accurately decode the binary data stream of the second field, which not only improves the flexibility of data processing, but also can be intelligently adjusted according to the relationship between different fields, and also ensures the consistency and accuracy in the decoding process, and is suitable for data formats with dependencies and dynamic changes between fields, and has the ability to process complex data structures, and can establish a reasonable data mapping relationship between multiple fields, so as to ensure that the data restoration in the decoding process is correct, improve the decoding efficiency and adaptability, and is particularly suitable for application scenarios that require flexible parsing of different types and formats of data.
[0077] The following uses the test scenario of the UFS protocol as an example to illustrate the data encoding method and the data decoding method provided in the embodiment of the present application, which should not be understood as limiting the method of the embodiment of the present application. The UFS (Universal Flash Storage) protocol is a high-speed storage technology, also known as the universal flash storage protocol, which can provide higher read and write speeds, lower latency, and supports full-duplex operation, allowing simultaneous reading and writing. It is mainly used to improve the performance of the memory and is suitable for devices that require fast data access and processing. UPIU (UFS Protocol Information Unit) is an information unit of the UFS protocol, responsible for the transmission of commands, data and status between the host (Host) and the device (Device). UPIU defines the data format during information transmission in the UFS protocol to ensure that the communication between the host and the device is normal. UPIU is divided into multiple types, such as command UPIU, response UPIU and data UPIU. UPIU is a data packet with a first data format, and the first data format is determined by the UFS protocol. The general data structure of UPIU consists of two parts: a header and a domain related to UPIU. The header and the domain contain multiple fields. Taking the header as an example, there are fields such as Transaction Type, Flags, Logical Unit Number (LUN), Task Tag, etc., only a few of which are given as examples for illustration. Among them, the field LUN is used for addressing and identifies the logical unit of the storage device. The field Task Tag is used to distinguish multiple commands sent at the same time. The field Transaction Type indicates that the UPIU is one of the 12 types of UPIU defined in the UFS protocol, for example, it can be a command UPIU, that is, Command, or a response UPIU, that is, Response, and so on. The field Flags specifies the properties of the UPIU, such as read commands, write commands, etc. The field Flags only works for command UPIU and response UPIU.The field Transaction Type here is equivalent to the first field, and the field Flags is equivalent to the second field. When assigning values to multiple fields in UPIU, the field value of the field Transaction Type must be determined first to determine whether the UPIU is a command UPIU or a response UPIU. If not, the field value of the field Flags may default to None, which means that the field is empty. If it is, it is necessary to further determine which subfields the field Flags contains. For example, assuming that the field Transaction Type is a command UPIU, the field Flags includes subfields such as Operational Flags and Task Attribute. The fields of the field Flags and the values of the subfields are stored in the form of a dictionary. The above briefly introduces multiple fields in this application scenario and the dependencies between the multiple fields.
[0078] When testing the UFS protocol, it is necessary to quickly configure a meaningful UPIU, that is, assign values to each field in the UPIU, determine the field values of each field, and after configuring the fields, package the field values of the fields and send them to the receiver, who will unpack them. This includes the following stages: The first is the preparation stage. A kvs list is created for the multiple fields contained in UPIU. The kvs list is a list of three tuples. The tuples in the kvs list correspond to multiple fields one by one. Each tuple includes the identifier, default value and packer of the corresponding field. The packer contains the encoding and decoding methods of the corresponding field, which will be used when encoding and decoding the field.
[0079] The second is the assignment phase. For details, see Figure 3A , is a flow chart of an assignment method provided in an embodiment of the present application. Figure 3AAs shown, first, traverse the kvs list, determine the first target field according to the identifier in the traversed tuple, and judge whether the first target field is the first field or the second field. If it is the first field, assign a value to the first target field based on the dict_init parameter, that is, the value of the first parameter. If the dict_init parameter is empty, the default value of the traversed tuple is used as the field value of the first target field. If the dict_init parameter is not empty, assign a value to the first target field based on the value of the dict_init parameter; if it is not the first field but the second field, add the traversed element to the delayed assignment list, that is, the first list. After waiting for the kvs list traversal to be completed, traverse the delayed assignment list, determine the second target field according to the identifier of the traversed tuple, and if the second target field is a dictionary type, determine the multiple subfields contained in the second target field based on the field value of the first field, determine the field values of the multiple subfields based on the value of the dict_init parameter, and use the field values of the multiple subfields as the field value of the second target field. If the second target field is of list type, the number of entries contained in the second target field is determined based on the field value of the first field, and a second list is generated based on the value of the dict_init parameter and the number of entries, and the second list is used as the field value of the second target field.
[0080] The third is the coding stage. For details, see Figure 3B , is a flow chart of another data encoding method provided in an embodiment of the present application. Figure 3B As shown, first, traverse the kvs list, determine the target field and the bit width of the target field according to the identifier in the traversed tuple, encode the field value of the target field based on the bit width and the encoding method in the packer in the traversed tuple, obtain the first binary bit stream corresponding to the target field, and add the first binary bit stream to the second binary bit stream.
[0081] The fourth stage is the decoding stage. For details, see Figure 3C , is a flow chart of another data decoding method provided in an embodiment of the present application. Figure 3CAs shown, first, traverse the kvs list, determine the first target field and the bit width of the first target field according to the identifier in the traversed tuple, extract the third binary bit stream from the second binary bit stream, determine whether the first target field is the first field or the second field, if the first target field is the second field, then add the traversed tuple and the extracted third binary bit stream to the delayed decoding list, if the first target field is the first field, then decode the extracted third binary bit stream through the decoding method of the packer in the traversed tuple, and assign the decoding result to the first target field. After waiting for the kvs list to be traversed, traverse the delayed decoding list again, determine the second target field according to the identifier of the traversed tuple, determine the data type of the second target field based on the field value of the first field, decode the third binary bit stream through the decoding method of the packer in the traversed tuple, obtain the field value that conforms to the data type, and assign the decoding result to the second target field.
[0082] As an example, the data packaging and data decoding methods shown in the above embodiments can be implemented by a custom BaseDict class in the Python programming language for specific types of UPIU packaging and unpacking. The custom BaseDict class inherits from the Dict class in the Python programming language, and other classes for specific types of UPIU packaging and unpacking inherit the BaseDict class, thereby obtaining core functions such as data storage, packaging, and unpacking. For different types of data structures, a special subclass will be defined, and this subclass will inherit and use the method provided by the parent class for packaging and unpacking. Of course, if other coding languages are used to implement the method of packaging and unpacking data in this application, it is also within the scope of protection of this application.
[0083] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0084] With the above Figure 1 Corresponding to the data encoding method shown, the present application embodiment also proposes a data encoding device. Figure 4 , is a structural diagram of a data encoding device provided in an embodiment of the present application, the device 400 includes: an acquisition unit 410, an encoding unit 420, and a splicing unit 430.
[0085] The acquisition unit 410 is used to acquire a data packet having a first data format, wherein the data packet includes field values of multiple fields.
[0086] The encoding unit 420 is used to encode the field value of each field into a corresponding first binary bit stream based on the bit width corresponding to the field.
[0087] The splicing unit 430 is used to splice the first binary bit streams corresponding to the multiple fields to obtain a second binary bit stream.
[0088] Optionally, when the multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field, the apparatus 400 further includes: a traversal unit: The traversal unit is configured to perform the following steps before the encoding unit 420 encodes the field value of the field into a corresponding first binary bit stream based on the bit width corresponding to the field for each field: traversing the multiple fields; Based on the first parameter, the following steps are performed on the traversed fields, where the first parameter is used to pass user-defined data: If the traversed field is the first field, assign a value to the traversed field based on the value of the first parameter; If the traversed field is the second field, the traversed field is added to the first list, and after the traversal of the multiple fields is completed, the fields in the first list are assigned values based on the field value of the first field in the multiple fields.
[0089] Optionally, in the case where the type of the second field includes a dictionary type, the traversal unit may perform the following steps when assigning values to the fields in the first list based on the field value of the first field in the multiple fields: traversing the fields in the first list; If the type of the traversed field is a dictionary type, then based on the field value of the first field, determining the subfields contained in the traversed field; Determine the field value of the subfield from the value of the first parameter; Assign the field value of the subfield to the traversed field.
[0090] Optionally, in the case where the type of the second field includes a list type, the traversal unit may perform the following steps when assigning values to the fields in the first list based on the field value of the first field in the multiple fields: traversing the fields in the first list; If the type of the traversed field is a list type, determining the number of entries in the traversed field based on the field value of the first field; Based on the value of the first parameter, generating a second list of entries including the number of entries; The second list is used as the field value of the traversed field.
[0091] Optionally, the first binary bit streams corresponding to the multiple fields may also be determined by the encoding unit performing the following steps: obtaining a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding to the multiple fields one by one, each tuple comprising an identifier and an encoding rule of the corresponding field; Traversing the tuples in the third list; Determine a target field from the multiple fields based on an identifier in the traversed tuple; Based on the bit width corresponding to the target field, the field value of the target field is encoded using the encoding rule in the traversed tuple to obtain a first binary bit stream corresponding to the target field.
[0092] Obviously, the data encoding device provided in the embodiment of the present application can be used as Figure 1 The execution subject of the data encoding method shown, for example Figure 1 In the data encoding method shown in FIG. 1 , step S102 may be performed by Figure 4 The acquisition unit 410 in the data encoding device shown in FIG. 1 is executed, and step S104 can be performed by Figure 4 The encoding unit 420 in the data encoding device shown in FIG. 1 is executed, and step S106 can be performed by Figure 4 The splicing unit 430 in the data encoding device shown is executed.
[0093] With the above Figure 2 Corresponding to the data decoding method shown, the present application embodiment also proposes a data decoding device. Figure 5 , is a structural diagram of a data decoding device provided in an embodiment of the present application, the device 500 includes: a receiving unit 510, a determining unit 520, an extracting unit 530 and a decoding unit 540.
[0094] The receiving unit 510 is used to receive a second binary bit stream, wherein the second binary bit stream is based on Figure 1 The data encoding method shown is obtained.
[0095] The determining unit 520 is used to determine a plurality of fields corresponding to the first data format.
[0096] The extraction unit 530 is configured to extract, for each field, a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field.
[0097] The decoding unit 540 is used to decode the third binary bit stream based on the data type corresponding to the field to obtain the field value of the field.
[0098] Optionally, the field values of the multiple fields may also be determined by the decoding unit 540 performing the following steps: obtaining a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding one-to-one to the multiple fields, each tuple comprising an identifier and a decoding rule of the corresponding field; Traversing the tuples in the third list; Determine a target field from the multiple fields based on an identifier in the traversed tuple; Determining, from the second binary bit stream, a third binary bit stream corresponding to the target field based on a bit width corresponding to the target field; Based on the data type corresponding to the target field, the third binary bit stream corresponding to the target field is decoded by using the encoding rules in the traversed tuple to obtain the field value of the target field.
[0099] Optionally, in a case where the multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field, the field values of the multiple fields may also be determined by the decoding unit 540 performing the following steps: determining, based on a bit width corresponding to each of the multiple fields, a third binary bit stream corresponding to each of the multiple fields; Decoding a third binary bit stream corresponding to the first field to obtain a field value of the first field; Determine the data type corresponding to the second field based on the field value of the first field; Based on the data type corresponding to the second field, the third binary bit stream corresponding to the second field is decoded to obtain the field value of the second field.
[0100] Obviously, the data decoding device provided in the embodiment of the present application can be used as Figure 2 The execution subject of the data decoding method shown is, for example Figure 2 In the data decoding method shown in FIG. 1 , step S202 may be performed by Figure 5 The receiving unit 510 in the data decoding device shown in FIG. 1 is executed, and step S204 can be performed by Figure 5 The determination unit 520 in the data decoding device shown in FIG. 1 is executed, and step S206 can be performed by Figure 5 The extraction unit 530 in the data decoding device shown in FIG. 1 is executed, and step S208 can be performed by Figure 5 The decoding unit 540 in the data decoding device shown is executed.
[0101] According to another embodiment of the present application, Figure 4 The data encoding device shown or Figure 5 The various units in the data decoding device shown can be separately or completely combined into one or several other units to constitute, or one (some) of the units can be further divided into multiple functionally smaller units to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions. In practical applications, the function of one unit can also be implemented by multiple units, or the functions of multiple units can be implemented by one unit. In other embodiments of the present application, the data encoding device or the data decoding device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by the collaboration of multiple units.
[0102] According to another embodiment of the present application, the program can be executed on a general computing device such as a computer including a central processing unit (CPU), a random access memory (RAM), a read-only memory (ROM), and other processing elements and storage elements. Figure 1 or Figure 2 A computer program (including program code) for each step involved in the corresponding method shown in FIG. Figure 4 The data encoding device shown in the embodiment of the present application is implemented by the data encoding method, or the structure Figure 5 The data decoding device shown in and the data decoding method of the embodiment of the present application are implemented. The computer program can be recorded on, for example, a computer-readable storage medium, and transferred to an electronic device through the computer-readable storage medium and run therein.
[0103] Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. Figure 6 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0104] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0105] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.
[0106] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a data processing device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations: Acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; For each field, based on a bit width corresponding to the field, encode the field value of the field into a corresponding first binary bit stream; The first binary bit streams corresponding to the multiple fields are concatenated to obtain a second binary bit stream.
[0107] Alternatively, the processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a data processing device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations: Receive a second binary bit stream, wherein the second binary bit stream is based on Figure 1 The data encoding method shown is obtained; Determine a plurality of fields corresponding to the first data format; For each field, extracting a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field; Based on the data type corresponding to the field, the third binary bit stream is decoded to obtain the field value of the field.
[0108] The above application Figure 4 or Figure 5The method performed by the device disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in a decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0109] The electronic device may also perform Figure 1 The method and the data encoding device are implemented in Figure 1 , Figure 4 The functions of the embodiments shown, or the execution Figure 2 The method and the data decoding device are implemented in Figure 2 , Figure 5 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.
[0110] Of course, in addition to software implementation methods, the electronic device of the present application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0111] The embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 1 The method of the embodiment shown is specifically used to perform the following operations: Acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; For each field, based on a bit width corresponding to the field, encode the field value of the field into a corresponding first binary bit stream; The first binary bit streams corresponding to the multiple fields are concatenated to obtain a second binary bit stream.
[0112] Or execute Figure 2 The method of the embodiment shown is specifically used to perform the following operations: Receive a second binary bit stream, wherein the second binary bit stream is based on Figure 1 The data encoding method shown is obtained; Determine a plurality of fields corresponding to the first data format; For each field, extracting a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field; Based on the data type corresponding to the field, the third binary bit stream is decoded to obtain the field value of the field.
[0113] In short, the above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0114] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0115] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0116] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0117] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
Claims
1. A data encoding method, characterized in that: include: Acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; For each field, based on a bit width corresponding to the field, encode the field value of the field into a corresponding first binary bit stream; The first binary bit streams corresponding to the multiple fields are concatenated to obtain a second binary bit stream.
2. The method according to claim 1, characterized in that The multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field; Before encoding the field value of each field into a corresponding first binary bit stream based on the bit width corresponding to the field, the method further includes: Traversing the multiple fields; Based on the first parameter, the following steps are performed on the traversed fields, where the first parameter is used to pass user-defined data: If the traversed field is the first field, assign a value to the traversed field based on the value of the first parameter; If the traversed field is the second field, the traversed field is added to the first list, and after the traversal of the multiple fields is completed, the fields in the first list are assigned values based on the field value of the first field in the multiple fields.
3. The method according to claim 2, characterized in that The type of the second field includes a dictionary type; The assigning values to the fields in the first list based on the field value of the first field in the multiple fields includes: Traverse the fields in the first list; If the type of the traversed field is a dictionary type, then based on the field value of the first field, determining the subfields contained in the traversed field; Determine the field value of the subfield from the value of the first parameter; Assign the field value of the subfield to the traversed field.
4. The method according to claim 2, characterized in that: The type of the second field includes a list type; The assigning values to the fields in the first list based on the field value of the first field in the multiple fields includes: Traverse the fields in the first list; If the type of the traversed field is a list type, determining the number of entries in the traversed field based on the field value of the first field; Based on the value of the first parameter, generating a second list of entries including the number of entries; The second list is used as the field value of the traversed field.
5. The method according to any one of claims 1 to 4, characterized in that: The first binary bit streams corresponding to the multiple fields are determined in the following manner: Obtaining a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding one-to-one to the plurality of fields, each tuple comprising an identifier and an encoding rule of a corresponding field; Traversing the tuples in the third list; Determine a target field from the multiple fields based on an identifier in the traversed tuple; Based on the bit width corresponding to the target field, the field value of the target field is encoded using the encoding rule in the traversed tuple to obtain a first binary bit stream corresponding to the target field.
6. A data decoding method, characterized in that: include: Receive a second binary bit stream, where the second binary bit stream is obtained based on the data encoding method according to any one of claims 1 to 5; Determine a plurality of fields corresponding to the first data format; For each field, extracting a third binary bit stream from the second binary bit stream based on a bit width corresponding to the field; Based on the data type corresponding to the field, the third binary bit stream is decoded to obtain the field value of the field.
7. The method according to claim 6, characterized in that The field values of the multiple fields are determined in the following manner: Obtain a third list corresponding to the first data format, the third list comprising a plurality of tuples corresponding one-to-one to the plurality of fields, each tuple comprising an identifier and a decoding rule of a corresponding field; Traversing the tuples in the third list; Determine a target field from the multiple fields based on an identifier in the traversed tuple; Determining, from the second binary bit stream, a third binary bit stream corresponding to the target field based on a bit width corresponding to the target field; Based on the data type corresponding to the target field, the third binary bit stream corresponding to the target field is decoded by using the encoding rules in the traversed tuple to obtain the field value of the target field.
8. The method according to claim 6, characterized in that The multiple fields include a first field and a second field, and the field value of the second field is determined based on the field value of the first field; The field values of the multiple fields are determined in the following manner: Determine, based on the bit widths corresponding to the multiple fields, third binary bit streams corresponding to the multiple fields; Decoding a third binary bit stream corresponding to the first field to obtain a field value of the first field; Determine the data type corresponding to the second field based on the field value of the first field; Based on the data type corresponding to the second field, the third binary bit stream corresponding to the second field is decoded to obtain the field value of the second field.
9. A data encoding device, characterized in that: include: An acquiring unit, configured to acquire a data packet having a first data format, wherein the data packet includes field values of a plurality of fields; an encoding unit, configured to encode, for each field, a field value of the field into a corresponding first binary bit stream based on a bit width corresponding to the field; The splicing unit is used to splice the first binary bit streams corresponding to the multiple fields to obtain a second binary bit stream.
10. A data decoding device, characterized in that: include: A receiving unit, configured to receive a second binary bit stream, wherein the second binary bit stream is obtained based on the data encoding method according to any one of claims 1 to 5; A determination unit, configured to determine a plurality of fields corresponding to the first data format; an extraction unit, configured to extract, for each field, a third binary bit stream of a specified length from the second binary bit stream based on a bit width corresponding to the field, wherein the specified length is determined based on the bit width corresponding to the field; A decoding unit is used to decode the third binary bit stream based on the data type corresponding to the field to obtain the field value of the field.
Citation Information
Cited By
Key-value cache management method, controller, device, apparatus, medium and product
CN122653548A