Decoding methods, devices, computer equipment, and storage media
By automatically analyzing field characteristics in the encoded data stream and selecting an appropriate decoding method, the problem of low decoding processing efficiency in the existing technology is solved, and an efficient automated decoding process is realized.
Patent Information
- Application Number
- CN202110477916.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-29
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-04-29
AI Technical Summary
The decoding processing efficiency of encoded data streams in the existing technology is low and relies on manual search for protocol files, resulting in insufficient processing efficiency and success rate.
By obtaining the encoded data stream, splitting it into N fields, analyzing the data characteristics of each field, determining its data type and selecting an appropriate decoding method according to the type for decoding processing, automatic reverse analysis and decoding can be achieved.
It improves the efficiency and success rate of decoding processing, avoids dependence on manual search for protocol files, and realizes an automated decoding process.
Smart Images

Figure CN115276889B
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, specifically to the field of coding and decoding technology, and in particular to a decoding processing method, a decoding processing device, a computer device and a computer-readable storage medium. Background Art
[0002] Data encoding refers to the process of encoding the original data using an encoding method to obtain an encoded data stream corresponding to the original data. At present, the decoding process of the encoded data stream is usually carried out by manually searching for the corresponding protocol file, such as the protocol file used in the encoding method, and then determining the decoding method corresponding to the encoded data stream according to the protocol file, thereby restoring the corresponding original data. This method of relying on manual search for protocol files for decoding processing has too low processing efficiency. Summary of the invention
[0003] The embodiments of the present application provide a decoding method, apparatus, computer device and storage medium, which can improve the efficiency of decoding processing and the decoding success rate.
[0004] On the one hand, an embodiment of the present application provides a decoding processing method, the method comprising:
[0005] Obtaining a coded data stream, where the coded data stream is a binary data stream obtained by encoding the original data;
[0006] The encoded data stream is split into N fields, where N is a positive integer;
[0007] Analyze the data features contained in each of the N fields respectively to determine the data type of each field;
[0008] Determine the decoding method corresponding to each field according to the data type of each field;
[0009] Decode each field according to the decoding method corresponding to each field to restore the original data.
[0010] On the one hand, an embodiment of the present application provides a decoding processing device, the device comprising:
[0011] An acquisition unit, used to acquire a coded data stream, where the coded data stream is a binary data stream obtained by encoding the original data;
[0012] A processing unit, used for splitting the coded data stream to obtain N fields, where N is a positive integer;
[0013] The processing unit is further used to analyze the data features contained in each of the N fields respectively to determine the data type of each field;
[0014] A determination unit, used to determine a decoding method corresponding to each field according to the data type of each field;
[0015] The processing unit is also used to decode each field according to the decoding method corresponding to each field to restore the original data.
[0016] On the one hand, an embodiment of the present application provides a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the above-mentioned decoding processing method.
[0017] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is read and executed by a processor of a computer device, the computer device executes the above-mentioned decoding processing method.
[0018] On the one hand, the embodiments of the present application provide a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the above-mentioned decoding processing method.
[0019] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 This is a schematic diagram of the structure of a blockchain network provided in an embodiment of the present application;
[0022] Figure 2 is a schematic diagram of a block structure provided in an embodiment of the present application;
[0023] Figure 3 It is a schematic diagram of the architecture of a decoding processing system provided by an embodiment of the present application;
[0024] Figure 4 It is a flowchart of a decoding processing method provided in an embodiment of the present application;
[0025] Figure 5 It is a schematic diagram of the structure of a coded data stream provided in an embodiment of the present application;
[0026] Figure 6 It is a flowchart of a splitting processing method provided in an embodiment of the present application;
[0027] Figure 7 It is a flowchart of a field decoding method provided in an embodiment of the present application;
[0028] Figure 8 is a structural diagram of a decoding processing device provided in an embodiment of the present application;
[0029] Fig. 9 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0031] The following is an introduction to the technical terms involved in the embodiments of the present application:
[0032] 1. Key technical terms:
[0033] Protobuf: short for Protocol buffers, a data encoding and decoding standard;
[0034] PB: short for Protobuf;
[0035] TV: Tag-Value, key-value;
[0036] TLV: Tag-Length-Value, key-length-value;
[0037] Protoc: Data protocol file defined by PB encoding standard specification;
[0038] Forward decoding: refers to the process of searching for the PB protocol file and calling the decoding algorithm recorded in the protocol file to decode and obtain the original data;
[0039] Reverse decoding: refers to the process of determining the decoding method by analyzing the encoded data stream, and using the decoding method obtained by analysis to restore the original data;
[0040] Splitting: Split the encoded data stream into many fields;
[0041] Field decoding: Call the decoding method on the field data to get the original data;
[0042] Serialization: refers to the process of converting structured data into a specified format according to certain encoding specifications;
[0043] Deserialization: refers to the process of parsing data converted into a specified format into original structured data;
[0044] Message: A composite data format defined in PB;
[0045] wire_type: A packaging type defined by PB, used to indicate the data type of the field. The specific values can include 0, 1, 2, and 5;
[0046] field_number: field number, used to indicate the sequence number of the field in the PB protocol, which is unique;
[0047] Tag: The calculation method is field_number<<3|wire_type;
[0048] Varint (variable length) codec: A codec algorithm that can improve data compression efficiency.
[0049] 2. Blockchain:
[0050] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0051] Since a large amount of data calculation and data storage services are involved in the blockchain, which require a large amount of computer operating costs, the original data and coded data streams involved in this application can be implemented by cloud storage technology in cloud technology. That is, the blockchain is stored in the "cloud" through cloud storage technology. When the original data and coded data streams need to be stored in the blockchain, these data can be uploaded to the blockchain on the "cloud" through cloud storage technology, and when the data needs to be read, the data can also be read from the blockchain on the "cloud" at any time, which can reduce the storage requirements for terminal devices and expand the application scope of the blockchain.
[0052] See also Figure 1 , Figure 1 It is a schematic diagram of the structure of a blockchain network provided by an embodiment of the present application. The blockchain network 100 (or distributed system 100) is formed by multiple nodes (any form of computing devices in the access network, such as servers and user terminals) and clients, and the nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol running on the Transmission Control Protocol (TCP) protocol. In a distributed system, any machine such as a server or a terminal can join and become a node, and the node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer.
[0053] See also Figure 1 The functions of each node in the blockchain network shown may include:
[0054] (1) Routing: A basic function of a node, used to support communication between nodes.
[0055] (2) Applications are used to be deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain network so that other nodes can add the record data to a temporary block when they successfully verify the source and integrity of the record data.
[0056] For example, the services implemented by the application include:
[0057] ① Wallet, used to provide the function of conducting electronic currency transactions, including initiating transactions (i.e. sending the transaction record of the current transaction to other nodes in the blockchain network). After successful verification by other nodes, as a response to acknowledge the validity of the transaction, the transaction record data is stored in the temporary block of the blockchain; of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;
[0058] ② Shared ledger, which is used to provide functions such as storage, query and modification of account data. The record data of the operation on the account data is sent to other nodes in the blockchain network. After other nodes verify the validity, they will store the record data in a temporary block as a response to acknowledge the validity of the account data. They can also send confirmation to the node that initiated the operation.
[0059] ③Smart contracts, computerized protocols, can execute the terms of a contract through code deployed on a shared ledger that is executed when certain conditions are met. The code is used to complete automated transactions according to actual business needs; that is, smart contracts are executable programs running on the blockchain, which are triggered to execute automatically when transactions are conducted on the blockchain. For example, query the logistics status of the goods purchased by the buyer, and transfer the buyer's electronic currency to the merchant's address after the buyer signs for the goods; of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0060] ④ Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain network.
[0061] Blockchain is essentially a decentralized database. As the underlying technology of Bitcoin, it is a string of data blocks generated by cryptography. Each data block is linked by a random hash algorithm (also called a hash algorithm). The next block contains the hash value of the previous block. Blockchain technology is widely used in digital assets, smart contracts, logistics tracking, product protection and other scenarios.
[0062] See also Figure 2 , Figure 2 Schematic diagram of a block structure provided by an embodiment of the present application. Figure 2The block structure shown in the figure includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. The blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information to verify the validity of its information (anti-counterfeiting) and generate the next block.
[0063] The decoding processing method of the present application can be combined with blockchain technology. For example, the original data and the encoded data stream can be uploaded to the blockchain for storage, which can ensure that the data on the blockchain is not easily tampered with. Alternatively, the reverse decoding processing flow of the encoded data stream of the present application can be executed on the blockchain, which can not only ensure the fairness and justice of the decoding processing flow, but also make the decoding processing flow traceable and improve the security of the decoding processing flow.
[0064] In the embodiments of the present application, after encoding any original data using a coding algorithm to obtain a binary encoded data stream, for example, the original data is encoded using a PB algorithm to obtain an encoded data stream; the decoding processing scheme provided by the present application can be used to automatically perform reverse analysis on the characteristics of the encoded data stream without manual search or reliance on protocol files, thereby realizing decoding processing to restore the original data, effectively improving decoding efficiency and decoding success rate.
[0065] Please refer to Figure 3 , Figure 3 1 is a schematic diagram of the architecture of a decoding processing system provided by an embodiment of the present application. The architecture diagram of the decoding processing system includes: a server 340 and a computer device cluster, wherein the computer device cluster may include: a computer device 310, a computer device 320, a computer device 330, etc. The computer device cluster and the server 340 may be directly or indirectly connected via wired or wireless communication, and the present application does not limit this.
[0066] Figure 1 The server 340 shown can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.
[0067] Figure 1The computer device 310, computer device 320, computer device 330, etc. shown in the figure can be a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile Internet device (MID), a vehicle, a vehicle-mounted device, a roadside device, an aircraft, a wearable device, such as a smart watch, a smart bracelet, a pedometer, etc., and other smart devices with decoding and processing functions.
[0068] In a possible implementation, taking the computer device 310 as an example, the computer device 310 obtains a coded data stream, wherein the coded data stream may be a binary data stream obtained after the computer device 310 encodes the original data. The computer device 310 sends the coded data stream to the server 340. After receiving the coded data stream, the server 340 may split the coded data stream to obtain N fields, where N is a positive integer; then, the server 340 analyzes the data features contained in each of the N fields to determine the data type of each field; and the server 340 determines the decoding method corresponding to each field according to the data type of each field; finally, the server 340 decodes each field according to the decoding method corresponding to each field to restore the original data. Then, the server 340 may send the restored original data to the computer device 310.
[0069] Of course, the coded data stream is split to obtain N fields, and the data features contained in each of the N fields are analyzed to determine the data type of each field; then, the decoding method corresponding to each field is determined according to the data type of each field; and each field is decoded according to the decoding method corresponding to each field. It is not necessarily performed by the server 340, and can also be performed by the computer device 310 or any other computer device in the computer device cluster. In addition, the encoding process of the original data to obtain the coded data stream is not necessarily performed by the computer device 310, but can also be performed by the server 340.
[0070] In one possible implementation, the decoding processing system provided in the embodiment of the present application can be deployed on the node of the blockchain. For example, the server 340 and each computer device included in the computer device cluster can be regarded as a node device of the blockchain to jointly constitute a blockchain network. Therefore, the decoding process of the encoded data stream in the present application can be executed on the blockchain. In addition, the encoding process of the original data can also be executed on the blockchain. This can not only ensure the fairness and justice of the data decoding process, but also make the decoding process traceable and improve the security of the decoding process.
[0071] It can be understood that the system architecture diagram described in the embodiment of the present application is for more clearly illustrating the technical solution of the embodiment of the present application, and does not constitute a limitation on the technical solution provided in the embodiment of the present application. A person of ordinary skill in the art can know that with the evolution of the system architecture and the emergence of new business scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.
[0072] The decoding method proposed in the embodiment of the present application will be described in detail below with reference to the accompanying drawings. Figure 4 , Figure 4 A decoding processing method provided in an embodiment of the present application, wherein the decoding processing method can be applied to a computer device, which can be, for example, a vehicle-mounted device, a smart phone, a tablet computer, a smart wearable device, or other smart device. The computer device can also be completed by a computer device and a server, and the computer device can also be a server. Figure 4 As shown, the decoding processing method may include steps S410 to S450. Among them:
[0073] S410: Obtain a coded data stream, where the coded data stream is a binary data stream obtained by encoding the original data.
[0074] The process of obtaining the encoded data stream may include: reading the encoded data stream and detecting whether the encoded data stream has been read to completion; the detection method here may include: running a data end instruction to detect whether the encoded data stream has been read to completion; the data end instruction may include but is not limited to an isEnd command; if it is detected that the encoded data stream has not been read to completion, continue reading the encoded data stream until the reading is completed.
[0075] In a possible implementation, after obtaining the coded data stream, it is necessary to determine whether the coded data stream is valid. The determination method here can be to determine whether the data contained in the coded data stream is empty. If it is not empty, the coded data stream is determined to be valid; if it is empty, the obtained coded data stream is invalid data and needs to be re-acquired. The coded data stream is a binary data stream obtained by encoding the original data using a coding algorithm.
[0076] In the present application, the encoding algorithm can be selected and used according to actual needs. The subsequent embodiments of the present application are described by taking the encoding algorithm as the Protocol Buffers (Protobuf, PB for short) protocol algorithm as an example; the Protobuf protocol is a lightweight and efficient structured data storage format that can be used for structured data serialization. The PB protocol encoding can encode the original data into a data encoding format of a TV (Tag-Value, key-value) structure or a data encoding format of a TLV (Tag-Length-Value, key-length-value) structure. Using the PB protocol algorithm to encode the original data will obtain a binary data stream consisting of 0 and 1, which is the encoded data stream.
[0077] S420: Split the encoded data stream to obtain N fields, where N is a positive integer.
[0078] In the present application, each of the N fields obtained is a field of the smallest unit, which means that each field obtained is a field that cannot be further split. In other words, the present application splits the coded data stream until each field cannot be further split, that is, the splitting process of the coded data stream is completed.
[0079] In a possible implementation, the coded data stream includes N identifiers T i , i is a positive integer and i≤N. Wherein, T i Can be used to uniquely identify the i-th field, for example, in the PB protocol encoding, identify T i The process of splitting the coded data stream in the present application may include the following steps: first, read the identifier T from the coded data stream; i , and read the mark T i Variable length decoding is performed; variable length decoding is the reverse operation method of variable length coding; so-called variable length coding refers to a method of serializing an integer using one or more bytes. So-called variable length decoding refers to a method of deserializing an integer into one or more bytes. In the embodiment of the present application, the variable length coding is Varint coding and the variable length decoding is Varint decoding as an example for explanation. Then, the identifier separation formula is used to separate the identifier T from the variable length decoded i Separate the logo T i The included data type sub-identifier and field number sub-identifier; the identifier separation formula can refer to each identifier T i For example, in PB protocol coding, the calculation formula can be: field_number<<3|wire_type. Then, according to the identifier T iThe value of the data type sub-identifier contained therein determines the matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields; finally, let i=i+1, and iterate the above steps until N fields are obtained.
[0080] The data type sub-identifier can be a unique identifier of the data type of each field, used to indicate the data type of the field, for example, the data type sub-identifier can be represented by wire_type. The field number sub-identifier can be a unique identifier of each field in the encoded data stream, used to indicate the number of the field in the encoded data stream, for example, the data type sub-identifier can be represented by field_number.
[0081] S430: Analyze the data features contained in each of the N fields respectively to determine the data type of each field.
[0082] In this application, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data; wherein the identifier T of the i-th field i As the unique identifier of the i-th field; the field data of the i-th field is the data of the i-th field itself, and the field data may include but is not limited to one or more data in integers and strings. The data type of the i-th field can be divided into the first encoding format type and the second encoding format type based on the encoding format of the i-th field. For example, based on the encoded data stream of the PB protocol, the first encoding format type can be a key-value (Tag-Value) encoding format type. If the data type of the i-th field is the first encoding format type, then the identifier T of the i-th field i is stored as a key, and the field data of the i-th field is stored as a Value. The second encoding format type can be a Tag-Length-Value. If the data type of the i-th field is the second encoding format type, the identifier T of the i-th field i is stored as a key, the field data of the ith field is stored as Value, and the length of the data field in Value is stored as Length. Furthermore, the second encoding format type can be further subdivided, for example, into a string type, a byte type, and the like.
[0083] S440: Determine a decoding method corresponding to each field according to the data type of each field.
[0084] Different data types have different corresponding decoding methods. This application analyzes the data features of each field in N fields. After determining the data type of each field, the decoding method corresponding to each field can be determined according to the data type of each field. In N fields, the decoding methods between different fields may be the same or different.
[0085] In a possible implementation, it can be seen from the above that the data type of the field may include: a first encoding format type and a second encoding format type, the first encoding format type may be a key-value (Tag-Value) encoding format type, and the second encoding format type may be a key-length-value (Tag-Length-Value). The decoding method of each field is determined according to the data type of each field. Therefore, the process of determining the decoding method of any field (taking the i-th field as an example) may include:
[0086] If the data type of the i-th field is the first encoding format type, it is determined that the decoding method corresponding to the i-th field is a variable-length decoding method.
[0087] If the data type of the i-th field is the second encoding format type, and the data type of the i-th field is a character string type; then it is determined that the decoding method corresponding to the i-th field is a character string decoding method.
[0088] If the data type of the i-th field is the second encoding format type, and the data type of the i-th field is the byte type; then it is determined that the decoding method corresponding to the i-th field is no decoding required.
[0089] S450: Decode each field according to the decoding method corresponding to each field to restore the original data.
[0090] In the present application, each field is decoded according to the decoding method corresponding to each field. The decoding process can be to decode each field in turn according to the decoding method of each field, or to decode N fields in parallel according to the decoding method of each field in the N fields. This application does not limit this.
[0091] In a possible implementation, each field is decoded according to the decoding method corresponding to each field to obtain the decoding result of each field; for example, in the aforementioned N fields, if the decoding method of the i-th field is a variable-length decoding method, then the i-th field is subjected to variable-length decoding to obtain a variable-length decoding result; if the decoding method of the i-th field is a string decoding method, then the i-th field is subjected to string decoding, for example, using the UTF-8 (Universal Character Set / Unicode Transformation Format, 8-bit) decoding algorithm to decode and obtain a string decoding result; if the decoding method of the i-th field is no need to decode, then the field data in the i-th field is directly output as the decoding result. Then, the decoding results of each field are spliced to obtain the original data corresponding to the coded data stream; here, since the N fields have a certain order in the coded data stream, the splicing is performed according to the order of each field in the coded data stream, for example, the decoding result of the first field is spliced after the decoding result of the second field, the decoding result of the second field is spliced after the decoding result of the third field, and so on.
[0092] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate.
[0093] The following is an explanation using the Protocol Buffers (Protobuf, PB for short) protocol algorithm as an example, that is, the encoded data stream is a binary encoded data stream obtained by encoding the original data using the PB protocol algorithm.
[0094] In one possible implementation, see Figure 5 , Figure 5 Schematic diagram of the structure of the coded data stream provided in the embodiment of the present application. Figure 5As shown, a message (message) is encoded by the PB protocol algorithm and the encoded data stream obtained contains multiple fields (field). The encoding format of these fields can be Tag-Length-Value (key-length-value) format or Tag-Value (key-value) format.
[0095] Each field contains a tag, which is the unique identifier of the field. The tag can also be called a key. The tag can be composed of two parts: field_number (field number) and wire_type (data type). The field_number is used as a field number sub-identifier to indicate the sequence number of the field in the encoded data stream; the wire_type is used as a data type sub-identifier to indicate the data type of the field data in the field. The calculation method of the tag can be field_number<<3|wire_type, and the encoding method of the tag can be Varints encoding (variable length encoding). The relationship between the meaning of the field wire_type and the encoding format corresponding to the field can be shown in Table 1 below:
[0096] Table 1: Mapping between field data types and field encoding formats
[0097]
[0098]
[0099] It can be seen from Table 1 above that when the wire_type of a field is 0, 1 or 5, the encoding format of the field is the Tag-Value format; when the wire_type is 2, the encoding format is the Tag-Length-Value format.
[0100] Next, the rules of Varints encoding (variable length encoding) and corresponding examples are introduced:
[0101] 1) The most significant bit (MSB) of each Byte is the flag bit. If the flag bit is 1, it means there are other bytes after the Byte; if the flag bit is 0, it means the Byte is the last Byte. Among them, 1 Bytes (byte) = 8 bits (bits / bit).
[0102] 2) The lower 7 bits of each Byte are used to store the value.
[0103] 3) The Varints method uses little-endian byte order (the last byte is placed first when decompressing the value).
[0104] For example, take the number 1 as an example: the binary is 0000 0001, the highest bit is 0, indicating that there are no more bytes behind, and the remaining 7 bits are the value bits, "000 0001" is obviously 1. Another example, take the number 300 as an example: its representation under the Varints encoding rule is 1010 1100 0000 0010. First, the first byte is 1010 1100, the highest bit is 1, indicating that there are more bytes behind; the content of the first byte is the last 7 bits, that is, 010 1100. Then, the second byte is 0000 0010, the highest bit is 0, indicating that there are no more bytes behind; the content of the second byte is the last 7 bits, that is, 000 0010. Finally, because the variable-length encoding is "low-endian", the actual bytes are 000 0010 010 1100 = 1 0010 1100 = 300.
[0105] Based on the above introduction, after the present application obtains the coded data stream encoded based on the PB protocol, the coded data stream can be split and processed, wherein the coded data stream may include N identifiers T i , i is a positive integer and i≤N; each identifier T i The process of splitting the coded data stream in this application may include the following steps:
[0106] ① Read the identifier T from the encoded data stream i , and read the mark T i Perform variable length decoding; since each tag in the coded data stream is obtained by using variable length coding (Varints coding); therefore, the read identifier T i Perform variable length decoding.
[0107] ②Use the identifier separation formula to decode the identifier T from the variable length i Separate the logo T i The included data type sub-identifier and field number sub-identifier; the identifier separation formula can refer to the identifier T i The calculation formula, for example, in PB protocol encoding, the calculation formula can be: field_number<<3|wire_type. The data type sub-identifier can indicate the data type of the field. In PB encoding, the data type sub-identifier is represented by wire_type. The field number sub-identifier can be used to indicate the sequence number of the field in the encoded data stream. In PB encoding, the field number sub-identifier is represented by field_number.
[0108] ③According to the mark T i The value of the included data type sub-identifier determines the matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields.
[0109] ④ Let i=i+1, and iteratively execute the above steps until N fields are obtained.
[0110] For example, if a string of serialized binary data (encoded data stream) is received, you can first read a marker T i (i.e. a Tag), and then read the tag T i Perform variable length decoding, using the identifier T i The calculation formula separates wire_type (specifically the identifier T i The last 3 digits of the wire_type are read. The encoding format of the field can be determined by referring to Table 1 above according to the value of wire_type. At the same time, field_number is shared. The sequence number of the field in the encoded data stream can be determined based on the value of field_number. The Value behind is read correctly according to wire_type. Then continue to read the next field, and iterate the above steps in sequence until N fields that cannot be split are determined.
[0111] For example, for a message (the encoded data stream obtained by the protobuf encoding algorithm), for example: 00001000 00001010 00010101 00000000 00000000 00000000 01000000. If the num1 field in the message is assigned a value of 10 and the num2 field is assigned a value of 1073741824. Based on the above description of the protobuf encoding rules, the obtained encoded data stream can be analyzed as follows:
[0112] From the above, we know that the Tag is obtained by variable-length coding. Therefore, the first byte (00001000) is read as the Tag of the first field based on the first MSB bit. The last 3 bits (000) indicate that the wire_type of the field is 0. The splitting method corresponding to wire_type = 0 can be a variable-length splitting method. Then, the encoded data stream is disassembled according to the variable-length splitting method to obtain the first field.
[0113] Disassembling the coded data stream in a variable length splitting manner may include, for example: reading the next byte (00001010) from the identifier (00001000) in the coded data stream, the MSB bit of the byte is 0, so it is determined that the read byte has an end flag bit, and thus the read byte is determined as the field data of the first field is: 00001010. The identifier and field data of the first field are taken as a complete field, thereby completing the disassembly of a field.
[0114] Next, read the next byte (00010101) in the encoded data stream as the tag of the second field. The last 3 bits (101) indicate that the wire_type of the field is 5. The splitting method corresponding to wire_type=5 can be the second length splitting method. Then, the encoded data stream is disassembled according to the second length splitting method to obtain the second field.
[0115] Decomposing the coded data stream in accordance with the second length splitting method may include, for example: starting from the coded data stream after the identifier (00010101), sequentially reading four bytes (00000000 00000000 0000000001000000). Then, the 4 bytes of data read are determined as the field data of the second field. Thus, the identifier and the field data of the second field are taken as a complete field, thereby completing the decomposition of one field. Next, for the third field, repeat the above steps, decomposing the coded data stream to obtain the third field, and so on. Finally, the coded data stream is decomposed to obtain N fields.
[0116] After the field splitting is completed, the data features contained in each of the N fields are analyzed to determine the data type of each field. Among them, any field in the N fields is represented as the i-th field, and the i-th field can contain the identifier T i The data type of the i-th field can be divided into the first encoding format type and the second encoding format type based on the encoding format of the i-th field. For example, based on the encoded data stream of the PB protocol, the first encoding format type can be a key-value (Tag-Value) encoding format type. If the data type of the i-th field is the first encoding format type, the identifier T of the i-th field i is stored as a key, and the field data of the i-th field is stored as a Value. The second encoding format type can be a Tag-Length-Value. If the data type of the i-th field is the second encoding format type, the identifier T of the i-th field i is stored as a key, the field data of the ith field is stored as Value, and the length of the data field in Value is stored as Length. Furthermore, the second encoding format type can be further subdivided, for example, into a string type, a byte type, and the like.
[0117] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is any unit value within the first value range, the data type of the i-th field is determined to be the first encoding format type. If the data type of the i-th field is the first encoding format type, the identifier T in the i-th field iThe field data is stored in a key-value manner. In the embodiment of the present application, it can be seen from the above that the value of the data type sub-identifier (wire_type) can be any value of 0, 1, 2, and 5. The first numerical range can include 0, 1, and 5, where 0, 1, and 5 are a unit value within the first numerical unit. For example, 0 can be the first unit value within the first numerical range, 1 can be the second unit value within the first numerical range, and 5 can be the third unit value within the first numerical range.
[0118] In a possible implementation, if the marker T i The value of the data type sub-identifier contained is the second value, then the data type of the i-th field is determined to be the second encoding format type; wherein, if the data type of the i-th field is the second encoding format type, then the identifier T in the i-th field i The field data is stored in a key-length-value format; wherein the length is used to represent the length of the field data in the i-th field. In the embodiment of the present application, as can be seen from the foregoing, the value of the data type sub-identifier (wire_type) can be any value among 0, 1, 2, and 5, and the second value can be 2.
[0119] Further, in the marker T i When the value of the data type sub-identifier contained is the second numerical value. Continue to analyze the data characteristics of the field data in the i-th field: if the data characteristics of the field data in the i-th field have string characteristics, then determine that the data type of the i-th field is a string type. Among them, the string characteristics may include UTF-8 encoding characteristics. Among them, UTF-8 encoding is a variable-length character encoding for Unicode (Unicode). It can be used to represent any character in the Unicode standard, and the first byte in its encoding is still compatible with ASCII (American Standard Code for Information Interchange), so that the original software that processes ASCII characters does not need to be modified or only a small modification is made before it can continue to be used.
[0120] In addition, if the data feature of the field data in the i-th field does not have a string feature, then according to the identifier T i The value of the contained field number sub-identifier is used to analyze whether the i-th field has an adjacent relationship with other fields; if not, the data type of the i-th field is determined to be a byte type.
[0121] In summary, each field is decoded according to the decoding method corresponding to each field to restore the original data. For example, if the decoding method corresponding to field 1 is variable-length decoding, field 1 is decoded by the variable-length decoding method to obtain original unit data 1; if the decoding method corresponding to field 2 is string decoding, field 2 is decoded by the string decoding method to obtain original unit data 2; if the decoding method of field 3 is no decoding required, the field data of field 3 is directly output as original unit data 3. By analogy, N original unit data corresponding to N fields are obtained, and they are spliced according to the order of each field in the encoded data stream to obtain the original data corresponding to the encoded data stream.
[0122] Next, a specific example is used to further illustrate the decoding processing method of the present application.
[0123] For example, for a message, if the first field in the message is assigned a value of 10 and the second field is assigned a value of 64. The binary data stream (i.e., the encoded data stream) serialized by the PB protocol algorithm can be expressed as: 0000100000001010 00010101 01000000 00000000 00000000 00000000. Based on the above method, the obtained encoded data stream can be analyzed to restore the original data. The process is as follows:
[0124] First, read the tag of the first field: read the first byte (00001000) from the encoded data stream according to the first MSB bit as the tag of the first field, and separate the data type sub-identifier wire_type and the field number sub-identifier field_number using the identifier separation method, that is, the last 3 bits (000) in the first byte represent the wire_type of the first field, and the remaining 5 bits (00001) in the first byte represent the field_number. It can be seen that the wire_type of the first field is 0, and the field_number is 1 (indicating that the number of the first field is 1). It can be seen that the splitting method of the first field is the variable-length splitting method, so the field data of the first field read from the encoded data stream using the variable-length splitting method is 00001010.
[0125] From wire_type=0, we know that the data type of the field data of the first field is the tag-value encoding format type, so the decoding method corresponding to the first field is the variable length decoding method. Therefore, variable length decoding is performed on 00001010 (the MSB bit needs to be removed during decoding). Since there is only one byte, the MSB bit is removed and the reverse order is still 0001010. The binary 0001010 represents the number: 10.
[0126] By analyzing the encoded data stream using the above method, the original data 10 of the first field in the message can be restored. It can be seen that the data obtained after the decoding process is exactly consistent with the original data.
[0127] Then, the tag of the second field is read, and the decoding process of the first field is referred to, so as to restore the original data of the second field in the message. Finally, the original data of the first field is concatenated with the original data of the second field to obtain the original data of the message.
[0128] In one possible implementation, after decoding each field according to the decoding method corresponding to each field, a decoding log can be generated and output according to the decoding result of each field. Among them, the decoding log may include: the encoded data stream, the decoding method corresponding to each field, and the decoding process of each field. Through this solution, the data content of the encoded data stream can be automatically analyzed by monitoring the protocol return packet to output the corresponding decoding log, which can be used to analyze and locate problems in the decoding process, and can avoid the situation where the key log is missing due to human factors and the cause of the problem cannot be located.
[0129] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate.
[0130] Based on the above analysis, the following is a detailed introduction to the splitting process of the encoded data stream. Figure 6 , Figure 6 is a flow chart of a splitting processing method provided in an embodiment of the present application, wherein the splitting processing method can be applied to a computer device, and, Figure 6 The embodiment may be Figure 4 A specific embodiment of step S420. Figure 6As shown, the splitting processing method may include steps S610 to S670. Among them:
[0131] S610: Determine whether the encoded data stream is valid.
[0132] In a possible implementation, after obtaining the coded data stream, the computer device may first determine the validity of the coded data stream, and determining whether the coded data stream is valid may include: determining whether the coded data stream is empty, or whether the coded data stream has a length, etc. In this way, the validity of the obtained coded data stream can be determined, thereby providing a guarantee for the subsequent data analysis.
[0133] If it is determined that the coded data stream is valid, then step S620 is continued. If it is determined that the coded data stream is invalid, then the coded data stream can be re-acquired until the acquired coded data stream is valid.
[0134] S620: Read an identifier.
[0135] In a possible implementation, after obtaining the coded data stream, based on the above analysis of the coded data stream, each field in the coded data stream is stored in a data format of Tag-Value or Tag-Length-Value, and the Tag of each field is a unique identifier of the field. The coded data stream may include N identifiers T i , i is a positive integer and i≤N. And, any field in the N fields is represented as the i-th field, and the i-th field contains the identifier T i For example, an identifier read by the computer device from the coded data stream may be the identifier T of the i-th field. i , which is the key of the i-th field.
[0136] S630: Extract the data type sub-identifier.
[0137] In a possible implementation, since the Tag (identifier T i ) are obtained through variable length coding, so for the extracted identifier T i First, variable length decoding can be used to decode the marker T i For example, the obtained identifier T of a certain field i is: 0001 0010, then according to the identifier T i The calculation formula is field_number<<3|wire_type. It can be obtained from the identifier T after variable length decoding. i Separate the logo T iThe data type sub-identifier (such as wire_type) and field number sub-identifier (such as field_number) included. That is, the last three digits of 0001 0010 are the data type sub-identifier, and the first five digits of 0001 0010 are the field number sub-identifier.
[0138] S640: Read the next byte from the encoded data stream.
[0139] From the above analysis, it can be known that each data type sub-identifier corresponds to a splitting method, that is, the corresponding splitting method can be determined according to the value of the data type sub-identifier. Therefore, according to the value of the data type sub-identifier extracted in S630, the corresponding splitting method of the field can be determined, and according to the splitting method, how to read the field data of the field in the encoded data stream can be determined.
[0140] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is the first unit value in the first numerical range, it is determined that the splitting method that matches the first unit value is a variable-length splitting method. The first numerical range may include 0, 1, and 5, wherein 0, 1, and 5 are respectively a unit value in the first numerical unit. For example, 0 can be the first unit value in the first numerical range. This means that if the value of the data type sub-identifier extracted from the field is 0, it can be determined that the splitting method that matches 0 is a variable-length splitting method. Furthermore, the encoded data stream is disassembled according to the variable-length splitting method to obtain a field.
[0141] Furthermore, the process of disassembling the coded data stream in a variable length splitting manner to obtain a field may be as follows: from the coded data stream at the position of the marker T i The next byte is read sequentially from the position after that. Further, after reading the next byte, it can be determined whether the next byte has an end flag. If the next byte read does not have an end flag, the next byte is read sequentially until a byte with an end flag is read; if the next byte read has an end flag, the byte read is used as the field data of the field.
[0142] Each byte is composed of 8 bits. The standard for judging whether a byte has an end flag is based on the highest bit (MSB) of the byte. In addition, the encoded data stream is a binary data stream, so the highest bit of the byte includes two cases: 0 and 1. If the highest bit of the byte is 0, it means that the byte has an end flag; if the highest bit of the byte is 1, it means that the byte does not have an end flag.
[0143] Therefore, if the next byte read does not have an end flag, the next byte is read sequentially until a byte with an end flag is read; then, all the bytes read are combined into field data of the i-th field in the reading order. For example, in the coded data stream: 0001 0000 1000 1000 0000 0001..., the first byte 0001 0000 is the identifier of a certain field. According to the above analysis of the field identifier, the value of the data type sub-identifier of the field (the last three bits 000) is 0, so the next byte read from the coded data stream at the identifier is: 1000 1000. Since the highest bit of the byte is 1, the next byte of the byte is read sequentially from the coded data stream: 0000 0001. Since the highest bit of the byte is 0, the byte has an end flag, and the reading is terminated. The two bytes read are combined into the field data of the field: 1000 1000 0000 0001. In addition, the field data of the field is also called the value of the field. Thus, through the above method, a complete field can be read from the encoded data stream.
[0144] S650: Read 64-bit data from the encoded data stream.
[0145] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is the second unit value within the first numerical range, then the splitting method that matches the second unit value is determined to be the first length splitting method. The first numerical range may include 0, 1, and 5, where 0, 1, and 5 are each a unit value within the first numerical unit. For example, 1 can be the second unit value within the first numerical range. This means that if the value of the data type sub-identifier extracted for the field is 1, then it can be determined that the splitting method that matches 1 is the first length splitting method, and the encoded data stream is disassembled according to the first length splitting method to obtain a field.
[0146] Further, the process of disassembling the coded data stream according to the first length splitting method to obtain a field may be as follows: i The first length of bytes is sequentially read from the position after the first length; the bytes of the first length read are determined as the field data of the i-th field. Wherein, when the value of the data type sub-identifier is 1, the first length can be 64 bits / bit (8 bytes), so the identifier T located in the field in the coded data stream can be i The 64-bit data is sequentially read from the position after that, and the 64-bit data read is determined as the field data of the field. In addition, the field data of the field is also called the value of the field. Thus, a complete field can be read from the encoded data stream in the above manner.
[0147] For example, in the coded data stream: 0001 0001 1000 1000 0000 0001 0000 0001 1000 10000000 0001 0000 0001 0000 0001 1000 1000..., the first byte 0001 0001 is the identifier of a certain field. According to the above analysis of the field identifier, the value of the data type sub-identifier of the field (the last three bits 001) is 1. Therefore, the 8 bytes (64 bits / bits) located at the identifier are read from the coded data stream: 1000 1000 0000 0001 00000001 1000 1000 0000 0001 0000 0001 0000 0001 1000 1000. The 8 bytes read are used as the field data of the field.
[0148] S660: Read 32-bit data from the encoded data stream.
[0149] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is the third unit value within the first numerical range, then the splitting method that matches the third unit value is determined to be the second length splitting method. The first numerical range may include 0, 1, and 5, where 0, 1, and 5 are respectively a unit value within the first numerical unit. For example, 5 can be the third unit value within the first numerical range. This means that if the value of the data type sub-identifier extracted for the field is 5, then it can be determined that the splitting method that matches 5 is the second length splitting method, and the encoded data stream is disassembled according to the second length splitting method to obtain a field.
[0150] Further, the process of disassembling the coded data stream according to the second length splitting method to obtain a field may be as follows: from the coded data stream at the position of the marker T i The second length of bytes is sequentially read from the position after the ith field; the bytes of the second length read are determined as the field data of the ith field. Wherein, when the value of the data type sub-identifier is 5, the second length can be 32 bits / bit (4 bytes), so the identifier T located in the field in the coded data stream can be i Then, 4 bytes of data are sequentially read from the position after that, and the 4 bytes of data read are determined as the field data of the field. In addition, the field data of the field is also called the value of the field. In the above way, a complete field can be read from the encoded data stream.
[0151] For example, in the coded data stream: 0001 0101 1000 1000 0000 0001 0000 0001 1000 10000000 0001 0000 0001 0000 0001 1000 1000..., the first byte: 0001 0101 is the identifier of a certain field. According to the above analysis of the field identifier, the value of the data type sub-identifier of the field (the last three bits 101) is: 5. Therefore, the 4 bytes (32 bits / bit) located at the identifier are read from the coded data stream: 1000 1000 0000 0001 00000001 1000 1000. The 4 bytes read are used as the field data of the field.
[0152] S670: Calculate the length of Tag-Length-Value.
[0153] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is the second numerical value, it is determined that the splitting method matching the second numerical value is the specified length splitting method. The second numerical value may be 2. This means that if the value of the data type sub-identifier of the extracted field is 2, it can be determined that the splitting method matching 2 is the specified length splitting method, and the encoded data stream is disassembled according to the specified length splitting method to obtain a field.
[0154] Further, based on the above analysis (as shown in Table 1), if the value of the data type sub-identifier of a field is 2 (wire_type=2), it can be determined that the data encoding format / storage format of the field is Tag-Length-Value. Disassembling the encoded data stream according to the specified length splitting method to obtain one or more fields may include: first, from the identifier T i Get the specified length from the encoded data stream; then, get the length from the code at the location marked T i Starting from the position after that, bytes of the specified length are sequentially read; the bytes of the specified length read are determined as the field data of the i-th field.
[0155] For example, if in the coded data stream: 0001 0010 0000 0011 0000 0001 0000 0001 10001000 0000 0001 0000 0001 0000 0001 1000 1000..., the first byte 0001 0010 is the identifier of a certain field. According to the above analysis of the field identifier, the value of the data type sub-identifier of the field (the last three bits 010) is 2. Therefore, the next byte read from the coded data stream at the identifier is the length of the field data. The length of the field data is: 0000 0011, that is, 3 (specified length). Therefore, the byte at the identifier T can be read from the coded data stream. i Starting from the second byte, 3 bytes are read sequentially: 0000 0001 0000 0001 1000 1000; and the read 3 bytes are used as the field data of the field.
[0156] In a possible implementation, during the process of disassembling the encoded data stream according to the specified length splitting method, if the field data of the i-th field contains multiple identifiers, and the values of the field number sub-identifiers contained in the multiple identifiers have an adjacent relationship, it means that the i-th field is a message and needs to be split again. Therefore, the i-th field is recursively split to obtain P fields, where P is a positive integer.
[0157] Among them, analyzing whether the values of the field number sub-identifiers have an adjacent relationship may include: determining whether the field number sub-identifiers of each identifier have an increasing relationship in the encoded data stream. For example, if identifier 1 includes a field number sub-identifier of 1, identifier 2 includes a field number sub-identifier of 2, and identifier 3 includes a field number sub-identifier of 3, it can be determined that the three field number sub-identifiers have an adjacent relationship; for another example, if identifier 1 includes a field number sub-identifier of 3, identifier 2 includes a field number sub-identifier of 2, and identifier 3 includes a field number sub-identifier of 1, it can be determined that the three field number sub-identifiers do not have an adjacent relationship. It should be noted that the values of the field number sub-identifiers do not need to satisfy a gradient increasing relationship, but only need to satisfy an increasing relationship. A gradient increasing relationship means that the difference between any two numerical values is the same. For example: 1, 2, 3, 4, 5..., refers to a gradient increase, and for another example: 1, 2, 3, 5, 8..., is increasing, but not a gradient increase. In the present application, it is only necessary for the field number sub-identifiers to satisfy an increasing relationship to determine that the fields have an adjacent relationship, without further limiting the need to satisfy a gradient increasing relationship. Of course, if the field number sub-identifiers satisfy a gradient increasing relationship, then they must also have an adjacent relationship.
[0158] For example, the read field data includes multiple identifiers, assuming that it includes identifier 1: 0010 0010 and identifier 2: 0010 1010, the value of the field number sub-identifier (the first five digits 00100) contained in identifier 1 is 4, and the value of the field number sub-identifier (the first five digits 00101) contained in identifier 2 is 5. Since the values of the field number sub-identifiers (2 and 3) of the two identifiers included in the field data have an adjacent relationship, the field data can continue to be split until the field data can no longer be split. The splitting process of the field data can refer to the splitting process of the encoded data stream in this application, and this application will not repeat it here.
[0159] In the embodiment of the present application, by reading and analyzing each identifier, the data type sub-identifier and field number sub-identifier contained in each identifier can be determined, and then the splitting method of the field can be determined according to the value of the data type sub-identifier contained in each identifier, and the splitting method of the field can be completed from the coded data stream to obtain one or more fields. Finally, until each field can no longer be split, the splitting of the coded data stream can be completed to obtain N fields. Since the data features in the coded data stream are automatically analyzed to complete the splitting of the fields, there is no need to manually find the corresponding protocol file to split the fields, so the present application can improve the efficiency of the splitting process.
[0160] based on Figure 6 In the embodiment, the N fields obtained after the encoded data stream is split and processed can then be analyzed for data features contained in each of the N fields, thereby determining a decoding method corresponding to each field, and decoding each field according to the decoding method corresponding to each field. Figure 7 , Figure 7 is a flow chart of a field decoding method provided in an embodiment of the present application. The field decoding method can be applied to a computer device, such as Figure 7 As shown, the field decoding method may include steps S710 to S770. Among them:
[0161] S710: Determine whether the field is valid.
[0162] In a possible implementation, after obtaining a field, the computer device may first determine the validity of the field. Determining whether the field is valid may include: determining whether the field is empty, or whether the field has a length, etc. In this way, the validity of the obtained field can be determined, thereby providing a guarantee for the subsequent data analysis.
[0163] If it is determined that the field is valid, then step S720 is continued. If it is determined that the field is invalid, the field can be re-acquired until the acquired field is valid.
[0164] S720: Extract the data type sub-identifier.
[0165] In a possible implementation, since the tag (identifier T i ) are obtained through variable length coding, so for the extracted identifier T i First, variable length decoding can be used to decode the marker T i For example, the obtained identifier T of a certain field i is: 0001 0010, then according to the identifier T i The calculation formula is field_number<<3|wire_type. It can be obtained from the identifier T after variable length decoding. i Separate the logo T i The data type sub-identifier (such as wire_type) and field number sub-identifier (such as field_number) included. That is, the last three digits of 0001 0010 are the data type sub-identifier, and the first five digits of 00010010 are the field number sub-identifier.
[0166] S730: variable length decoding.
[0167] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is any unit value within the first numerical range, it can be determined that the decoding method corresponding to the i-th field is a variable-length decoding method. The first numerical range may include 0, 1, and 5, where 0, 1, and 5 are unit values within the first numerical unit, respectively. For example, 0 can be the first unit value within the first numerical range. This means that if the value of the data type sub-identifier extracted for the field is any value among 0, 1, and 5, it can be determined that the decoding method corresponding to the i-th field is a variable-length decoding method.
[0168] For example, based on the above introduction to the rules of variable-length coding, if wire_type=0, the rules of variable-length decoding mainly include: removing the highest bit of each byte and combining the bytes with the highest bit removed in reverse order, and restoring the original data corresponding to the field according to the recombined binary data. For example, the wire_type of a field is 0, and the field data of the field is 1000 1000 0000 0001. After removing the highest bit of each byte, 000 1000000 0001 is obtained, and it is combined in reverse order to form new binary data: 000 0001 000 1000, so the original data restored to the field is 136. For another example, the field data of a field is 0000 1000. After removing the highest bit of each byte, 000 1000 is obtained. Since there is only one byte, the new binary data combined in reverse order is still: 0001000, so the original data restored to the field is 8.
[0169] The reverse order refers to changing the order of data from the first direction to the second direction to the order of data from the second direction to the first direction. The first direction may be the left direction, and the second direction may be the right direction. For example, if a certain data is arranged from left to right as [1 2 3 4 5], the reverse order of the data may be arranged from right to left. Therefore, after arranging the data from right to left, [5 4 3 2 1] may be obtained.
[0170] In one possible implementation, if wire_type=1, the field data of the field includes 8 bytes of binary data. Since it is a fixed-length read in this case (wire_type=1), there is no need to remove the highest bit of each byte when performing variable-length decoding on the field data of the field, but the 8 bytes need to be combined in reverse order and converted into the corresponding original data. For example, the wire_type of a field is 1, and the field data of the field is: 0000000000000000 00000000 01000000 00000000 00000000 00000000 00000000, these 8 bytes are combined in reverse order: 00000000 00000000 00000000 00000000 01000000 00000000 00000000000000, so the original data of the field is restored to 1073741824.
[0171] Similarly, if wire_type=5, the field data of the field includes 4 bytes of binary data. Since the fixed length is read in this case (wire_type=5), it is not necessary to remove the highest bit of each byte when performing variable-length decoding on the field data of the field, but it is necessary to combine these 4 bytes in reverse order and convert them into the corresponding original data. For example, the wire_type of a field is 5, and the field data of the field is: 01010100 00000000 0000000000000000, and these 8 bytes are combined in reverse order as: 00000000 00000000 00000000 01010100, so the original data of the field is restored to 84.
[0172] S740: Determine whether it has symbol features.
[0173] After variable-length decoding is performed on the field data of the field, it can be further determined whether the variable-length decoded field data contains a sign feature. If the variable-length decoded field data contains a sign feature, the variable-length decoded field data is further decoded using an integer compression decoding method to obtain the original data of the field. If the variable-length decoded field data does not contain a sign feature, the variable-length decoded field data is used as the original data of the field. In the present application, the sign feature may include a minus sign.
[0174] First, let's explain the encoding of negative numbers in Varints. There is a huge difference between signed int types (sint32 and sint64) and "standard" int types (int32 and int64) when encoding negative numbers. If int32 or int64 is used as the type for negative numbers, the resulting varint is always ten bytes; that is, negative numbers like -1, -2 will also take up more bytes. In fact, it is treated as a very large unsigned integer. If one of the signed types (sint32 and sint64) is used, the resulting varint uses a modified ZigZag encoding (integer compression encoding), which is more efficient. ZigZag encoding maps signed numbers to unsigned numbers so that numbers with smaller absolute values (such as -1) also have smaller varint encoding values. The way this is done is to "zigzag" back and forth through positive and negative integers, encoding -1 as 1, 1 as 2, -2 as 3... and so on. This is shown in Table 2 below:
[0175] Table 2: Integer compression encoding
[0176] negative number Encoded as 0 0 -1 1 1 2 -2 3 2 4 -3 5 ... ... 2147483647 4294967294 -2147483648 4294967295
[0177] In a possible implementation, in this application, if a field has a sign feature, it may mean that the field is a negative number. Based on the above-mentioned analysis of the variable-length coding of negative numbers, ZigZag decoding is used when decoding negative numbers, that is, after the positive number is solved, it is mapped back to the original negative number according to the mapping relationship. For example, int32 val = -2 is set. The mapping results in 3, then the number 3 is encoded with Varints, and the result is stored or sent out. After receiving the data, the receiver performs Varints decoding to obtain the number 3, and then maps 3 back to -2.
[0178] S750: Analyze data characteristics of field data.
[0179] In a possible implementation, if the marker T i If the value of the data type sub-identifier contained is the second value, it is necessary to continue analyzing the data characteristics of the field data in the field (the i-th field). The second value may be 2, which means that if the value of the data type sub-identifier extracted for the field is 2, it is necessary to continue analyzing the data characteristics of the field data in the field, so as to determine the decoding method corresponding to the field.
[0180] S760: Determine whether the string has characteristics.
[0181] After analyzing the data features of the field data, it is then determined whether the data features of the field data in the field have string features. If the data features of the field data in the field have string features, the decoding method corresponding to the field is a string decoding method. If the data features of the field data in the field do not have string features, step S770 is executed.
[0182] In the present application, the string feature may include UTF-8 features, and the UTF-8 feature may include ASCII characters (such as symbols such as a, b, and c). For example, if the data feature of the field data of a certain field is: 1a 03 08 96 01, then the data feature of the field has a string feature. In a possible implementation, if the data feature of the field data in the i-th field has a string feature, then the data type of the i-th field is determined to be a string type, and therefore, the decoding method corresponding to the field is determined to be a string decoding method.
[0183] S770: Determine whether there is an adjacent relationship.
[0184] In a possible implementation, if the data feature of the field data in the i-th field does not have a string feature, it is necessary to identify the field data according to the identifier T iThe value of the contained field number sub-identifier is used to analyze whether the i-th field has an adjacent relationship with other fields. Furthermore, if there is no adjacent relationship between the field and other fields, the data type of the i-th field is determined to be a byte type, wherein no decoding is required for byte type data, and therefore, the decoding method corresponding to the field is determined to be no decoding required. If there is an adjacent relationship between the field and other fields, it is necessary to continue to split the field data of the field. The specific process of the splitting process can refer to the splitting process of the encoded data stream in this application, and this application will not repeat it here.
[0185] Among them, analyzing whether a certain field has an adjacent relationship with other fields may include: judging whether the field number sub-identifiers corresponding to each field have an increasing relationship in the encoded data stream. For example, if the field number sub-identifier of field 1 is 1, the field number sub-identifier of field 2 is 2, and the field number sub-identifier of field 3 is 3, it can be determined that field 1 has an adjacent relationship with field 2 and field 3; for another example, if the field number sub-identifier of field 1 is 3, the field number sub-identifier of field 2 is 2, and the field number sub-identifier of field 3 is 1, it can be determined that field 1 does not have an adjacent relationship with field 2 and field 3. It should be noted that the field number sub-identifiers do not need to satisfy a gradient increasing relationship, but only need to satisfy an increasing relationship. A gradient increasing relationship means that the difference between any two numbers is the same. For example: 1, 2, 3, 4, 5..., refers to a gradient increase, and for another example: 1, 2, 3, 5, 8..., is increasing, but not a gradient increase. In the present application, it is only necessary that the field number sub-identifiers satisfy an increasing relationship to determine that the fields have an adjacent relationship, without further limiting the need to satisfy a gradient increasing relationship. Of course, if the field number sub-identifiers satisfy a gradient increasing relationship, then the fields must also have an adjacent relationship.
[0186] In summary, in this application, for each field, the data type sub-identifier of each field is extracted, and the decoding method of each field is determined according to the value of the data type sub-identifier. Then, based on the determined decoding method, the corresponding field is decoded according to the specific rules of the decoding method, so that the original data corresponding to each field can be obtained. It can be seen that the present application automatically analyzes the data features contained in each field and completes the decoding of each field. There is no need to manually search for the corresponding protocol file to decode the field. Therefore, the present application can improve the efficiency of the decoding process. In addition, the process of automatic reverse analysis and decoding does not rely on the protocol file, which can effectively improve the decoding success rate.
[0187] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a decoding processing device provided in an embodiment of the present application. The decoding processing device 800 can be applied to Figures 4 to 7The computer device in the corresponding method embodiment. The decoding processing device 800 may be a computer program (including program code) running in a lightweight node, for example, the decoding processing device 800 is an application software; the device may be used to execute the corresponding steps in the method provided in the embodiment of the present application. The decoding processing device 800 may include:
[0188] An acquisition unit 810 is used to acquire a coded data stream, where the coded data stream is a binary data stream obtained by encoding the original data;
[0189] The processing unit 820 is used to split the coded data stream to obtain N fields, where N is a positive integer;
[0190] The processing unit 820 is further configured to analyze the data features contained in each of the N fields to determine the data type of each field;
[0191] A determining unit 830, configured to determine a decoding method corresponding to each field according to a data type of each field;
[0192] The processing unit 820 is further configured to decode each field according to a decoding method corresponding to each field to restore the original data.
[0193] In a possible implementation, the coded data stream includes N identifiers T i , i is a positive integer and i≤N;
[0194] The processing unit 820 splits the coded data stream to obtain N fields, including:
[0195] Read the identifier T from the encoded data stream i , and read the mark T i Perform variable length decoding;
[0196] Use the identity separation formula to decode the identity T from the variable length i Separate the logo T i The included data type sub-id and field number sub-id;
[0197] According to the mark T i The value of the included data type sub-identifier determines the matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields;
[0198] Let i=i+1, and iteratively execute the above steps until N fields are obtained.
[0199] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0200] The processing unit 820 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0201] If the label T i If the value of the data type sub-identifier included is the first unit value within the first value range, it is determined that the splitting method matching the first unit value is the variable-length splitting method;
[0202] The processing unit 820 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0203] From the coded data stream located at marker T i The next byte is read sequentially starting from the position after that;
[0204] If the next byte read does not have an end flag, continue to read the next byte in sequence until a byte with an end flag is read;
[0205] All the bytes read are combined into field data of the i-th field in the order in which they are read.
[0206] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0207] The processing unit 820 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0208] If the label T i If the value of the data type sub-identifier included is a second unit value within the first value range, it is determined that the splitting method that matches the second unit value is the first length splitting method;
[0209] The processing unit 820 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0210] From the coded data stream located at marker T i Start reading the bytes of the first length sequentially from the position after that;
[0211] The bytes of the first length read are determined as the field data of the i-th field.
[0212] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0213] The processing unit 820 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0214] If the label T i If the value of the contained data type sub-identifier is the third unit value within the first value range, it is determined that the splitting method that matches the third unit value is the second length splitting method;
[0215] The processing unit 820 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0216] From the coded data stream located at marker T i Start reading the bytes of the second length sequentially from the position after that;
[0217] The read bytes of the second length are determined as field data of the i-th field.
[0218] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0219] The processing unit 820 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0220] If the label T i If the value of the data type sub-identifier included is the second value, it is determined that the splitting method matching the second value is the specified length splitting method;
[0221] The processing unit 820 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0222] From the coded data stream located at marker T i The position after that reads the specified length;
[0223] Continue to read the specified length of bytes from the encoded data stream sequentially according to the specified length;
[0224] The bytes of the specified length read are determined as the field data of the i-th field.
[0225] In a possible implementation, the processing unit 820 decomposes the coded data stream according to the matching decomposition mode to obtain one or more fields, further comprising:
[0226] If the field data of the i-th field contains multiple identifiers, and the values of the field number sub-identifiers contained in the multiple identifiers have an adjacent relationship, the i-th field is recursively split to obtain P fields, where P is a positive integer.
[0227] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0228] The processing unit 820 analyzes the data features contained in each of the N fields to determine the data type of each field, including:
[0229] If the label T i If the value of the data type sub-identifier contained is any unit value within the first value range, the data type of the i-th field is determined to be the first encoding format type; wherein, if the data type of the i-th field is the first encoding format type, the identifier T in the i-th field i And field data is stored in a key-value manner;
[0230] The determining unit 830 determines a decoding method corresponding to each field according to a data type of each field, including: determining that the decoding method corresponding to the i-th field is a variable-length decoding method.
[0231] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0232] The processing unit 820 analyzes the data features contained in each of the N fields to determine the data type of each field, including:
[0233] If the label T i The value of the data type sub-identifier contained is the second value, then the data type of the i-th field is determined to be the second encoding format type; wherein, if the data type of the i-th field is the second encoding format type, then the identifier T in the i-th field i The field data is stored in a key-length-value format; the length is used to represent the length of the field data in the i-th field;
[0234] Analyze data characteristics of field data in the i-th field;
[0235] If the data feature of the field data in the i-th field has a character string feature, then the data type of the i-th field is determined to be a character string type;
[0236] The determining unit 830 determines a decoding method corresponding to each field according to a data type of each field, including: determining that the decoding method corresponding to the i-th field is a character string decoding method.
[0237] In a possible implementation, analyzing the data features contained in each of the N fields to determine the data type of each field further includes:
[0238] If the data feature of the field data in the i-th field does not have a string feature, then according to the identifier T i The value of the contained field number sub-identifier is used to analyze whether the i-th field has an adjacent relationship with other fields;
[0239] If there is no adjacent relationship, the data type of the i-th field is determined to be a byte type;
[0240] The determining unit 830 determines a decoding method corresponding to each field according to a data type of each field, including: determining that a decoding method corresponding to the i-th field is no decoding required.
[0241] In a possible implementation, the processing unit 820 decodes each field according to a decoding method corresponding to each field to restore the original data, including:
[0242] Decode each field according to the decoding method corresponding to each field to obtain a decoding result of each field;
[0243] The decoding results of each field are concatenated to obtain the original data.
[0244] In a possible implementation, the processing unit 820 is further configured to perform the following operations:
[0245] Outputs the decoding log, which contains the encoded data stream, the decoding method corresponding to each field, and the decoding process flow of each field.
[0246] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate.
[0247] See also Fig. 9 , Fig. 9900 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figures 4 to 7 In the corresponding method embodiment, the computer device 900 includes: one or more processors 910; one or more input devices 920, one or more output devices 930 and a memory 940. The processor 910, the input device 920, the output device 930 and the memory 940 are connected via a bus 950. The memory 940 is used to store a computer program, and the computer program includes program instructions. The processor 910 is used to execute the program instructions stored in the memory 940, and perform the following operations:
[0248] Obtaining a coded data stream, where the coded data stream is a binary data stream obtained by encoding the original data;
[0249] The encoded data stream is split into N fields, where N is a positive integer;
[0250] Analyze the data features contained in each of the N fields respectively to determine the data type of each field;
[0251] Determine the decoding method corresponding to each field according to the data type of each field;
[0252] Decode each field according to the decoding method corresponding to each field to restore the original data.
[0253] In a possible implementation, the coded data stream includes N identifiers T i , i is a positive integer and i≤N;
[0254] The processor 910 splits the coded data stream to obtain N fields, including:
[0255] Read the identifier T from the encoded data stream i , and read the mark T i Perform variable length decoding;
[0256] Use the identity separation formula to decode the identity T from the variable length i Separate the logo T i The included data type sub-id and field number sub-id;
[0257] According to the mark T i The value of the included data type sub-identifier determines the matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields;
[0258] Let i=i+1, and iteratively execute the above steps until N fields are obtained.
[0259] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0260] The processor 910 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0261] If the label T i If the value of the data type sub-identifier included is the first unit value within the first value range, it is determined that the splitting method matching the first unit value is the variable-length splitting method;
[0262] The processor 910 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0263] From the coded data stream located at marker T i The next byte is read sequentially starting from the position after that;
[0264] If the next byte read does not have an end flag, continue to read the next byte in sequence until a byte with an end flag is read;
[0265] All the bytes read are combined into field data of the i-th field in the order in which they are read.
[0266] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0267] The processor 910 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0268] If the label T i If the value of the data type sub-identifier included is a second unit value within the first value range, it is determined that the splitting method that matches the second unit value is the first length splitting method;
[0269] The processor 910 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0270] From the coded data stream located at marker T i Start reading the bytes of the first length sequentially from the position after that;
[0271] The bytes of the first length read are determined as the field data of the i-th field.
[0272] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0273] The processor 910 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0274] If the label T i If the value of the contained data type sub-identifier is the third unit value within the first value range, it is determined that the splitting method that matches the third unit value is the second length splitting method;
[0275] The processor 910 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0276] From the coded data stream located at marker T i Start reading the bytes of the second length sequentially from the position after that;
[0277] The read bytes of the second length are determined as field data of the i-th field.
[0278] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0279] The processor 910 generates a signal according to the identifier T i The value of the included data type sub-identifier determines the matching split method, including:
[0280] If the label T i If the value of the data type sub-identifier included is the second value, it is determined that the splitting method matching the second value is the specified length splitting method;
[0281] The processor 910 disassembles the encoded data stream according to the matching splitting mode to obtain one or more fields, including:
[0282] From the coded data stream located at marker T i The position after that reads the specified length;
[0283] Continue to read the specified length of bytes from the encoded data stream sequentially according to the specified length;
[0284] The bytes of the specified length read are determined as the field data of the i-th field.
[0285] In a possible implementation, the processor 910 decomposes the coded data stream according to the matching decomposition mode to obtain one or more fields, further comprising:
[0286] If the field data of the i-th field contains multiple identifiers, and the values of the field number sub-identifiers contained in the multiple identifiers have an adjacent relationship, the i-th field is recursively split to obtain P fields, where P is a positive integer.
[0287] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0288] The processor 910 analyzes the data features contained in each of the N fields respectively to determine the data type of each field, including:
[0289] If the label T i If the value of the data type sub-identifier contained is any unit value within the first value range, the data type of the i-th field is determined to be the first encoding format type; wherein, if the data type of the i-th field is the first encoding format type, the identifier T in the i-th field i And field data is stored in a key-value manner;
[0290] The processor 910 determines a decoding method corresponding to each field according to a data type of each field, including: determining that a decoding method corresponding to an i-th field is a variable-length decoding method.
[0291] In a possible implementation, any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data;
[0292] The processor 910 analyzes the data features contained in each of the N fields respectively to determine the data type of each field, including:
[0293] If the label T i The value of the data type sub-identifier contained is the second value, then the data type of the i-th field is determined to be the second encoding format type; wherein, if the data type of the i-th field is the second encoding format type, then the identifier T in the i-th field i The field data is stored in a key-length-value format; the length is used to represent the length of the field data in the i-th field;
[0294] Analyze data characteristics of field data in the i-th field;
[0295] If the data feature of the field data in the i-th field has a character string feature, then the data type of the i-th field is determined to be a character string type;
[0296] The processor 910 determines a decoding method corresponding to each field according to a data type of each field, including: determining that a decoding method corresponding to the i-th field is a character string decoding method.
[0297] In a possible implementation, analyzing the data features contained in each of the N fields to determine the data type of each field further includes:
[0298] If the data feature of the field data in the i-th field does not have a string feature, then according to the identifier T i The value of the contained field number sub-identifier is used to analyze whether the i-th field has an adjacent relationship with other fields;
[0299] If there is no adjacent relationship, the data type of the i-th field is determined to be a byte type;
[0300] The processor 910 determines a decoding method corresponding to each field according to a data type of each field, including: determining that a decoding method corresponding to the i-th field is no decoding required.
[0301] In a possible implementation, the processor 910 decodes each field according to a decoding method corresponding to each field to restore the original data, including:
[0302] Decode each field according to the decoding method corresponding to each field to obtain a decoding result of each field;
[0303] The decoding results of each field are concatenated to obtain the original data.
[0304] In a possible implementation, the processor 910 is further configured to perform the following operations:
[0305] Outputs the decoding log, which contains the encoded data stream, the decoding method corresponding to each field, and the decoding process flow of each field.
[0306] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate.
[0307] In addition, it should be pointed out here that: the embodiment of the present application also provides a computer storage medium, and the computer storage medium stores a computer program executed by the decoding processing device 800 mentioned above, and the computer program includes program instructions. When the processor executes the above program instructions, it can execute the above Figures 4 to 7 The method in the corresponding embodiment, therefore, will not be repeated here. In addition, the description of the beneficial effects of the same method will not be repeated. For technical details not disclosed in the computer storage medium embodiment involved in this application, please refer to the description of the method embodiment of this application. As an example, the program instructions can be deployed on a computer device, or executed on multiple computer devices located in one location, or, executed on multiple computer devices distributed in multiple locations and interconnected by a communication network, and multiple computer devices distributed in multiple locations and interconnected by a communication network can constitute a blockchain system.
[0308] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device can perform the above Figures 4 to 7 The method in the corresponding embodiment will therefore not be described in detail here.
[0309] In the embodiment of the present application, a coded data stream is obtained, which is a binary data stream obtained after encoding the original data; the coded data stream is split to obtain N fields, where N is a positive integer; the data features contained in each of the N fields are analyzed respectively to determine the data type of each field, and the decoding method corresponding to each field is determined according to the data type of each field; then each field is decoded according to the decoding method corresponding to each field to restore the original data. It can be seen that the present application can automatically analyze and process the characteristics of the coded data stream itself, and based on the reverse analysis of the data characteristics of each field in the binary data stream, the corresponding decoding method of each field can be determined, and further, the decoding method of each field is decoded to restore the original data; through the automatic reverse analysis and decoding process of the present application, no manual search is required, which can effectively improve the efficiency of the decoding process. In addition, the automatic reverse analysis and decoding process does not rely on the protocol file, which can effectively improve the decoding success rate.
[0310] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the above-mentioned program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The above-mentioned storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0311] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A decoding processing method, characterized in that: The method comprises: Obtain a coded data stream, wherein the coded data stream is a binary data stream obtained by encoding the original data; the coded data stream includes N identifiers T i , i and N are both positive integers and i≤N; Read the identifier T from the encoded data stream i , and read the mark T i Perform variable length decoding; The identifier separation formula is used to separate the identifier T from the variable length decoded identifier T. i Separate the logo T i The included data type sub-id and field number sub-id; According to the identification T i The value of the included data type sub-identifier determines a matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields; Let i=i+1, and iterate the above steps until N fields are obtained; wherein any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data; Analyze the data features contained in the i-th field to determine the data type of the i-th field; wherein the data type includes: a first encoding format type and a second encoding format type; if the data type of the i-th field is the first encoding format type, then the identifier T in the i-th field i The field data is stored in a key-value manner. If the data type of the i-th field is the second encoding format type, the identifier T in the i-th field i and field data are stored in a key-length-value manner; the length is used to represent the length of the field data in the i-th field; Determining a decoding method corresponding to the i-th field according to a data type of the i-th field; The i-th field is decoded according to the decoding method corresponding to the i-th field to restore the original data.
2. The method according to claim 1, characterized in that According to the identification T i The value of the included data type sub-identifier determines the matching split method, including: If the identifier T i If the value of the data type sub-identifier included is a first unit value within a first value range, it is determined that the splitting method matching the first unit value is a variable-length splitting method; The step of disassembling the encoded data stream according to the matching splitting mode to obtain one or more fields includes: From the coded data stream located at the marker T i The next byte is read sequentially starting from the position after that; If the next byte read does not have an end flag, continue to read the next byte in sequence until a byte with an end flag is read; All the bytes read are combined into field data of the i-th field in the reading order.
3. The method according to claim 1, characterized in that According to the identification T i The value of the included data type sub-identifier determines the matching split method, including: If the identifier T i If the value of the data type sub-identifier included is a second unit value within the first value range, it is determined that the splitting method that matches the second unit value is the first length splitting method; The step of disassembling the encoded data stream according to the matching splitting mode to obtain one or more fields includes: From the coded data stream located at the marker T i Start reading the bytes of the first length sequentially from the position after that; The read bytes of the first length are determined as field data of the i-th field.
4. The method according to claim 1, characterized in that According to the identification T i The value of the included data type sub-identifier determines the matching split method, including: If the identifier T i If the value of the data type sub-identifier contained is a third unit value within the first value range, it is determined that the splitting method matching the third unit value is the second length splitting method; The step of disassembling the encoded data stream according to the matching splitting mode to obtain one or more fields includes: From the coded data stream located at the marker T i Start reading the bytes of the second length sequentially from the position after that; The read bytes of the second length are determined as field data of the i-th field.
5. The method according to claim 1, characterized in that According to the identification T i The value of the included data type sub-identifier determines the matching split method, including: If the identifier T i If the value of the data type sub-identifier included is a second numerical value, it is determined that the splitting method matching the second numerical value is a specified length splitting method; The step of disassembling the encoded data stream according to the matching splitting mode to obtain one or more fields includes: From the coded data stream located at the marker T i The position after that reads the specified length; Continue to sequentially read bytes of the specified length from the encoded data stream according to the specified length; The bytes of the specified length read are determined as field data of the i-th field.
6. The method according to any one of claims 1 to 5, characterized in that: The step of disassembling the encoded data stream according to the matched splitting mode to obtain one or more fields further includes: If the field data of the i-th field contains multiple identifiers, and the values of the field number sub-identifiers contained in the multiple identifiers have an adjacent relationship, the i-th field is recursively split to obtain P fields, where P is a positive integer.
7. The method according to claim 1, characterized in that The analyzing the data features contained in the i-th field to determine the data type of the i-th field includes: If the identifier T i If the value of the data type sub-identifier included is any unit value within the first value range, it is determined that the data type of the i-th field is the first encoding format type; The determining a decoding method corresponding to the i-th field according to a data type of the i-th field includes: determining that the decoding method corresponding to the i-th field is a variable-length decoding method.
8. The method according to claim 1, characterized in that The analyzing the data features contained in the i-th field to determine the data type of the i-th field includes: If the identifier T i If the value of the data type sub-identifier included is the second numerical value, it is determined that the data type of the i-th field is the second encoding format type; Analyzing data features of field data in the i-th field; If the data feature of the field data in the i-th field has a character string feature, determining that the data type of the i-th field is a character string type; The determining a decoding method corresponding to the i-th field according to a data type of the i-th field includes: determining that the decoding method corresponding to the i-th field is a character string decoding method.
9. The method according to claim 8, characterized in that The analyzing the data features contained in the i-th field to determine the data type of the i-th field further includes: If the data feature of the field data in the i-th field does not have a character string feature, then according to the identifier T i The value of the contained field number sub-identifier is used to analyze whether the i-th field and other fields have an adjacent relationship; If there is no adjacent relationship, determining that the data type of the i-th field is a byte type; The determining a decoding method corresponding to the i-th field according to a data type of the i-th field includes: determining that the decoding method corresponding to the i-th field is one that does not require decoding.
10. The method according to claim 1, characterized in that The decoding the i-th field according to the decoding method corresponding to the i-th field to restore the original data includes: Decoding each field according to a decoding method corresponding to each field to obtain a decoding result of each field; The decoding results of each field are concatenated to obtain the original data.
11. The method according to claim 1, characterized in that The method further comprises: A decoding log is output, wherein the decoding log includes the encoded data stream, a decoding method corresponding to each field, and a decoding process flow of each field.
12. A decoding processing device, characterized in that: The device comprises: The acquisition unit is used to acquire a coded data stream, wherein the coded data stream is a binary data stream obtained by encoding the original data; the coded data stream includes N identifiers T i , i and N are both positive integers and i≤N; A processing unit, configured to read a marker T from the encoded data stream i , and read the mark T i Perform variable length decoding; The processing unit is further configured to use a tag separation formula to separate the tag T from the tag T after the variable length decoding. i Separate the logo T i The included data type sub-id and field number sub-id; The processing unit is further configured to: i The value of the included data type sub-identifier determines a matching splitting method, and the encoded data stream is disassembled according to the matching splitting method to obtain one or more fields; The processing unit is further used to set i=i+1 and iteratively perform the above steps until N fields are obtained; wherein any one of the N fields is represented as the i-th field, and the i-th field contains the identifier T i and field data; The processing unit is further configured to analyze the data features contained in the i-th field to determine the data type of the i-th field; wherein the data type includes: a first encoding format type and a second encoding format type; if the data type of the i-th field is the first encoding format type, then the identifier T in the i-th field i The field data is stored in a key-value manner. If the data type of the i-th field is the second encoding format type, the identifier T in the i-th field i and field data are stored in a key-length-value manner; the length is used to represent the length of the field data in the i-th field; a determining unit, configured to determine a decoding method corresponding to the i-th field according to a data type of the i-th field; The processing unit is further used to decode the i-th field according to the decoding method corresponding to the i-th field to restore the original data.
13. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 11 is performed.
