Data analysis method and device, protocol analyzer generation method and device, equipment and medium

By processing the target protocol into a tree structure and generating parsing code, the problem of inefficient addition of new protocols in the protocol parser is solved, and efficient data parsing is achieved.

CN120066511APending Publication Date: 2025-05-30QI AN XIN TECHNOLOGY GROUP INC
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202311617645.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-29
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The inefficiency of adding new protocols to protocol parsers in the prior art leads to a reduced data parsing efficiency.

Method used

The target protocol is processed into a tree structure, with nodes corresponding to field clusters, and the connection represents the jump relationship between field clusters. The parsing code is generated and added to the protocol parser to avoid repeated code testing and repair.

Benefits of technology

Improve the efficiency of adding protocols and data parsing in protocol parsers, and reduce the workload of manual development, testing and repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066511A_ABST
    Figure CN120066511A_ABST
Patent Text Reader

Abstract

The invention provides a data analysis method and device, a protocol analyzer generation method and device, equipment and a medium, and the data analysis method comprises the steps: receiving to-be-analyzed data, packaging the to-be-analyzed data based on a target protocol, enabling the target protocol to be of a tree structure, enabling nodes in the tree structure to correspond to field clusters in the target protocol, connecting lines between the nodes correspond to jump relations between the field clusters; and analyzing the to-be-analyzed data on the basis of the field cluster and the jump relationship in the tree structure by running an analysis code, and generating the analysis code on the basis of the target protocol and passing the test. In this way, the target protocol with the preset format can be directly processed into the parsing code and then added to the protocol parser, work such as code testing and repairing does not need to be carried out again, and the adding efficiency of the protocol in the protocol parser is improved. After the to-be-parsed data is received, the parsing code in the protocol parser can be directly used for data parsing, so that the data parsing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data transmission, and in particular, to a method, apparatus, device, and medium for data parsing and protocol parser generation. Background Art

[0002] When transmitting data between different devices, the transmitted data needs to be encapsulated according to a protocol pre-agreed by each device. One device sends the encapsulated data to another device, and the other device needs to use a protocol parser to read fields from the encapsulated data. When a new protocol emerges, the protocol parser needs to add this protocol so that it can parse the data encapsulated by the new protocol.

[0003] Currently, to add a new protocol to a protocol parser, the main approach is as follows: Relevant personnel first develop parsing code according to the new protocol. Then, functional testing, stability testing, etc. are performed on the parsing code. When problems are detected in the parsing code, the parsing code is repaired for the problems. After the parsing code is repaired, the repaired parsing code is tested again. Repeated repair and testing are carried out until the repaired parsing code passes the test. Finally, the parsing code that passes the test is added to the protocol parser. In this way, the protocol parser can parse the data encapsulated by the new protocol through the added parsing code.

[0004] With the increasing frequency of data interaction, new protocols will emerge continuously. Correspondingly, parsing code for new protocols needs to be continuously added to the protocol parser. For each addition of parsing code for a new protocol in the protocol parser, relevant personnel need to carry out a round of code development, code testing, and code repair work. These works will consume a large amount of time, reduce the efficiency of adding new protocols in the protocol parser, and further reduce the data parsing efficiency. Summary of the Invention

[0005] The purpose of the embodiments of this application is to provide a method, apparatus, device, and medium for data parsing and protocol parser generation to improve data parsing efficiency.

[0006] To solve the above technical problems, the embodiments of this application provide the following technical solutions:

[0007] The first aspect of this application provides a data parsing method, which includes: receiving data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; running parsing code to parse the data to be parsed based on the field clusters and jump relationships in the tree structure, where the parsing code is generated based on the target protocol and has passed the test.

[0008] Compared with the prior art, the data parsing method provided in the first aspect of the present application processes the target protocol into a tree structure, with nodes corresponding to field clusters and the connections between nodes corresponding to the jump relationships between field clusters. In this way, the target protocol with a preset format can be directly processed into parsing code and then added to the protocol parser, eliminating the need for additional code testing, repair, etc., and improving the efficiency of adding protocols in the protocol parser. After receiving the data to be parsed, the parsing code in the protocol parser can be directly used for data parsing, thereby improving the data parsing efficiency.

[0009] In some alternative embodiments of the first aspect of the present application, the number of field clusters is multiple, at least one field cluster includes jump information indicating the jump relationship, and the parsing code is stored in the protocol parser; the parsing of the data to be parsed based on the field clusters and jump relationships in the tree structure by running the parsing code includes: when the protocol parser runs, calling the parsing code therein, determining the jump relationship according to the jump information in the at least one field cluster; according to the jump relationship, respectively reading the fields in the corresponding field clusters until all the field clusters with jump relationships are read; using the read fields as the parsing result of the data to be parsed.

[0010] Through the jump information in the field cluster, the jump relationship between each field cluster in the target protocol can be determined, so as to parse the data using each field cluster in the target protocol according to the jump relationship, avoiding data parsing using incorrect field clusters and improving the accuracy of data parsing.

[0011] In some alternative embodiments of the first aspect of the present application, the jump information includes a jump field and a jump value. The jump field is used to indicate the jump, and the jump value is used to represent the field cluster to be jumped to; the step of respectively reading the fields in the corresponding field clusters according to the jump relationship includes: in response to the jump field, determining the current field cluster; based on the jump value, determining the field cluster to be jumped to; respectively reading the fields in the current field cluster and the field cluster to be jumped to.

[0012] During the process of reading the fields in each field cluster, after encountering the jump field, locking the current field cluster and determining the field cluster to be jumped to according to the jump value in the current field cluster can accurately associate two field clusters with a jump relationship, improving the accuracy of the field reading order in the target protocol and further improving the accuracy of data parsing.

[0013] In some modified embodiments of the first aspect of the present application, the jump information further includes the name of the field cluster; before respectively reading the fields in the current field cluster and the field cluster to be jumped to, the method further includes: determining the field cluster to be verified according to the name of the field cluster included in the jump information, where the field cluster to be verified is the next-hop field cluster that the current field cluster needs to jump to; determining whether the field cluster to be verified is the same as the field cluster to be jumped to; if not, determining that there is an error in the jump relationship between the field clusters in the target protocol; the step of respectively reading the fields in the current field cluster and the field cluster to be jumped to includes: if so, respectively reading the fields in the current field cluster and the field cluster to be jumped to.

[0014] By comparing the name of the field cluster in the current field cluster with the name of the field cluster determined by the jump value, it can be ensured that the current field cluster accurately jumps to the next field cluster, improving the accuracy of the jump between field clusters and further improving the accuracy of data parsing.

[0015] In some modified embodiments of the first aspect of the present application, the method further includes: receiving an extended keyword and the field cluster corresponding to the extended keyword; adding the extended keyword to the corresponding field cluster to obtain an updated field cluster; updating the target protocol based on the updated field cluster; generating new parsing code based on the updated target protocol.

[0016] Through the extended keyword, the fields in the field cluster can be extended, enabling the target protocol and the parsing code to parse more types of data and improving the coverage of data parsing.

[0017] In some modified embodiments of the first aspect of the present application, the method further includes: receiving new data, where the new data includes the field cluster corresponding to the extended keyword and the new data is encapsulated by the updated target protocol; parsing the new data encapsulated by the updated target protocol based on the field cluster corresponding to the extended keyword by running the new parsing code.

[0018] By running the new parsing code to parse the new data including the extended keyword, the parsing of more types of data is realized.

[0019] The second aspect of the present application provides a method for generating a protocol parser, the method including: obtaining a target protocol, where the target protocol is in a tree structure, the nodes in the tree structure correspond to the field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; generating corresponding parsing code based on the target protocol, where the parsing code is used to parse the data encapsulated by the target protocol; generating a protocol parser based on the parsing code that passes the test.

[0020] In a third aspect of the present application, a data parsing device is provided. The device includes: a receiving module, configured to receive data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; a parsing module, configured to parse the data to be parsed based on the field clusters and jump relationships in the tree structure by running parsing code, and the parsing code is generated based on the target protocol and has passed tests.

[0021] In a fourth aspect of the present application, a device for generating a protocol parser is provided. The device includes: an obtaining module, configured to obtain a target protocol, where the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; a first generating module, configured to generate corresponding parsing code based on the target protocol, where the parsing code is used to parse data encapsulated using the target protocol; a second generating module, configured to generate a protocol parser based on the parsing code that has passed tests.

[0022] In a fifth aspect of the present application, an electronic device is provided. The electronic device includes: a processor, a memory, and a bus; wherein, the processor and the memory communicate with each other through the bus; the processor is configured to call program instructions in the memory to execute the method in the first aspect or the second aspect.

[0023] In a sixth aspect of the present application, a computer-readable storage medium is provided. The storage medium includes: a stored program; wherein, when the program runs, it controls the device where the storage medium is located to execute the method in the first aspect or the second aspect.

[0024] The method for generating a protocol parser provided in the second aspect of the present application, the data parsing device provided in the third aspect, the device for generating a protocol parser provided in the fourth aspect, the electronic device provided in the fifth aspect, and the computer-readable storage medium provided in the sixth aspect have the same or similar technical effects as the data parsing method provided in the first aspect, and will not be elaborated here. Description of the Drawings

[0025] By referring to the accompanying drawings and reading the following detailed description, the above and other purposes, features, and advantages of the exemplary embodiments of the present application will become readily understandable. In the drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, where:

[0026] Figure 1Schematic diagram of the application scenario of the data parsing method in the embodiments of the present application;

[0027] Figure 2 Schematic flow of the data parsing method in the embodiments of the present application Figure 1 ;

[0028] Figure 3 Schematic diagram of the structure of the target protocol in the embodiments of the present application;

[0029] Figure 4 Schematic flow of the data parsing method in the embodiments of the present application Figure 2 ;

[0030] Figure 5 Schematic diagram of the flow of the method for generating a protocol parser in the embodiments of the present application;

[0031] Figure 6 Schematic diagram of the structure of the data parsing device in the embodiments of the present application Figure 1 ;

[0032] Figure 7 Schematic diagram of the structure of the data parsing device in the embodiments of the present application Figure 2 ;

[0033] Figure 8 Schematic diagram of the structure of the device for generating a protocol parser in the embodiments of the present application;

[0034] Figure 9 Schematic diagram of the structure of the electronic device in the embodiments of the present application. Detailed implementation manners

[0035] Hereinafter, the exemplary embodiments of the present disclosure will be described in more detail with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be fully communicated to those skilled in the art.

[0036] It should be noted that unless otherwise specified, the technical terms or scientific terms used in the present application should have the ordinary meanings understood by those skilled in the art to which the present application belongs.

[0037] Currently, to write a certain protocol into a protocol parser, it is necessary to first generate the parsing code for the protocol, and then perform operations such as testing and repairing the parsing code. For the parsing code, operations such as generation, testing, and repair all require a great deal of time and effort from relevant personnel, which will reduce the efficiency of adding the protocol to the protocol parser and thus reduce the data parsing efficiency.

[0038] In view of this, an embodiment of the present application provides a method, apparatus, device, and medium for data parsing and protocol parser generation. By processing the target protocol into a tree structure, with nodes corresponding to field clusters and the connections between nodes corresponding to the jump relationships between field clusters, the target protocol with a preset format can be directly processed into parsing code and then added to the protocol parser, eliminating the need for code testing, repair, etc. again, thereby improving the efficiency of adding protocols to the protocol parser. After receiving the data to be parsed, the parsing code in the protocol parser can be directly used for data parsing, thus improving the data parsing efficiency.

[0039] First, the application scenario of the data parsing method provided by the embodiment of the present application is described.

[0040] Figure 1 For the application scenario schematic diagram of the data parsing method in the embodiment of the present application, see Figure 1 As shown, this scenario may include a first device 11, a second device 12, and a protocol parser 13. A transmission protocol is pre-agreed between the first device 11 and the second device 12, and this transmission protocol is stored in the protocol parser 13. When the first device 11 needs to send data to the second device 12, the first device 11 encapsulates the data based on the transmission protocol and sends the encapsulated data to the second device 12. After receiving the encapsulated data, the second device 12 sends the encapsulated data to the protocol parser 13 for parsing. The protocol parser 13 reads the fields from the encapsulated data and sends the read fields to the second device 12. In this way, the second device 12 can learn the information sent by the first device 11 to it through these fields.

[0041] It should be noted here that the execution subject of the embodiment of the present application is the above-mentioned protocol parser. The protocol parser can be located in the second device or outside the second device. When a new protocol is generated, the protocol needs to be processed accordingly and then added to the protocol parser so that the protocol parser can parse the data encapsulated using the new added protocol.

[0042] Next, the data parsing method provided by the embodiment of the present application is described in detail.

[0043] Figure 2 For the flowchart of the data parsing method in the embodiment of the present application Figure 1 see Figure 2 As shown, the method may include:

[0044] S21: Receive the data to be parsed.

[0045] Among them, the data to be parsed is encapsulated based on the target protocol. The target protocol is a tree structure. The nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters.

[0046] Here, the field cluster can refer to a set of fields with an equal relationship in the target protocol. In the target protocol, there are multiple fields. Some fields have a parallel relationship, and some fields have a reference relationship. The fields with a parallel relationship can form a field cluster. The fields with a reference relationship are respectively in two field clusters, and these two field clusters have a relationship where one references the other.

[0047] Figure 3 For the structural schematic diagram of the target protocol in the embodiments of this application, see Figure 3 As shown, in the target protocol, there are multiple field clusters, such as: Root.json, Read_Device_Info.json, Read_Time.json, Hardware_Info.json, Software_Info.json. Each field cluster is a node in the tree structure. There are connections between some field clusters, and these connections are the jump relationships between the respective field clusters. For example: the field cluster Root.json can jump to the field cluster Read_Device_Info.json or the field cluster Read_Time.json.

[0048] In the above Figure 3 some fields are involved, and the specific meanings of these fields are shown in Table 1 below.

[0049] Table 1

[0050]

[0051]

[0052] In the above Figure 3 the protocol structure is represented by a json file. It can also be represented using other languages, as long as it is represented according to the above tree structure.

[0053] The following gives an actual example of a field cluster:

[0054]

[0055]

[0056] In other words, when it is necessary to add a target protocol to a protocol parser so that the protocol parser can parse data encapsulated using the target protocol, the target protocol can be represented in the above-mentioned tree structure and then directly added to the protocol parser. In this way, the protocol parser only needs a general running program to parse the corresponding data to be parsed according to the target protocol in the tree structure. There is no need to develop parsing code anymore, and thus there is no need to perform tasks such as code testing and fixing, which can improve the efficiency of adding protocols in the protocol parser, and then the data can be parsed earlier, improving the data parsing efficiency.

[0057] When data needs to be parsed, the protocol parser receives the data to be parsed. The data to be parsed is the data from which the protocol parser needs to extract fields with actual meanings based on the corresponding protocols therein.

[0058] S22: Parse the data to be parsed based on the field clusters and jump relationships in the tree structure by running the parsing code.

[0059] Among them, the parsing code is generated based on the target protocol and has passed the test.

[0060] After the target protocol is edited according to the tree structure, the generated parsing code generally can pass the test. This is because: for the protocol edited according to this structure, the generated parsing code has been tested in the initial stage and can pass the test after code adjustment. For subsequent protocols edited according to this structure, as long as the parsing code is generated in the same way, there generally will be no problem with code errors.

[0061] After the protocol parser receives the data to be parsed, it will run the parsing code therein to find the corresponding protocol of the data to be parsed, and then read the corresponding fields from the data to be parsed based on the found protocol. For example: the data to be parsed is encapsulated based on protocol a, and protocol a, protocol b, and protocol c are stored in the protocol parser. After the protocol parser receives the data to be parsed, it determines that the data to be parsed is encapsulated using protocol a through the identifier of the data to be parsed or the data characteristics therein. Therefore, it will select protocol a from protocol a, protocol b, and protocol c and parse the data to be parsed based on protocol a.

[0062] In the process of parsing the data to be parsed based on protocol a, that is, the target protocol, the fields in the data to be parsed can be read sequentially according to the field clusters and their jump relationships in the tree structure of the target protocol, so as to achieve the parsing of the data to be parsed.

[0063] As can be seen from the above, the data parsing method provided by the embodiments of the present application processes the target protocol into a tree structure, with nodes corresponding to field clusters and the connections between nodes corresponding to the jump relationships between field clusters. In this way, the target protocol with a preset format can be directly processed into parsing code and then added to the protocol parser, eliminating the need for code testing, repair, etc. again, thereby improving the efficiency of adding protocols in the protocol parser. After receiving the data to be parsed, the parsing code in the protocol parser can be directly used for data parsing, thereby improving the data parsing efficiency.

[0064] Further, as a refinement and extension of the Figure 2 method shown above, the embodiments of the present application also provide a data parsing method.

[0065] Figure 4 The flowchart of the data parsing method in the embodiments of the present application is Figure 2 shown in Figure 4 and can include the following steps:

[0066] S41: Receive the data to be parsed.

[0067] The specific implementation of this step is the same as that of the foregoing step S21. For relevant descriptions, refer to the foregoing step S21 and will not be elaborated here.

[0068] S42: When the protocol parser runs, call the parsing code therein and determine the jump relationship according to the jump information in at least one field cluster.

[0069] In the target protocol, generally there will not be only one field cluster, because different field clusters will be used for parsing according to different contents of the data during the parsing process. Therefore, the number of field clusters is multiple, at least one field cluster includes jump information indicating the jump relationship, and the parsing code is stored in the protocol parser. The field cluster containing jump information is generally considered the parent field cluster, and the starting parent field cluster is the root field cluster. The field cluster pointed to by the jump information or edge in the parent field cluster is the child field cluster corresponding to the parent field cluster.

[0070] When starting to parse the data to be parsed, the protocol parser runs and calls the parsing code therein. When the parsing code runs, it will determine the jump relationships between all field clusters in the target protocol according to the jump information in the field clusters.

[0071] Still referring to Figure 3 shown, assume Figure 3The target protocol is composed of the field clusters shown. The field cluster Root.json contains jump information to the field cluster Read_Device_Info.json or the field cluster Read_Time.json. The field cluster Read_Device_Info.json contains jump information to the field cluster Hardware_Info.json or the field cluster Software_Info.json. Through the jump information in each field cluster, it can be determined that the jump relationship in the target protocol is that the field cluster Root.json jumps to the field cluster Read_Device_Info.json or the field cluster Read_Time.json. The field cluster Read_Device_Info.json jumps to the field cluster Hardware_Info.json or the field cluster Software_Info.json.

[0072] S43: According to the jump relationship, read the fields in the corresponding field clusters respectively until all the field clusters with jump relationships are read.

[0073] Still referring to Figure 3 shown, starting from the field cluster Root.json, read the fielf1, field2, etc. in it. Then, read the manufacturer, etc. in the field cluster Read_Device_Info.json, and the hour, etc. in the field cluster Read_Time.json. After the field cluster Read_Device_Info.json, read the cpu_type, etc. in the field cluster Hardware_Info.json, and the os, etc. in the field cluster Software_Info.json. In this way, the sequential reading of the fields such as fielf1, field2, etc., manufacturer, etc. in the target protocol is completed.

[0074] During the process of reading the fields in the field cluster, in order to ensure the accurate reading of the jump information and thus ensure the accuracy of the field cluster jump, the jump information may include a jump field and a jump value. The jump field is used to indicate the jump. The jump value is used to represent the field cluster to be jumped to.

[0075] Correspondingly, the above step S43 may include:

[0076] Step A1: Respond to the jump field and determine the current field cluster.

[0077] When reading the fields in the field cluster, if a jump field is encountered, it means that a jump to the next field cluster is about to be made. Then, the field cluster currently being read is used as the current field cluster.

[0078] The jump field can be set in advance. Specifically, it can be set as a character with a jump meaning, or it can be set as a character representing the use of the next field for jumping, and so on.

[0079] Step A2: Based on the jump value, determine the cluster of fields to be jumped to.

[0080] Different jump values can indicate different clusters of fields. In different jump relationships, the same jump value can be used. While in the same jump relationship, different jump values are required.

[0081] Still referring to Figure 3 As shown, taking the field cluster Root.json as an example, read field1, field2, field3 in sequence. When reading function_code, function_code is the jump field, indicating that a jump to a cluster of fields is required hereafter. Continuing to read backward, it will be found that value: 1, where 1 is the jump value, indicating a jump to the field cluster Read_Device_Info.json. It will also be found that value: 2, where 2 is the jump value, indicating a jump to the field cluster Read_Time.json. Whether to finally jump to the field cluster Read_Device_Info.json or the field cluster Read_Time.json depends on whether the value at the corresponding position in the data to be parsed is 1 or 2.

[0082] And in the field cluster Read_Device_Info.json, the jump values can also be represented by 1 and 2. Here, 1 indicates a jump to the field cluster Hardware_Info.json, and 2 indicates a jump to the field cluster Software_Info.json.

[0083] Step A3: Read the fields in the current field cluster and the field cluster to be jumped to respectively.

[0084] After determining which field cluster to jump to which other field cluster, after reading the fields in the current field cluster, it is possible to jump to the next field cluster to continue reading the fields until the fields in the last field cluster in the jump relationship are read completely, and then the reading of the fields can be ended.

[0085] Before reading the fields in the current field cluster and the field cluster to be jumped to, in order to avoid incorrect determination of the field cluster to be jumped to, resulting in incorrect reading of the field order and further incorrect parsing of the data, it is possible to further confirm the field cluster to be jumped to again.

[0086] Specifically, before the above Step A3, the method may further include:

[0087] Step A301: Determine the field cluster to be verified according to the name of the field cluster included in the jump information.

[0088] Among them, the field cluster to be verified is the next-hop field cluster that the current field cluster needs to jump to.

[0089] In a field cluster, in addition to including jump fields and jump values, it also includes the name of the field cluster to be jumped to. This named field cluster can be used to verify whether the field cluster to be jumped to determined based on the jump value is correct. Still referring to Figure 3 As shown, taking the field cluster Root.json as an example, the jump field function_code indicates that the jump is about to start, and the jump value 1 indicates jumping to the field cluster Read_Device_Info.json, which is the field cluster to be jumped to. At the same time, after the jump value 1, there is also the name Read_Device_Info.json, which is the field cluster to be verified and can be used to verify whether the field cluster to be jumped to is correct to ensure jumping to the correct field cluster.

[0090] Step A302: Determine whether the field cluster to be verified is the same as the field cluster to be jumped to. If not, execute Step A303; if so, execute Step A3.

[0091] The field cluster to be verified is determined by the name of the field cluster in the field cluster, and the field cluster to be jumped to is determined by the jump value in the field cluster and the corresponding relationship between the jump value and the field cluster. Compare the field clusters determined by the above two methods (the name, characteristic fields, etc. of the field clusters can be compared). Through the comparison result, it can be determined whether the determination of the field cluster to be jumped to is correct.

[0092] Step A303: Determine that there is an error in the jump relationship between field clusters in the target protocol.

[0093] The comparison of the field clusters determined by the two methods is inconsistent, indicating that either the jump value in the field cluster is incorrect or the name of the field cluster to be jumped to is incorrect. Whichever error it is, it means that the jump relationship configuration between the field clusters in the target protocol is incorrect, and the user who inputs the target protocol needs to be prompted so that the user can modify the target protocol, and then input the correct target protocol to avoid errors during data parsing and improve the accuracy of data parsing.

[0094] The comparison of the field clusters determined by the two methods is consistent, indicating that the jump value in the field cluster and the name of the field cluster to be jumped to corroborate each other, and the field cluster to be jumped to is correct. The fields in the current field cluster and the field cluster to be jumped to (or the next-hop field cluster) can be read.

[0095] S44: Use the read fields as the parsing result of the data to be parsed.

[0096] After the fields in the target protocol are read in sequence, the fields in the data to be parsed can be parsed according to the fields read in sequence to obtain the meanings of the fields in the data to be parsed, that is, the parsing result.

[0097] In the process of using the target protocol for data parsing, sometimes, as the business requirements or user needs change, some new fields need to be added to the target protocol, that is, extended keywords. At this time, it is necessary to update the target protocol in the protocol parser.

[0098] S45: Receive the extended keywords and the field clusters corresponding to the extended keywords.

[0099] For the fields to be extended in the target protocol, these fields are input into the protocol parser as the information of the extended keywords and their corresponding field clusters. The protocol parser can receive the information of the extended keywords and the field clusters they are in, so as to lock the field clusters corresponding to the extended keywords according to this information.

[0100] In practical applications, the extended keywords can include, but are not limited to, the keywords in Table 2 below.

[0101] Table 2

[0102]

[0103]

[0104] S46: Add the extended keywords to the corresponding field clusters to obtain the updated field clusters.

[0105] After receiving the information of the extended keywords and the field clusters they are in, the protocol parser can determine the field clusters corresponding to the extended keywords and the positions of the extended keywords in the field clusters according to this information, and then add the extended keywords to the corresponding positions in the field clusters to obtain the updated field clusters.

[0106] S47: Update the target protocol based on the updated field clusters.

[0107] The target protocol is generated based on each field cluster. Since the field clusters have changed, correspondingly, the target protocol will also change. Therefore, it is necessary to regenerate the protocol using the updated field clusters and the field clusters that have not been updated. The process of generating the protocol based on the field clusters is prior art and will not be elaborated here.

[0108] S48: Generate new parsing code based on the updated target protocol.

[0109] Data parsing depends on the target protocol. When the target protocol is updated, the parsing code that runs during data parsing also needs to be updated. To generate the parsing code based on the target protocol, a code generator can be used. This code generator can be pre-developed according to the process of generating parsing code for the above-mentioned tree-structured protocol. During the development of the code generator, the process of generating protocol parsing code will be repeatedly debugged until the code parser can directly generate the correct parsing code for the protocol. After that, when using the new protocol with the code generator, it can directly generate the correct parsing code for this protocol.

[0110] After the parsing code is updated, for the new data related to the target protocol received thereafter, it can be parsed through the new parsing code.

[0111] S49: Receive new data.

[0112] Among them, the new data contains a field cluster corresponding to the extended keyword, and the new data is encapsulated using the updated target protocol.

[0113] After the target protocol is updated, the data transmitted using the target protocol thereafter will be encapsulated using the updated target protocol. In the new data at this time, it may involve data related to the extended keyword.

[0114] S410: By running the new parsing code, based on the field cluster corresponding to the extended keyword, parse the new data encapsulated using the updated target protocol.

[0115] For the new data, running the new parsing code and parsing according to the updated target protocol can parse the relevant fields in the new data that involve the extended keyword, improving the flexibility and coverage of data parsing.

[0116] It should be noted here that the new parsing code generated in the above steps S45 - S48 can not only parse the new data received in step S49, but also parse the data to be parsed received in step S41.

[0117] The above is the process of data parsing based on the target protocol in the protocol parser, that is, the usage process of the protocol parser. Next, continue to explain how to generate the protocol parser based on the target protocol, that is, the construction process of the protocol parser.

[0118] Figure 5 It is a schematic flowchart of the method for generating a protocol parser in an embodiment of this application. Refer to Figure 5 As shown, this method may include:

[0119] S51: Obtain the target protocol.

[0120] Among them, the target protocol is a tree structure, where the nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters. For the specific content of the target protocol in the tree structure, reference can be made to the relevant description in step S21 above, which will not be elaborated here.

[0121] When a protocol parser containing the target protocol needs to be generated, the target protocol can first be processed into a tree structure. The field clusters in the target protocol are used as nodes, and the jump relationships between the field clusters are used as edges.

[0122] S52: Generate corresponding parsing code based on the target protocol.

[0123] Among them, the parsing code is used to parse the data encapsulated using the target protocol.

[0124] After obtaining the target protocol, since the target protocol is configured in a pre-specified tree structure, a code generator designed based on this tree structure can be used to generate the corresponding parsing code. The code generator generates the parsing code, and its function has been repeatedly tested and debugged. Therefore, the parsing code of the target protocol generated based on the code generator can directly pass the test smoothly.

[0125] S53: Generate a protocol parser based on the parsing code that has passed the test.

[0126] Since the parsing code of the target protocol is generated using a code generator, this parsing code will directly pass the test smoothly, and then a corresponding protocol parser is generated, improving the generation efficiency of the protocol parser.

[0127] The protocol parser here can be a parser that only contains the target protocol, or a parser that contains multiple protocols (one of which is the target protocol).

[0128] In the actual operation process of generating a protocol parser based on the target protocol, first, the target protocol can be loaded into the data structure in the memory corresponding to the protocol parser. Then, a preset code generator is used to compile the content in the data structure into parsing code. Finally, a protocol parser is generated based on the parsing code.

[0129] So far, the data parsing method and the protocol parser generation method provided by the embodiments of the present application have been fully described.

[0130] Based on the same inventive concept, as an implementation of the above data parsing method, the embodiments of the present application also provide a data parsing device.

[0131] Figure 6 For the structural schematic of the data parsing device in the embodiments of the present application Figure 1 See Figure 6As shown, the device may include: a receiving module 61 and a parsing module 62. Among them, the receiving module 61 and the parsing module 62 are connected.

[0132] The receiving module 61 is configured to receive data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters.

[0133] The parsing module 62 is configured to parse the data to be parsed based on the field clusters and jump relationships in the tree structure by running parsing code, where the parsing code is generated based on the target protocol and has passed tests.

[0134] Further, as a refinement and extension of the Figure 6 shown device, an embodiment of the present application further provides a data parsing device.

[0135] Figure 7 For the structural schematic of the data parsing device in the embodiment of the present application Figure 2 , see Figure 7 As shown, the device may include: a receiving module 71, a first parsing module 72, an extension module 73, and a second parsing module 74. Among them, the receiving module 71, the first parsing module 72, the extension module 73, and the second parsing module 74 are connected in sequence.

[0136] The receiving module 71 is configured to receive data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters.

[0137] When the number of the field clusters is multiple, at least one field cluster includes jump information indicating the jump relationship, and the parsing code is stored in a protocol parser, the first parsing module 72 includes: a determination unit 721, a reading unit 722, a judgment unit 723, and an acting unit 724. Among them, the determination unit 721, the reading unit 722, the judgment unit 723, and the acting unit 724 are connected in sequence.

[0138] The determination unit 721 is configured to, when the protocol parser runs, call the parsing code therein and determine the jump relationship according to the jump information in the at least one field cluster.

[0139] The reading unit 722 is configured to respectively read the fields in the corresponding field clusters according to the jump relationship until the reading of all the field clusters with jump relationships is completed.

[0140] When the jump information includes a jump field and a jump value, where the jump field is used to indicate a jump and the jump value is used to represent a field cluster to be jumped to, the reading unit 722 is specifically configured to, in response to the jump field, determine the current field cluster; based on the jump value, determine the field cluster to be jumped to; and respectively read the fields in the current field cluster and the field cluster to be jumped to.

[0141] When the jump information further includes the name of the field cluster, the determination unit 723 is configured to determine the field cluster to be verified according to the name of the field cluster included in the jump information, where the field cluster to be verified is the next-hop field cluster that the current field cluster needs to jump to; determine whether the field cluster to be verified is the same as the field cluster to be jumped to; if not, determine that there is an error in the jump relationship between the field clusters in the target protocol; if so, enter the acting unit 724.

[0142] The acting unit 724 is configured to use the read fields as the parsing result of the data to be parsed.

[0143] The extension module 73 includes: a first receiving unit 731, an extension unit 732, a first updating unit 733, and a second updating unit 734. Among them, the first receiving unit 731, the extension unit 732, the first updating unit 733, and the second updating unit 734 are connected in sequence.

[0144] The first receiving unit 731 is configured to receive the extended keyword and the field cluster corresponding to the extended keyword.

[0145] The extension unit 732 is configured to add the extended keyword to the corresponding field cluster to obtain an updated field cluster.

[0146] The first updating unit 733 is configured to update the target protocol based on the updated field cluster.

[0147] The second updating unit 734 is configured to generate new parsing code based on the updated target protocol.

[0148] The second parsing module 74 includes: a second receiving unit 741 and a parsing unit 742. Among them, the second receiving unit 741 and the parsing unit 742 are connected.

[0149] The second receiving unit 741 is configured to receive new data, where the new data includes the field cluster corresponding to the extended keyword, and the new data is encapsulated in the updated target protocol.

[0150] The parsing unit 742 is configured to parse the new data encapsulated in the updated target protocol based on the field cluster corresponding to the extended keyword by running the new parsing code.

[0151] Based on the same inventive concept, as an implementation of the method for generating the above-mentioned protocol parser, an embodiment of the present application further provides a device for generating a protocol parser.

[0152] Figure 8 It is a schematic structural diagram of the device for generating a protocol parser in an embodiment of the present application. Refer to Figure 8 As shown, the device may include: Among them, an acquisition module 81, a first generation module 82, and a second generation module 83 are connected in sequence.

[0153] The acquisition module 81 is configured to acquire a target protocol, where the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to jump relationships between the field clusters.

[0154] The first generation module 82 is configured to generate corresponding parsing code based on the target protocol, and the parsing code is used to parse data encapsulated using the target protocol.

[0155] The second generation module 83 is configured to generate a protocol parser based on the parsing code that has passed the test.

[0156] It should be noted here that the description of the above device embodiments is similar to the description of the above method embodiments and has similar beneficial effects to the method embodiments. For technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0157] Based on the same inventive concept, an embodiment of the present application further provides an electronic device. Figure 9 It is a schematic structural diagram of the electronic device in an embodiment of the present application. Refer to Figure 9 As shown, the electronic device may include: a processor 91, a memory 92, and a bus 93; among them, the processor 91 and the memory 92 complete communication with each other through the bus 93; the processor 91 is configured to call program instructions in the memory 92 to execute the method in the above one or more embodiments.

[0158] It should be noted here that the description of the above electronic device embodiments is similar to the description of the above method embodiments and has similar beneficial effects to the method embodiments. For technical details not disclosed in the electronic device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0159] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium, and the storage medium may include: a stored program; among them, when the program runs, it controls the device where the storage medium is located to execute the method in the above one or more embodiments.

[0160] It should be noted here that the description of the above storage medium embodiments is similar to that of the above method embodiments and has similar beneficial effects to those of the method embodiments. For the technical details not disclosed in the storage medium embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0161] As described above, the above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed in the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A data parsing method, characterized in that, the method includes: receiving data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; parsing the data to be parsed based on the field clusters and jump relationships in the tree structure by running parsing code, where the parsing code is generated based on the target protocol and has passed testing.

2. The method according to claim 1, characterized in that, the number of the field clusters is multiple, at least one field cluster includes jump information indicating the jump relationship, and the parsing code is stored in a protocol parser; the parsing the data to be parsed based on the field clusters and jump relationships in the tree structure by running parsing code includes: when the protocol parser runs, calling the parsing code therein, and determining the jump relationship according to the jump information in the at least one field cluster; reading the fields in the corresponding field clusters respectively according to the jump relationship until reading all the field clusters with jump relationships is completed; using the read fields as the parsing result of the data to be parsed.

3. The method according to claim 2, characterized in that, the jump information includes a jump field and a jump value, the jump field is used to indicate a jump, and the jump value is used to represent the field cluster to be jumped to; the reading the fields in the corresponding field clusters respectively according to the jump relationship includes: responding to the jump field to determine the current field cluster; determining the field cluster to be jumped to based on the jump value; reading the fields in the current field cluster and the field cluster to be jumped to respectively.

4. The method according to claim 3, characterized in that, the jump information further includes the name of the field cluster; before reading the fields in the current field cluster and the field cluster to be jumped to respectively, the method further includes: determining the field cluster to be verified according to the name of the field cluster included in the jump information, where the field cluster to be verified is the next-hop field cluster that the current field cluster needs to jump to; judging whether the field cluster to be verified is the same as the field cluster to be jumped to; if not, determining that there is an error in the jump relationship between the field clusters in the target protocol; the reading the fields in the current field cluster and the field cluster to be jumped to respectively includes: if so, reading the fields in the current field cluster and the field cluster to be jumped to respectively.

5. The method according to any one of claims 1 to 4, characterized in that, the method further includes: receiving extended keywords and the corresponding field clusters of the extended keywords; adding the extended keywords to the corresponding field clusters to obtain updated field clusters; updating the target protocol based on the updated field clusters; generating new parsing code based on the updated target protocol.

6. The method according to claim 5, characterized in that, the method further includes: receiving new data, where the new data contains the field clusters corresponding to the extended keywords, and the new data is encapsulated with the updated target protocol; By running new parsing code, new data encapsulated with the updated target protocol is parsed based on the field clusters corresponding to the extended keywords included therein.

7. A method for generating a protocol parser, characterized in that the method includes: obtaining a target protocol, where the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; generating corresponding parsing code based on the target protocol, where the parsing code is used to parse data encapsulated with the target protocol; generating a protocol parser based on the parsing code that has passed the test.

8. A data parsing device, characterized in that the device includes: a receiving module, configured to receive data to be parsed, where the data to be parsed is encapsulated based on a target protocol, the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; a parsing module, configured to parse the data to be parsed by running parsing code, based on the field clusters and jump relationships in the tree structure, where the parsing code is generated based on the target protocol and has passed the test.

9. A device for generating a protocol parser, characterized in that the device includes: an obtaining module, configured to obtain a target protocol, where the target protocol is a tree structure, nodes in the tree structure correspond to field clusters in the target protocol, and the connections between the nodes correspond to the jump relationships between the field clusters; a first generating module, configured to generate corresponding parsing code based on the target protocol, where the parsing code is used to parse data encapsulated with the target protocol; a second generating module, configured to generate a protocol parser based on the parsing code that has passed the test.

10. An electronic device, characterized in that the electronic device includes: a processor, a memory, and a bus; wherein, the processor and the memory communicate with each other through the bus; the processor is configured to call program instructions in the memory to execute the method according to any one of claims 1 to 7.

11. A computer-readable storage medium, characterized in that the storage medium includes: a stored program; wherein, when the program runs, it controls the device where the storage medium is located to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Water meter protocol matching method and system based on artificial intelligence

    CN120825523A