Communication message analysis method and device

By designing a generalized communication message analysis method and defining the parsing structure using configuration files, the problem of poor reusability of communication analysis tools in the prior art is solved, efficient analysis of messages from different communication protocols is achieved, and testing efficiency and quality are improved.

CN119652993APending Publication Date: 2025-03-18CASCO SIGNAL LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411770765.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

During the testing process of the railway signal industry in the existing technology, the communication analysis tool has poor reusability and cannot effectively parse messages from different communication protocols, resulting in low testing efficiency and low quality.

Method used

By designing a generalized communication message parsing method, using configuration files to define the parsing structure of all message types, the parsing structure contains structural attributes and key-value attributes, the decoupling of the parsing algorithm and the communication protocol is realized, and the reusability and flexibility of the tool are improved.

Benefits of technology

It realizes general parsing of messages from different communication protocols, reduces the work difficulty of testers, improves testing efficiency and quality, and avoids the situation of one protocol and one tool.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119652993A_ABST
    Figure CN119652993A_ABST
Patent Text Reader

Abstract

The invention provides a communication message analysis method and device, which are used for analyzing information corresponding to all message types from a to-be-analyzed message, and the method comprises the following steps: obtaining the to-be-analyzed message and a corresponding configuration file, defining information of analysis structures of all message types in the configuration file, the analysis structure comprises information of a plurality of key values; and for each message type, carrying out the following processing: obtaining an analysis structure of the message type, carrying out structure analysis according to a structure attribute defined in the analysis structure, and sequentially analyzing key values contained in the analysis structure according to defined key value attributes, recording the analysis result of each key value in an analysis data recording dictionary; and after the analysis of all message types is completed, outputting the analysis data record dictionary. According to the invention, the working difficulty of message analysis can be reduced, and the working efficiency and quality are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a universal communication message parsing method, device, electronic device and computer-readable storage medium. Background Art

[0002] Communication analysis is an essential part of the railway signaling industry testing process. Due to various requirements such as industry specifications and security specifications, the definition of communication protocols between various types of equipment is highly complex, and there are large differences between different protocols. Currently, most of the testing process still uses manual packet capture inspection, and some communications use automated tools for analysis, but the analysis tools only support the analysis process of a specific type of message, and the tool's reusability is poor. Summary of the invention

[0003] The purpose of the present invention is to provide a universal communication message parsing method, device, electronic device and computer-readable storage medium to achieve decoupling of the parsing algorithm and the communication protocol, improve the reusability and flexibility of the parsing tool, avoid the situation of one protocol and one tool, reduce the work difficulty of testers, and improve work efficiency and quality.

[0004] To achieve the above objectives, the present invention is implemented through the following technical solutions:

[0005] A communication message parsing method is used to parse data corresponding to all message types from a message to be parsed, comprising the following steps:

[0006] Obtain the message to be parsed and the corresponding configuration file, wherein the configuration file defines the parsing structure information of all message types, and the parsing structure contains information of several key values;

[0007] For each message type, the following processing is performed: obtaining the parsing structure of the message type, performing structural parsing according to the structural attributes defined in the parsing structure, and sequentially parsing the key values ​​contained in the parsing structure according to the defined key value attributes, and recording the parsing result of each key value in the parsing data record dictionary;

[0008] After parsing of all message types is completed, the parsed data record dictionary is output.

[0009] Optionally, the structural attributes of the parsed structure definition include: a custom prefix attribute;

[0010] The performing structural analysis according to the structural attributes defined in the analytical structure includes:

[0011] If the custom prefix attribute is empty or "-", the custom prefix of the current prefix is ​​set to empty, and the current prefix is ​​updated to the first position in the prefix list;

[0012] If the custom prefix attribute is not empty, obtain the prefix at the first position from the prefix list, combine it with the variable in the custom prefix attribute to form a variable name, and look up the value corresponding to the variable name in the current parsed data record dictionary, place the value as the custom prefix in front of the current prefix, and update the current prefix to the first position in the prefix list.

[0013] Optionally, the structural attributes of the parsing structure definition further include: a self-loop attribute, a self-loop merging attribute, and a loop count definition byte attribute;

[0014] The performing structural analysis according to the structural attributes defined in the analytical structure also includes:

[0015] If the self-loop attribute is "Y" and the self-loop merge attribute is not "Y", the first prefix in the prefix list is updated according to the number of self-loop cycles;

[0016] Determine whether the byte attribute for defining the number of loops is defined; if the byte attribute for defining the number of loops is not defined, parse each key value in the parsing structure in turn; if the byte attribute for defining the number of loops is defined, determine the number of loops according to the number of bytes defined by the attribute, and perform a cyclic parsing on the parsing structure according to the number of loops, each cyclic parsing creates a new group of substructures according to the current number of loops, and parses each key value record in the substructure in turn according to the parsing structure until the number of loops is completed.

[0017] Optionally, the structural attributes of the analytical structure definition further include: a self-loop condition parameter attribute, a self-loop condition determination method attribute, and a self-loop condition expected value attribute;

[0018] The performing structural analysis according to the structural attributes defined in the analytical structure also includes:

[0019] After the parsing is completed, determine whether the self-loop condition parameter attribute is empty or "-";

[0020] If the self-loop condition parameter attribute is empty or "-", the parsing of the parsing structure is terminated;

[0021] If the self-loop condition parameter attribute is not empty or "-", the value of the variable is searched in the parsed data record dictionary based on the variable defined by the self-loop condition parameter attribute in combination with the prefix list, and a judgment is made based on the judgment method defined by the self-loop condition judgment method attribute and the expected value defined by the self-loop condition expected value attribute. If the judgment result is that the self-loop condition is met, the next loop analysis is continued. If the judgment result is that the self-loop condition is not met, the loop analysis of the parsing structure is terminated.

[0022] Optionally, the key value attributes of the key value definition include: a virtual calculation attribute, a parsing length attribute, a parsing condition parameter attribute, a parsing condition determination method attribute, and a parsing condition expected value attribute;

[0023] The parsing process of the key value contained in the parsed structure according to the key value attribute includes:

[0024] Determine whether the virtual calculation attribute of the current key value is empty or "-"; if the virtual calculation attribute is not empty or "-", perform data calculation according to the logic processing function defined by the virtual calculation attribute, and record the calculation result as the parsing result of the current key value in the parsing data record dictionary; if the virtual calculation attribute is empty or "-", determine the key value length of the current key value according to the parsing length attribute;

[0025] Determine whether the parsing condition parameter attribute of the current key value is empty or "-"; if the parsing condition parameter attribute is empty or "-", continue with the subsequent parsing; if the parsing condition parameter attribute is not empty or "-", then according to the variable in the parsing condition parameter attribute, in combination with the prefix list, look up the value of the variable in the parsing data record dictionary, and make a judgment according to the judgment method defined by the parsing condition judgment method attribute and the expected value defined by the parsing condition expected value attribute. If the judgment result is that the parsing condition is met, continue with the subsequent parsing; if the judgment result is that the parsing condition is not met, skip the current key value and perform the parsing of the next key value;

[0026] Determine whether the current key value needs to be parsed in a loop; if not, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and then continue to parse the next key value; if cyclic parsing is required, determine the number of loops, and cyclically parse the current key value according to the number of loops. In each parsing, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and continue to parse the next key value after the cyclic parsing is completed.

[0027] Optionally, determining the key value length of the current key value according to the parsed length attribute includes:

[0028] Determine whether the variable defined by the parsing length attribute is of int type. If it is of int type, determine the value of the variable defined by the parsing length attribute as the key value length of the current key value; if it is not of int type, then according to the variable defined by the parsing length attribute, combined with the prefix list, search for the value of the variable in the parsing data record dictionary, and use the value of the variable as the key value length of the current key value.

[0029] Optionally, the key value attributes of the key value definition include: a loop count attribute, a loop attribute based on a variable value, a special loop algorithm attribute, and a loop to end attribute;

[0030] The step of determining whether the current key value needs to be cyclically parsed includes:

[0031] If the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute are all empty or "-", and the loop to end attribute is not "Y", it is determined that the current key value does not need loop analysis;

[0032] If any one of the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute is not empty or "-", or the loop to end attribute is "Y", it is determined that the current key value needs loop analysis.

[0033] Optionally, determining the number of cycles includes:

[0034] If the loop count attribute is not empty or "-", the value of the variable defined by the loop count attribute is determined as the loop count;

[0035] If the loop attribute based on variable value is not empty or "-", then according to the variable defined by the loop attribute based on variable value, in combination with the prefix list, the value of the variable is searched in the parsed data record dictionary, and the value of the variable is used as the number of loops;

[0036] If the special loop algorithm attribute is not empty or "-", data calculation is performed according to the logic processing function defined by the special loop algorithm attribute, and the calculation result is used as the number of loops;

[0037] If the loop to end attribute is "Y", the number of loops is set to -1.

[0038] Optionally, the performing cyclic parsing on the current key value according to the number of cycles includes:

[0039] If the number of loops is greater than 0, the current key value is looped according to the number of loops;

[0040] If the number of loops is -1, the current key value will be processed in a loop until all the information in the current parsing structure is parsed;

[0041] If the number of loops is 0, skip the current key value and execute the parsing of the next key value.

[0042] Optionally, the key-value attributes of the key-value definition include: substructure attributes;

[0043] The step of parsing the message to be parsed according to the key value length and recording the parsing result in a parsing data record dictionary includes:

[0044] Determine whether the key value length of the current key value is 0; if not, extract information from the remaining unextracted information of the message to be parsed according to the key value length; if 0, extract all the remaining unextracted information of the message to be parsed;

[0045] Determine whether the substructure attribute of the current key value is empty or "-"; if it is empty or "-", record the extracted information in the parsing data record dictionary; if it is not empty "-", call the substructure defined by the substructure attribute to parse the extracted information, and record the parsing result in the parsing data record dictionary.

[0046] Optionally, the structural attributes of the substructure include: bit structural attributes;

[0047] The calling of the substructure defined by the substructure attribute to parse the extracted information includes:

[0048] If the bit identification attribute of the substructure is "Y", the extracted information is converted into bit type data, and then the substructure is recursively called for parsing;

[0049] If the bit identification attribute is "N", the substructure is directly recursively called to parse the extracted information.

[0050] Optionally, the determination method includes:

[0051] Determine whether the value of the variable is the same as the expected value. If so, it is determined to meet the conditions. If not, it is determined to meet the conditions.

[0052] Determine whether the value of the variable is different from the expected value. If different, it is determined to meet the conditions. If the same, it is determined not to meet the conditions.

[0053] Determine whether the value of the variable is greater than the expected value. If so, it is determined to meet the conditions. If not, it is determined to not meet the conditions.

[0054] Determine whether the value of the variable is less than the expected value. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0055] Determine whether the value of the variable is an odd number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0056] Determine whether the value of the variable is an even number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0057] A communication message parsing device, used for parsing data corresponding to all message types from a message to be parsed, comprising:

[0058] An acquisition module is used to acquire a message to be parsed and a corresponding configuration file, wherein the configuration file defines information on parsing structures of all message types, and the parsing structure contains information on a number of key values;

[0059] The parsing module is used to perform the following processing for each message type to be parsed: obtaining the parsing structure of the message type, performing structural parsing according to the structural attributes defined in the parsing structure, and successively parsing the key values ​​contained in the parsing structure according to the defined key value attributes, and recording the parsing result of each key value in the parsing data record dictionary;

[0060] The output module is used to output the parsed data record dictionary after completing the parsing of all message types.

[0061] An electronic device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0062] Memory, used to store computer programs;

[0063] The processor is used to implement any of the method steps described above when executing the program stored in the memory.

[0064] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements any of the method steps described above.

[0065] Compared with the prior art, the present invention has the following advantages:

[0066] The universal communication message parsing method provided by the present invention allows testers to parse a specific communication protocol in the form of a configuration file and use the parsing method to parse the protocol message. The configuration file is a common file format and requires almost no programming knowledge from the user. Moreover, by adjusting the configuration file, parsing of different communication protocols can be achieved, thereby improving the overall reusability and flexibility of the tool. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for the description. Obviously, the drawings described below are an embodiment of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work:

[0068] Figure 1 A flow chart of a communication message parsing method provided by one embodiment of the present invention;

[0069] Figure 2 This is a processing flow chart for custom prefixes;

[0070] Figure 3 A flowchart for the processing of parsing structure;

[0071] Figure 4 It is a flowchart for key value processing;

[0072] Figure 5 This is a partial schematic diagram of a configuration file in a specific example;

[0073] Figure 6 A structural diagram of a communication message parsing device provided by one embodiment of the present invention;

[0074] Figure 7 A structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0075] The scheme proposed by the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become clearer according to the following description. It should be noted that the accompanying drawings are in a very simplified form and are not in precise proportions, which are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.

[0076] The existing technology has the following problems: 1. The inspection process of manual testing is inefficient, and it is easy to make mistakes in the inspection process; 2. The existing tool parsing process can only target a specific type of message, and has poor reusability; 3. If testers are expected to be able to implement the automated parsing process of new types of communication protocols, certain programming skills are required of the testers.

[0077] In view of the above problems, an embodiment of the present invention provides a communication message parsing method for parsing data corresponding to all message types from the message to be parsed. The execution subject of the method described in this embodiment can be an automated parsing tool, such as Figure 1 As shown, the method comprises the following steps:

[0078] Step S101: obtaining a message to be parsed and a corresponding configuration file, wherein the configuration file defines information of parsing structures of all message types, and the parsing structure includes information of several key values.

[0079] The parsing structure of each message type defines several structural attributes, including but not limited to: custom prefix attribute (Name_PRE_Mark), loop number definition byte attribute (NumberByte), self-loop attribute (Sub_Self_Repeat), self-loop merge attribute (Repeat_Combine), self-loop condition parameter attribute (Slef_Repeat_cond_Key), self-loop condition determination method attribute (Self_Repeat_Cond_Method), and self-loop condition expected value attribute (Self_repeat_Cond_Value).

[0080] Each key value of each parsing structure defines several key value attributes, which include but are not limited to: virtual calculation attribute (Virtual_Math), parsing length attribute (Msg Length), parsing condition parameter attribute (Cond_Key), parsing condition determination method attribute (Cond_Method), parsing condition expected value attribute (Cond_Value), loop count attribute (Param_Repeat_Time), loop based on variable value attribute (Repeat_Base_Var), loop to end attribute (Repeat_Till_End), special loop algorithm attribute (Repeat_Special), and substructure attribute (Sub_Struct).

[0081] It is understandable that a communication message of a communication protocol corresponds to a configuration file, in which different parsing structures are set according to the message characteristics of the protocol, and corresponding structural attributes and key-value attributes are defined. When a message to be parsed is obtained, the corresponding configuration file can be determined based on its communication protocol. Therefore, this embodiment can parse communication messages of different protocols by configuring different configuration files.

[0082] Step S102: For each message type, the following processing is performed: obtaining the parsing structure of the message type, performing structural parsing according to the structural attributes defined in the parsing structure, and parsing the key values ​​contained in the parsing structure in turn according to the defined key value attributes, and recording the parsing results of each key value in the parsing data record dictionary.

[0083] This embodiment uses a recursive method to parse the message to be parsed based on the configuration file. After the parsing tool reads the configuration file, it can obtain the structural information of all message types, and then parse each message type in turn. The overall parsing process is that the parsing tool disassembles, parses and updates the records from the message to be parsed into the parsing data record dictionary according to the structure of each message type.

[0084] For the message type to be currently parsed, the parsing tool obtains the parsing structure of the message type from the configuration file, and reads each structural attribute defined in the parsing structure.

[0085] First, set the custom prefix. Figure 2 As shown, it is determined whether the custom prefix attribute (Name_Pre_Mark) is empty or "-". If the custom prefix attribute is empty or "-", it means that the variable name of the parsing structure does not need to add a custom prefix, then the custom prefix of the current prefix is ​​set to empty, and the current prefix is ​​updated to the first position of the prefix list, so that the variable can be searched in sequence according to the hierarchy when the variable is queried subsequently.

[0086] If the custom prefix attribute is not empty or "-", it means that the variable name of the parsing structure needs to add a custom prefix, then the existing prefixes are obtained from the prefix list in turn, combined with the variables in the custom prefix attribute to form a variable name, and the value corresponding to the variable name is searched in the current parsing data record dictionary. If it is not found, the query continues according to the prefix list; if it is found, the value is placed in front of the current prefix as a custom prefix, and the current prefix is ​​updated to the first position in the prefix list. If the qualified variable cannot be found after traversing the prefix list, an error is reported and the program exits.

[0087] After completing the setting of the custom prefix, the tool will parse the message to be parsed based on the current parsing structure until the parsing is completed.

[0088] Specifically, Figure 3As shown, first determine the self-loop attribute (Sub_Self_Repeat) and self-loop merge attribute (Repeat_Combine) of the current parsing structure. If the self-loop attribute is "Y" and the self-loop merge attribute is not "Y", the tool will update the first prefix in the prefix list (i.e., the current prefix) according to the number of self-loops (to ensure that each variable name is unique during the loop). It should be noted that when there is a loop and the self-loop merge attribute (Repeat_Combine) is Y, this structure uses the same variable name for each loop during the loop processing. The next loop process will update the result of the previous loop, and finally form a set of variables and values. When the self-loop merge attribute (Repeat_Combine) is N, the field of the number of loops will be added to the variable name for each loop to ensure that the variable name will not be repeated, so as to obtain each variable and value for each loop.

[0089] Then, it is determined whether the loop number definition byte attribute is defined; it is determined whether the current parsing structure defines the loop number definition byte attribute (NumberByte). If the attribute is not defined, the tool will parse each key value in turn according to the current parsing structure; if the attribute is defined, the part will be extracted and parsed according to the number of bytes defined by the attribute, the loop number will be obtained, and the loop parsing will be performed according to the loop number information. Each loop parsing will create a new set of record substructures according to the current loop number, and the key values ​​parsed in turn according to the current parsing structure will be recorded in the substructure.

[0090] After parsing is completed, it is determined whether the self-loop condition parameter attribute (Slef_Repeat_cond_Key) is empty or "-". If the self-loop condition parameter attribute is empty or "-", it indicates that the current structure does not need to be cyclically parsed, and it is believed that the parsing of the parsing structure is completed, then the parsing of the parsing structure is terminated and the parsing result (i.e., parsing data record dictionary) of the parsing structure is returned. If the self-loop condition parameter attribute is not empty or "-", then according to the variable defined by the self-loop condition parameter attribute, in combination with the prefix list, the value of the variable is searched in the parsing data record dictionary, and the expected value defined by the self-loop condition determination method attribute (Self_Repeat_Cond_Method) and the expected value defined by the self-loop condition expected value attribute (Self_repeat_Cond_Value) are judged (the judgment method will be introduced later), if the judgment result is to meet the self-loop condition, then the next cyclic parsing is continued, if the judgment result is not to meet the self-loop condition, it is believed that the cyclic parsing of the parsing structure is completed, then the cyclic parsing of the parsing structure is terminated and the cyclic parsing result of the parsing structure is returned. If an exception occurs during the process of determining whether the self-loop conditions are met, the tool will report an error and exit the analysis.

[0091] Then, the key values ​​contained in the parsing structure are parsed in turn according to the defined key value attributes, such as Figure 4 As shown, the details are as follows:

[0092] First, determine whether the virtual calculation attribute (Virtual_Math) of the current key value is empty or "-". If it is not empty, it means that the current key value is a user-defined virtual parameter. The communication protocol itself does not contain this part, but due to the length of subsequent key values ​​or the number of loops in the protocol, this parameter is set for calculation. The tool calls the logical processing function defined by the virtual calculation attribute to perform data calculation. If the calculation process is normal, the calculation result will be recorded in the parsed data record dictionary, otherwise it will report an error and exit.

[0093] If the virtual calculation attribute (Virtual_Math) is empty or "-", it means that the current key value is part of the communication protocol, then continue to execute the subsequent steps for parsing. It is necessary to first determine the key value length of the current key value according to the parsing length attribute (Msg_length) (the method for determining the key value length will be introduced later).

[0094] Then determine whether the parsing condition parameter attribute (Cond_Key) of the current key value is empty or "-"; if the parsing condition parameter attribute is empty or "-", it means that the current key value needs to be parsed unconditionally, and then continue with the subsequent parsing; if the parsing condition parameter attribute is not empty or "-", it means that the current key value needs to be parsed according to the condition, then according to the variable in the parsing condition parameter attribute, combined with the prefix list, the value of the variable is searched in the parsing data record dictionary, and the judgment method defined by the parsing condition judgment method attribute (Cond_Method) and the expected value defined by the parsing condition expected value attribute (Cond_Value) are judged (the judgment method will be introduced later). If the judgment result is that the parsing condition is met, then continue with the subsequent parsing. If the judgment result is that the parsing condition is not met, then skip the current key value and perform the parsing of the next key value. If an exception occurs during the judgment of whether the parsing condition is met, an error is reported and exited.

[0095] Then determine whether the current key value needs to be parsed in a loop; if it does not need to be parsed in a loop, parse the message to be parsed according to the key value length (to be described later), record the parsing result in the parsing data record dictionary, and then continue to parse the next key value; if it needs to be parsed in a loop, determine the number of loops, and parse the current key value in a loop according to the number of loops. In each parsing, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and continue to parse the next key value after the loop parsing is completed. If an exception occurs during the parsing process, an error is reported and the program exits.

[0096] Specifically, the process of determining whether the current key value requires loop analysis is as follows: if the loop count attribute (Param_Repeat_Time), the loop attribute based on variable value (Repeat_Base_Var), and the special loop algorithm attribute (Repeat_Special) are all empty or "-", and the loop to end attribute (Repeat_Till_End) is not "Y", then it is determined that the current key value does not require loop analysis; if any one of the loop count attribute (Param_Repeat_Time), the loop attribute based on variable value (Repeat_Base_Var), and the special loop algorithm attribute (Repeat_Special) is not empty or "-", or the loop to end attribute (Repeat_Till_End) is "Y", then it is determined that the current key value requires loop analysis.

[0097] In the case where loop parsing is required, the number of loops is determined as follows: if the loop number attribute (Param_Repeat_Time) is not empty or "-", the value of the variable defined by the loop number attribute is determined as the loop number; if the loop attribute based on variable value (Repeat_Base_Var) is not empty or "-", the variable defined by the loop attribute based on variable value, combined with the prefix list, is searched for the value of the variable in the parsed data record dictionary, and the value of the variable is used as the loop number; if the special loop algorithm attribute (Repeat_Special) is not empty or "-", data calculation is performed according to the logic processing function defined by the special loop algorithm attribute, and the calculation result is used as the loop number; if the loop to end attribute (Repeat_Till_End) is "Y", the loop number is set to -1. It should be noted that, under normal circumstances, the key value of the loop to end attribute set to Y should be the last key value of the parsed structure.

[0098] The current key value is then analyzed in a loop according to the number of loops, as follows: if the number of loops is greater than 0, the current key value is processed in a loop according to the number of loops; if the number of loops is -1, the current key value is processed in a loop until all the information in the current analysis structure is analyzed; if the number of loops is 0, the current key value is skipped and the next key value is analyzed. If the number of loops is other values, an error is reported and the program exits.

[0099] In each analysis, the message to be analyzed is analyzed according to the key value length, and the analysis result is recorded in the analysis data record dictionary, as follows: determine whether the key value length of the current key value is 0; if not 0, extract information from the remaining unextracted information of the message to be analyzed according to the key value length; if 0, extract all the remaining unextracted information of the message to be analyzed. Continue to determine whether the sub-structure attribute of the current key value is empty or "-"; if it is empty or "-", it means that the current key value is an ordinary key value, and the extracted information is recorded in the analysis data record dictionary; if it is not empty "-", it means that the current key value is a composite structure, and the sub-structure defined by the sub-structure attribute (Sub_Struct) is called to analyze the extracted information, and the analysis result is recorded in the analysis data record dictionary.

[0100] Wherein, the structural attribute of the substructure includes: bit structural attribute. Then the substructure defined by the substructure attribute is called to parse the extracted information, including: if the bit identification attribute of the substructure is "Y", indicating that the substructure is a bit type structure, the extracted information is converted into bit type data, and then the substructure is recursively called for parsing; if the bit identification attribute is "N", indicating that the substructure is a byte type structure, the substructure is directly recursively called for parsing the extracted information.

[0101] In the above-mentioned judgment of whether the self-loop condition and the parsing condition are met, the judgment method includes the following six cases: ① The judgment method is set to "==", which means judging whether the value of the variable is the same as the expected value. If the same, it is judged to meet the condition, if different, it is judged to meet the condition; ② The judgment method is set to "!=", which means judging whether the value of the variable is different from the expected value. If different, it is judged to meet the condition, if the same, it is judged not to meet the condition; ③ The judgment method is set to "morethan", which means judging whether the value of the variable is greater than the expected value. If greater, it is judged to meet the condition, if not greater, it is judged not to meet the condition; ④ The judgment method is set to "lessthan", which means judging whether the value of the variable is less than the expected value. If less, it is judged to meet the condition, if not less, it is judged not to meet the condition; ⑤ The judgment method is set to "single", which means judging whether the value of the variable is an odd number. If so, it is judged to meet the condition, if not, it is judged not to meet the condition; ⑥ The judgment method is set to "double", which means judging whether the value of the variable is an even number. If so, it is judged to meet the condition, if not, it is judged not to meet the condition. If the judgment method exceeds the above range, it is judged as a processing exception.

[0102] The aforementioned determination of the key value length of the current key value according to the parsing length attribute specifically includes: judging whether the variable defined by the parsing length attribute is of int type; if it is of int type, indicating that the item defines the current key value length, the value of the variable defined by the parsing length attribute is determined as the key value length of the current key value; if it is not of int type, indicating that the item defines a certain variable that has been parsed, and the current key value length needs to be determined by the current value of the variable, then according to the variable defined by the parsing length attribute, combined with the prefix list, the value of the variable is searched in the parsing data record dictionary; if it cannot be found normally, an error is reported and the exit is made; if it is found, the value of the variable is used as the key value length of the current key value.

[0103] Step S103: After completing the parsing of all message types, output the parsed data record dictionary.

[0104] After the parsing of all message types is completed, the parsing data record dictionary has recorded the parsing results of all message types, and thus the parsing data record dictionary is output, completing all parsing of the messages to be parsed.

[0105] The method of the present invention is described below with a specific example. For example, the message to be parsed is: 01 23 4508 89 01 01AA03 00 00 00 01 01 01 01..., and the configuration file is as follows: Figure 5 As shown, the parsing process is as follows:

[0106] The current parsing structure name is Main_Struct, the prefix Pre_Mark is empty (the prefix Pre_Mark is set to an empty string when the parsing function is called for the first time, that is, ""), the parsing data record dictionary is empty, and the prefix list is empty;

[0107] First, read each structure attribute according to the current parsed structure: the number of bytes defined by the number of loops is 0, the bit structure attribute is "N", there is no self-loop attribute (Sub_Self_Repeat), no custom prefix attribute (Name_Pre_Mark), and no self-loop merge attribute (Repeat_Combine);

[0108] The current prefix is ​​"", and the custom prefix attribute is determined to be empty, so the current custom prefix is ​​set to "", so that the current prefix is ​​still "";

[0109] Insert the current prefix to the front of the prefix list, and the prefix list becomes [""];

[0110] Determine that the self-loop attribute is not "Y" and there is no self-loop merge attribute;

[0111] Determine the number of loops in the current parsing structure and the number of byte attributes defined is 0;

[0112] Process the detail key values ​​in sequence according to the current structure, i.e. MA, the parsed length attribute (Msg Length) is 0, the sub-structure attribute (Sub_Struct) is Main_Detail, the number of loops attribute (Param_Repeat_Time) is "-", the loop attribute based on the variable value (Repeat_Base_Var) is "-", the loop to the end attribute (Repeat_Till_End) is "Y", the self-loop attribute (Sub_Self_Repeat) is "-", the type (Type) is Hex, and the endian (Detail_Byte_Endian) is "Little";

[0113] Determine that the virtual calculation attribute (Virtual_Math) is not defined in the MA structure;

[0114] Determine that the parsing length defined in the MA structure is 0, and record the key value length of the current key value as 0;

[0115] Determine whether the parsing condition parameter attribute (Cond_Key) of the current key value is empty;

[0116] In the current key value parsing rule, the number of loops is "-", the loop based on the variable value is "-", the special loop algorithm is empty, and the loop to the end is Y, so the number of loops is set to -1 (special value);

[0117] Determine that the number of cycles is not greater than 0;

[0118] The number of cycles is judged to be -1;

[0119] Determine that the current message has not been fully parsed;

[0120] Determine that the current key value parsing length is 0;

[0121] Then, according to the substructure definition of the current key value, a recursive calling function is defined to process the current remaining messages.

[0122] According to the current parsing structure (Main_Detail), read each structure attribute: the number of bytes defined by the number of loops is 0, the bit structure attribute is "N", there is no self-loop attribute (Sub_Self_Repeat), custom prefix attribute (Name_Pre_Mark), and self-loop merge attribute (Repeat_Combine);

[0123] The current prefix is ​​"MA.", and if the custom prefix attribute is empty, set the current custom prefix to "";

[0124] Insert the current prefix to the front of the prefix list, and the prefix list becomes ["MA.", ""];

[0125] Determine that the self-loop attribute is not "Y" and there is no self-loop merge attribute;

[0126] Determine the number of loops in the current parsing structure and the number of byte attributes defined is 0;

[0127] Process the detail key values ​​in sequence according to the current structure, that is, 0A, the parsed length attribute (Msg Length) is 2, the sub-structure attribute (Sub_Struct) is "-", the number of loops attribute is "-", the loop attribute based on the variable value (Repeat_Base_Var) is "-", the loop to the end attribute (Repeat_Till_End) is "-", the self-loop attribute (Sub_Self_Repeat) is empty, the type (Type) is Hex, and the size end (Detail_Byte_Endian) is "Little";

[0128] It is determined that the virtual calculation flag (Virtual_Math) is not defined in the 0A structure;

[0129] Determine that the parsing length defined in the 0A structure is 2, and record the key value length 2 of the current key value;

[0130] Determine whether the parsing condition parameter attribute (Cond_Key) of the current key value is empty;

[0131] Determine the current key value parsing rule, the number of loops, loop based on variable value is "-", the special loop algorithm is empty, and loop to end is "-";

[0132] Determine that the current key value length is 2;

[0133] The substructure definition for judging the current key value is "-";

[0134] According to the key value length 2, extract the information and record it in the parsing data record dictionary, that is, extract 01 23, update the parsing data record dictionary: MA.0A=0123, and the remaining message to be parsed is 45 08 89 01 01AA 03 00 00 00 01 0101 01...

[0135] Continue to return to process the next detail key value, that is, 0B, the parsed length attribute is 0, the substructure attribute is "Sub_A", the loop count attribute is "-", the loop attribute according to the variable value is "-", the loop to end attribute is "-", the self-loop flag is empty, the type is Hex, and the endianness is "Little";

[0136] Determine that no virtual computed attribute is defined in the 0B structure;

[0137] Determine that the parsing length defined in the 0B structure is 0, and record the key value length of the current key value as 0;

[0138] Determine whether the parsing condition parameter attribute of the current key value is empty;

[0139] Determine that in the current key value parsing rule, the loop times attribute and the loop based on variable value attribute are "-", the special loop algorithm attribute is empty, and the loop to end attribute is "-";

[0140] Determine that the current key value length is 0;

[0141] The parsing function is recursively called according to its substructure definition (Sub_A) for further processing.

[0142] According to the current parsed structure (Sub_A), read each structure attribute: the number of loop times defines the number of bytes as 0, the bit structure attribute is "N", the self-loop attribute is Y, the self-loop condition parameter attribute is 2B, the self-loop condition determination method attribute is "==", the self-loop condition expected value attribute is 1, the custom prefix attribute is 0A, and the self-loop merge attribute is N;

[0143] The current prefix is ​​"MA.0B", the custom prefix attribute is determined to be 0A, and the current value of 0A is 0123, so the current custom prefix is ​​set to "(0123)";

[0144] Update the current prefix content according to the custom prefix and insert it to the front of the prefix list. The prefix list becomes ["(0123)MA.0B", "MA.", ""];

[0145] Determine that the self-loop attribute is "Y" and the self-loop merge attribute is N. Add the loop number to the first position of the prefix list, and the prefix list becomes ["(0123)[0]MA.0B", "MA.", ""];

[0146] Determine the number of loops in the current parsing structure and the number of byte attributes defined is 0;

[0147] Process the detail key values ​​in sequence according to the current structure, i.e. 1A, the parsing length attribute is 1, the substructure attribute is "Sub_B", the loop times attribute is "-", the loop attribute based on the variable value is "-", the loop to end attribute is "-", the parsing condition parameter attribute is "-", the parsing condition judgment method attribute is "-", the parsing condition expected value attribute is "-", the type is Hex, and the endianness is "Little";

[0148] It is determined that no virtual computed attribute is defined in the 1A structure;

[0149] Determine that the parsing length defined in the 1A structure is 1, and record that the key value length of the current key value is 1;

[0150] Determine whether the parsing condition parameter attribute of the current key value is "-";

[0151] Determine the current key value parsing rule, the number of loops, loop based on variable value is "-", the special loop algorithm is empty, and loop to end is "-";

[0152] Determine that the current key value length is 1;

[0153] Determine the substructure definition of the current key value as "Sub_B";

[0154] According to the key value length 1, information 45 is extracted, and the remaining message to be parsed is 08 89 01 01AA03 0000 00 0101 01 01...;

[0155] The parsing function is recursively called according to its substructure definition (Sub_B), and the extracted information 45 is sent in for further processing.

[0156] According to the current parsing structure (Sub_B), read the values ​​of each structure attribute: the number of bytes defined by the number of loops is 0, the bit structure attribute is "Y", the self-loop attribute is empty, the self-loop condition parameter attribute is empty, the self-loop condition determination method attribute is empty, the self-loop condition expected value attribute is empty, the custom prefix attribute is empty, and the self-loop merge attribute is empty;

[0157] If the custom prefix attribute is empty, set the current custom prefix to "";

[0158] Insert the current prefix to the front of the prefix list, and the prefix list becomes ["(0123)[0]MA.0B.1A", "(0123)[0]MA.0B", "MA.", ""];

[0159] Determine whether the self-loop attribute and the self-loop merge attribute are empty;

[0160] Determine the number of loops in the current parsing structure and the number of byte attributes defined is 0;

[0161] Process the detail key values ​​in sequence according to the current structure, i.e. 2A, the parsing length attribute is 1 (the structure is a bit structure, which is 1 bit), the substructure attribute is "-", the loop times attribute is "5", the loop attribute based on the variable value is "-", the loop to end attribute is empty, the parsing condition parameter attribute, the parsing condition judgment method attribute, and the parsing condition expected value attribute are empty, the type is int, and the big and small endian is "-";

[0162] It is determined that no virtual computed attribute is defined in the 2A structure;

[0163] Determine that the parsing length defined in the 2A structure is 1, and record that the key value length of the current key value is 1;

[0164] Determine whether the parsing condition parameter attribute of the current key value is empty;

[0165] In the current key value parsing rule, the number of loops is 5, the loop based on the variable value is "-", the special loop algorithm is empty, and the loop to the end is empty;

[0166] If the number of loops is greater than 0, perform loop analysis;

[0167] It is determined that the target number of cycles has not been reached;

[0168] Determine whether the current key value length is not 0;

[0169] According to the key value length 1, extract the information and record it in the parsed data record dictionary, that is, extract the first bit in 45 (01000101), and update the parsed data record dictionary: (0123) [0] MA.0B.1A.2A [0] = 0, and the remaining parsed information is 1000101;

[0170] After 5 cycles, we get:

[0171] (0123)[0]MA.0B.1A.2A[0]=0,

[0172] (0123)[0]MA.0B.1A.2A[1]=1,

[0173] (0123)[0]MA.0B.1A.2A[2]=0,

[0174] (0123)[0]MA.0B.1A.2A[3]=0,

[0175] (0123)[0]MA.0B.1A.2A[4]=0;

[0176] Continue to perform subsequent parsing of the current structure and obtain:

[0177] (0123)[0]MA.0B.1A.2B=1、

[0178] (0123)[0]MA.0B.1A.2C=1 (01 converted to int type)

[0179] Return to the previous parsing structure.

[0180] In the Sub_A parsing structure, continue parsing. According to the previous parsing method, obtain (0123)[0]MA.0B.1B=08, and the remaining message to be parsed is 89 01 01AA03 00 00 00 01 01 0101...;

[0181] Continue loop parsing, and process the detail key values ​​in turn according to the current structure, that is, 1C, the parsing length attribute is 1B, the substructure attribute is "Sub_C", the loop times attribute is "-", the loop attribute based on the variable value is "-", the loop to end attribute is "-", the parsing condition parameter attribute is "0A", the parsing condition judgment method attribute is "==", the parsing condition expected value attribute is "0123", the type is Hex, and the endianness is "Little";

[0182] Determine that no virtual computed attribute is defined in the 1C structure;

[0183] Determine that the parsing length defined in the 1C structure is 1B, query the specific value of 1B in the current parsing data record dictionary according to the prefix list, and find (0123)[0]MA.0B.1B=08. The key value length of the current key value is 8;

[0184] Determine that the parsing condition parameter attribute of the current key value is "0A", and search for the specific value of 0A in the current parsing data record dictionary according to the prefix list. (0123) MA.0B.0A is not found, and MA.0A=0123 is found;

[0185] The current analysis condition is judged as "==", and the expected value is 0123, which is consistent with the current value of MA.0A, and meets the conditions, so further analysis is performed;

[0186] Determine the current key value parsing rule, the number of loops, loop based on variable value is "-", the special loop algorithm is empty, and loop to end is "-";

[0187] Determine that the current key value length is 8;

[0188] The substructure definition for judging the current key value is "Sub_C";

[0189] According to the key value length 8, extract the information 89 01 01AA 03 00 00 00..., and the remaining message to be parsed is 01 0101 01...;

[0190] The parsing function is recursively called according to its substructure definition (Sub_C) for further processing.

[0191] According to the current parsing structure (Sub_C), read each structure parameter: the number of bytes defining the number of loops is 0, the bit structure attribute is "N", the self-loop attribute, self-loop condition parameter attribute, self-loop condition determination method attribute, self-loop condition expected value attribute, custom prefix attribute, and self-loop merge attribute are all empty;

[0192] Determine if the custom prefix attribute is empty and set the current custom prefix to "";

[0193] Insert the current prefix to the front of the prefix list, and the prefix list becomes ["(0123)MA.0B.1C", "(0123)MA.0B", "MA.", ""];

[0194] Determine that the self-loop attribute is empty and the self-loop merge attribute is empty;

[0195] Determine the number of loops in the current parsing structure and the number of byte attributes defined is 0;

[0196] Process the detail key values ​​in sequence according to the current structure, and according to the normal parsing logic, obtain:

[0197] (0123)MA.0B.1C.3A=89,

[0198] (0123)MA.0B.1C.3B=1(01 to int),

[0199] (0123)MA.0B.1C.3C=1(01 to int), remaining AA03 00 00 00

[0200] Parse 3D, determine that the virtual calculation attribute in the 3D structure is BitCalcByte##3B##3C, call the BitCalcByte special calculation execution module to perform data calculation according to the logic processing function, obtain the current variable results of 3B and 3C, calculate 3D to be 1, and obtain (0123)MA.0B.1C.3D=1;

[0201] Parse 3E, the parsing length attribute is 1, the substructure attribute is "-", the loop count attribute is "-", the loop based on variable value attribute is "-", the loop to end attribute is "-", the parsing condition parameter attribute is "-", the parsing condition judgment method attribute is "-", the parsing condition expected value attribute is "-", the special loop algorithm attribute is BitCalcByte##3B##3C, the type is hex, and the endianness is "Little";

[0202] Determine whether the virtual calculated attribute in the 3E structure is empty;

[0203] Determine that the parsing length defined in the 3E structure is 1, and record that the key value length of the current key value is 1;

[0204] Determine that the parsing condition attribute of the current key value is "-";

[0205] Determine the current key value parsing rule, the number of loops, the loop based on the variable value is "-", the special loop algorithm is BitCalcByte##3B##3C, the loop to the end is "-", and the number of loops obtained according to the special loop algorithm BitCalcByte##3B##3C is 1;

[0206] Determine whether the number of cycles is greater than 0;

[0207] Loop analysis to obtain (0123)MA.0B.1C.3E[0]=AA, remaining 03 00 00 00;

[0208] Process the detail key values ​​in sequence according to the current structure, and according to the normal parsing logic, obtain:

[0209] (0123)MA.0B.1C.3F=3(03 converted to int), remaining 00 00 00;

[0210] Parse 3G, get the message length as 1, the substructure attribute is "-", the loop times attribute is "-", the loop attribute based on the variable value is "3F", the loop until the end attribute is "-", the parsing condition parameter attribute is "-", the parsing condition judgment method attribute is "-", the parsing condition expected value attribute is "-", the special loop algorithm attribute is "-", the type is Hex, and the endianness is "Little";

[0211] Determine whether the virtual calculation attribute in the 3G structure is empty;

[0212] Determine that the parsing length defined in the 3G structure is 1, and record the key value length 1 of the current key value;

[0213] Determine whether the parsing condition parameter attribute of the current key value is "-";

[0214] In the judgment 3G structure, the number of loops is "-", the loop according to the variable value is "3F", the special loop algorithm is "-", and the loop to the end is "-". According to 3F, i.e., the prefix list, (0123)MA.0B.1C.3F=3 is obtained, i.e., the number of loops is 3;

[0215] Determine whether the number of cycles is greater than 0;

[0216] Loop analysis to obtain:

[0217] (0123) MA.0B.1C.3G[0]=00,

[0218] (0123)MA.0B.1C.3G[1]=00,

[0219] (0123) MA.0B.1C.3G[2]=00;

[0220] The current structure is parsed and returns to the previous parsed structure to continue processing.

[0221] Continue the Sub_A structure loop parsing, and process the detail key values ​​in turn according to the current structure, that is, 1D, the parsing length attribute is 1B, the substructure attribute is "Sub_D", the loop times attribute is "-", the loop attribute based on the variable value is "-", the loop to end attribute is "-", the parsing condition parameter attribute is "0A", the parsing condition judgment method attribute is "==", the parsing condition expected value attribute is "0124", the type is Hex, and the endianness is "Little";

[0222] Determine if virtual computed attributes are not defined in the 1D structure;

[0223] Determine that the parsing length defined in the 1D structure is 1B, query the specific value of 1B in the current parsing data record dictionary according to the prefix list, and find (0123)[0]MA.0B.1B=08. The key value length of the current key value is 8.

[0224] Determine that the parsing condition parameter attribute of the current key value is "0A", and search for the specific value of 0A in the current parsing data record dictionary according to the prefix list. (0123) MA.0B.0A is not found, and MA.0A=0123 is found;

[0225] The current analysis condition judgment mode attribute is "==", and the expected value is 0124, which is inconsistent with the current value of MA.0A and does not meet the conditions, so 1D analysis is skipped.

[0226] According to the self-loop condition parameter 2B and the prefix list of Sub_A, (0123)[0]MA.0B.1A.2B=1 is obtained, which is consistent with the expected value of the self-loop condition. Therefore, the Sub_A parsing logic is repeatedly executed until the self-loop condition is not satisfied.

[0227] So far, the present invention has described the detailed parsing algorithm of the universal parsing tool as a whole, and the communication message is automatically disassembled according to the parsing configuration (message structure definition) to realize the splitting of the communication message and the recognition of its meaning. For complex message structures, a series of definitions such as self-loop attributes, loop count attributes, virtual calculation attributes, substructure attributes, and conditional judgment attributes are used to guide the tool to implement more complex loops and judgment logics, including operations such as obtaining subsequent parsing loop conditions or times from the parsed part of the current communication packet, realizing the universal parsing process of various special communication protocols, and automatically generating the current parameter prefix and name according to the parsing loop and field to ensure the uniqueness of the parameters in the parsing result.

[0228] Based on the same inventive concept, an embodiment of the present invention further provides a communication message parsing device, which is used to parse data corresponding to all message types from the message to be parsed, such as Figure 6 As shown, including:

[0229] The acquisition module 201 is used to acquire the message to be parsed and the corresponding configuration file, wherein the configuration file defines the parsing structure information of all message types, and the parsing structure contains information of several key values;

[0230] The parsing module 202 is used to perform the following processing for each message type to be parsed: obtain the parsing structure of the message type, perform structural parsing according to the structural attributes defined in the parsing structure, and sequentially parse the key values ​​contained in the parsing structure according to the defined key value attributes, and record the parsing result of each key value in the parsing data record dictionary;

[0231] The output module 203 is used to output the parsed data record dictionary after completing the parsing of all message types.

[0232] Optionally, the structural attributes of the parsed structure definition include: a custom prefix attribute;

[0233] The parsing module 202 performs structural parsing according to the structural attributes defined in the parsed structure, including:

[0234] If the custom prefix attribute is empty or "-", the custom prefix of the current prefix is ​​set to empty, and the current prefix is ​​updated to the first position in the prefix list;

[0235] If the custom prefix attribute is not empty, obtain the prefix at the first position from the prefix list, combine it with the variable in the custom prefix attribute to form a variable name, and look up the value corresponding to the variable name in the current parsed data record dictionary, place the value as the custom prefix in front of the current prefix, and update the current prefix to the first position in the prefix list.

[0236] Optionally, the structural attributes of the parsing structure definition further include: a self-loop attribute, a self-loop merging attribute, and a loop count definition byte attribute;

[0237] The parsing module 202 performs structural parsing according to the structural attributes defined in the parsed structure, and further includes:

[0238] If the self-loop attribute is "Y" and the self-loop merge attribute is not "Y", the first prefix in the prefix list is updated according to the number of self-loop cycles;

[0239] Determine whether the byte attribute for defining the number of loops is defined; if the byte attribute for defining the number of loops is not defined, parse each key value in the parsing structure in turn; if the byte attribute for defining the number of loops is defined, determine the number of loops according to the number of bytes defined by the attribute, and perform a cyclic parsing on the parsing structure according to the number of loops, each cyclic parsing creates a new group of substructures according to the current number of loops, and parses each key value record in the substructure in turn according to the parsing structure until the number of loops is completed.

[0240] Optionally, the structural attributes of the analytical structure definition further include: a self-loop condition parameter attribute, a self-loop condition determination method attribute, and a self-loop condition expected value attribute;

[0241] The parsing module 202 performs structural parsing according to the structural attributes defined in the parsed structure, and further includes:

[0242] After the parsing is completed, determine whether the self-loop condition parameter attribute is empty or "-";

[0243] If the self-loop condition parameter attribute is empty or "-", the parsing of the parsing structure is terminated;

[0244] If the self-loop condition parameter attribute is not empty or "-", the value of the variable is searched in the parsed data record dictionary based on the variable defined by the self-loop condition parameter attribute in combination with the prefix list, and a judgment is made based on the judgment method defined by the self-loop condition judgment method attribute and the expected value defined by the self-loop condition expected value attribute. If the judgment result is that the self-loop condition is met, the next loop analysis is continued. If the judgment result is that the self-loop condition is not met, the loop analysis of the parsing structure is terminated.

[0245] Optionally, the key value attributes of the key value definition include: a virtual calculation attribute, a parsing length attribute, a parsing condition parameter attribute, a parsing condition determination method attribute, and a parsing condition expected value attribute;

[0246] The parsing module 202 performs parsing processing on the key value contained in the parsing structure according to the key value attribute, including:

[0247] Determine whether the virtual calculation attribute of the current key value is empty or "-"; if the virtual calculation attribute is not empty or "-", perform data calculation according to the logic processing function defined by the virtual calculation attribute, and record the calculation result as the parsing result of the current key value in the parsing data record dictionary; if the virtual calculation attribute is empty or "-", determine the key value length of the current key value according to the parsing length attribute;

[0248] Determine whether the parsing condition parameter attribute of the current key value is empty or "-"; if the parsing condition parameter attribute is empty or "-", continue with the subsequent parsing; if the parsing condition parameter attribute is not empty or "-", then according to the variable in the parsing condition parameter attribute, in combination with the prefix list, look up the value of the variable in the parsing data record dictionary, and make a judgment according to the judgment method defined by the parsing condition judgment method attribute and the expected value defined by the parsing condition expected value attribute. If the judgment result is that the parsing condition is met, continue with the subsequent parsing; if the judgment result is that the parsing condition is not met, skip the current key value and perform the parsing of the next key value;

[0249] Determine whether the current key value needs to be parsed in a loop; if not, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and then continue to parse the next key value; if cyclic parsing is required, determine the number of loops, and cyclically parse the current key value according to the number of loops. In each parsing, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and continue to parse the next key value after the cyclic parsing is completed.

[0250] Optionally, the parsing module 202 determines the key value length of the current key value according to the parsing length attribute, including:

[0251] Determine whether the variable defined by the parsing length attribute is of int type. If it is of int type, determine the value of the variable defined by the parsing length attribute as the key value length of the current key value; if it is not of int type, then according to the variable defined by the parsing length attribute, combined with the prefix list, search for the value of the variable in the parsing data record dictionary, and use the value of the variable as the key value length of the current key value.

[0252] Optionally, the key value attributes of the key value definition include: a loop count attribute, a loop attribute based on a variable value, a special loop algorithm attribute, and a loop to end attribute;

[0253] The parsing module 202 determines whether the current key value needs to be cyclically parsed, including:

[0254] If the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute are all empty or "-", and the loop to end attribute is not "Y", it is determined that the current key value does not need loop analysis;

[0255] If any one of the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute is not empty or "-", or the loop to end attribute is "Y", it is determined that the current key value needs loop analysis.

[0256] Optionally, the parsing module 202 determines the number of cycles, including:

[0257] If the loop count attribute is not empty or "-", the value of the variable defined by the loop count attribute is determined as the loop count;

[0258] If the loop attribute based on variable value is not empty or "-", then according to the variable defined by the loop attribute based on variable value, in combination with the prefix list, the value of the variable is searched in the parsed data record dictionary, and the value of the variable is used as the number of loops;

[0259] If the special loop algorithm attribute is not empty or "-", data calculation is performed according to the logic processing function defined by the special loop algorithm attribute, and the calculation result is used as the number of loops;

[0260] If the loop to end attribute is "Y", the number of loops is set to -1.

[0261] Optionally, the parsing module 202 performs a loop parsing on the current key value according to the loop number, including:

[0262] If the number of loops is greater than 0, the current key value is looped according to the number of loops;

[0263] If the number of loops is -1, the current key value will be processed in a loop until all the information in the current parsing structure is parsed;

[0264] If the number of loops is 0, skip the current key value and execute the parsing of the next key value.

[0265] Optionally, the key-value attributes of the key-value definition include: substructure attributes;

[0266] The parsing module 202 parses the message to be parsed according to the key value length, and records the parsing result in a parsing data record dictionary, including:

[0267] Determine whether the key value length of the current key value is 0; if not, extract information from the remaining unextracted information of the message to be parsed according to the key value length; if 0, extract all the remaining unextracted information of the message to be parsed;

[0268] Determine whether the substructure attribute of the current key value is empty or "-"; if it is empty or "-", record the extracted information in the parsing data record dictionary; if it is not empty "-", call the substructure defined by the substructure attribute to parse the extracted information, and record the parsing result in the parsing data record dictionary.

[0269] Optionally, the structural attributes of the substructure include: bit structural attributes;

[0270] The parsing module 202 calls the substructure defined by the substructure attribute to parse the extracted information, including:

[0271] If the bit identification attribute of the substructure is "Y", the extracted information is converted into bit type data, and then the substructure is recursively called for parsing;

[0272] If the bit identification attribute is "N", the substructure is directly recursively called to parse the extracted information.

[0273] Optionally, the determination method includes:

[0274] Determine whether the value of the variable is the same as the expected value. If so, it is determined to meet the conditions. If not, it is determined to meet the conditions.

[0275] Determine whether the value of the variable is different from the expected value. If different, it is determined to meet the conditions. If the same, it is determined not to meet the conditions.

[0276] Determine whether the value of the variable is greater than the expected value. If so, it is determined to meet the conditions. If not, it is determined to not meet the conditions.

[0277] Determine whether the value of the variable is less than the expected value. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0278] Determine whether the value of the variable is an odd number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0279] Determine whether the value of the variable is an even number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

[0280] An embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 301, a communication interface 302, a memory 303 and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304;

[0281] Memory 303, used for storing computer programs;

[0282] The processor 301 is used to implement the steps of the communication message parsing method in the above embodiment when executing the program stored in the memory 303.

[0283] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the communication message parsing method in the above embodiment are implemented.

[0284] In another embodiment of the present invention, a computer program product including instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the communication message parsing method in the above embodiment.

[0285] In summary, the present invention provides a universal communication message parsing method and device, which realizes the decoupling of communication protocol definition and parsing logic, so that testers can parse specific communication messages only by completing the communication protocol file, thereby improving the universality of the parsing process, reducing work complexity, and improving work efficiency and quality.

[0286] Although the content of the present invention has been described in detail through the above preferred embodiments, it should be appreciated that the above description should not be considered as a limitation of the present invention. After reading the above content, it will be apparent to those skilled in the art that various modifications and substitutions of the present invention will occur. Therefore, the protection scope of the present invention should be limited by the appended claims.

Claims

1. A communication message parsing method, used to parse data corresponding to all message types from a message to be parsed, characterized in that: The steps include: Obtain the message to be parsed and the corresponding configuration file, wherein the configuration file defines the parsing structure information of all message types, and the parsing structure contains information of several key values; For each message type, the following processing is performed: obtaining the parsing structure of the message type, performing structural parsing according to the structural attributes defined in the parsing structure, and sequentially parsing the key values ​​contained in the parsing structure according to the defined key value attributes, and recording the parsing result of each key value in the parsing data record dictionary; After parsing of all message types is completed, the parsed data record dictionary is output.

2. The communication message parsing method according to claim 1, characterized in that: The structural attributes of the parsing structure definition include: a custom prefix attribute; The performing structural analysis according to the structural attributes defined in the analytical structure includes: If the custom prefix attribute is empty or "-", the custom prefix of the current prefix is ​​set to empty, and the current prefix is ​​updated to the first position in the prefix list; If the custom prefix attribute is not empty, obtain the prefix at the first position from the prefix list, combine it with the variable in the custom prefix attribute to form a variable name, and look up the value corresponding to the variable name in the current parsed data record dictionary, place the value as the custom prefix in front of the current prefix, and update the current prefix to the first position in the prefix list.

3. The communication message parsing method according to claim 2, characterized in that: The structural attributes of the parsing structure definition also include: self-loop attribute, self-loop merging attribute, and loop count definition byte attribute; The performing structural analysis according to the structural attributes defined in the analytical structure also includes: If the self-loop attribute is "Y" and the self-loop merge attribute is not "Y", the first prefix in the prefix list is updated according to the number of self-loop cycles; Determine whether the byte attribute for defining the number of loops is defined; if the byte attribute for defining the number of loops is not defined, parse each key value in the parsing structure in turn; if the byte attribute for defining the number of loops is defined, determine the number of loops according to the number of bytes defined by the attribute, and perform a cyclic parsing on the parsing structure according to the number of loops, each cyclic parsing creates a new group of substructures according to the current number of loops, and parses each key value record in the substructure in turn according to the parsing structure until the number of loops is completed.

4. The communication message parsing method according to claim 3, characterized in that: The structural attributes of the analytical structure definition also include: self-loop condition parameter attributes, self-loop condition determination method attributes, and self-loop condition expected value attributes; The performing structural analysis according to the structural attributes defined in the analytical structure also includes: After the parsing is completed, determine whether the self-loop condition parameter attribute is empty or "-"; If the self-loop condition parameter attribute is empty or "-", the parsing of the parsing structure is terminated; If the self-loop condition parameter attribute is not empty or "-", the value of the variable is searched in the parsed data record dictionary according to the variable defined by the self-loop condition parameter attribute in combination with the prefix list, and a judgment is made according to the judgment method defined by the self-loop condition judgment method attribute and the expected value defined by the self-loop condition expected value attribute. If the judgment result is that the self-loop condition is met, the next loop analysis is continued. If the judgment result is that the self-loop condition is not met, the loop analysis of the parsing structure is terminated.

5. The communication message parsing method according to claim 1, characterized in that: The key value attributes of the key value definition include: virtual calculation attribute, parsing length attribute, parsing condition parameter attribute, parsing condition determination method attribute, and parsing condition expected value attribute; The parsing process of the key value contained in the parsed structure according to the key value attribute includes: Determine whether the virtual calculation attribute of the current key value is empty or "-"; if the virtual calculation attribute is not empty or "-", perform data calculation according to the logic processing function defined by the virtual calculation attribute, and record the calculation result as the parsing result of the current key value in the parsing data record dictionary; if the virtual calculation attribute is empty or "-", determine the key value length of the current key value according to the parsing length attribute; Determine whether the parsing condition parameter attribute of the current key value is empty or "-"; if the parsing condition parameter attribute is empty or "-", continue the subsequent parsing; if the parsing condition parameter attribute is not empty or "-", then according to the variable in the parsing condition parameter attribute, in combination with the prefix list, search for the value of the variable in the parsing data record dictionary, and make a judgment according to the judgment method defined by the parsing condition judgment method attribute and the expected value defined by the parsing condition expected value attribute. If the judgment result is that the parsing condition is met, continue the subsequent parsing; if the judgment result is that the parsing condition is not met, skip the current key value and perform the parsing of the next key value; Determine whether the current key value needs to be parsed in a loop; if not, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and then continue to parse the next key value; if cyclic parsing is required, determine the number of loops, and cyclically parse the current key value according to the number of loops. In each parsing, parse the message to be parsed according to the key value length, record the parsing result in the parsing data record dictionary, and continue to parse the next key value after the cyclic parsing is completed.

6. The communication message parsing method according to claim 5, characterized in that: The determining the key value length of the current key value according to the parsed length attribute includes: Determine whether the variable defined by the parsing length attribute is of int type. If it is of int type, determine the value of the variable defined by the parsing length attribute as the key value length of the current key value; if it is not of int type, then according to the variable defined by the parsing length attribute, combined with the prefix list, search for the value of the variable in the parsing data record dictionary, and use the value of the variable as the key value length of the current key value.

7. The communication message parsing method according to claim 5, characterized in that: The key value attributes of the key value definition include: loop count attribute, loop attribute based on variable value, special loop algorithm attribute, and loop to end attribute; The step of determining whether the current key value needs to be cyclically parsed includes: If the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute are all empty or "-", and the loop to end attribute is not "Y", it is determined that the current key value does not need loop analysis; If any one of the loop count attribute, the variable value loop attribute, and the special loop algorithm attribute is not empty or "-", or the loop to end attribute is "Y", it is determined that the current key value needs loop analysis.

8. The communication message parsing method according to claim 7, characterized in that: Determining the number of cycles comprises: If the loop count attribute is not empty or "-", the value of the variable defined by the loop count attribute is determined as the loop count; If the loop attribute based on variable value is not empty or "-", then according to the variable defined by the loop attribute based on variable value, combined with the prefix list, the value of the variable is searched in the parsed data record dictionary, and the value of the variable is used as the number of loops; If the special loop algorithm attribute is not empty or "-", data calculation is performed according to the logic processing function defined by the special loop algorithm attribute, and the calculation result is used as the number of loops; If the loop to end attribute is "Y", the number of loops is set to -1.

9. The communication message parsing method according to claim 8, characterized in that: The looping and parsing of the current key value according to the loop number includes: If the number of loops is greater than 0, the current key value is processed in a loop according to the number of loops; If the number of loops is -1, the current key value will be processed in a loop until all the information in the current parsing structure is parsed; If the number of loops is 0, skip the current key value and execute the parsing of the next key value.

10. The communication message parsing method according to claim 5, characterized in that: The key-value attributes of the key-value definition include: substructure attributes; The step of parsing the message to be parsed according to the key value length and recording the parsing result in a parsing data record dictionary includes: Determine whether the key value length of the current key value is 0; if not, extract information from the remaining unextracted information of the message to be parsed according to the key value length; if 0, extract all the remaining unextracted information of the message to be parsed; Determine whether the substructure attribute of the current key value is empty or "-"; if it is empty or "-", the extracted information is recorded in the parsed data record dictionary; if it is not empty "-", the substructure defined by the substructure attribute is called to parse the extracted information, and the parsing result is recorded in the parsed data record dictionary.

11. The communication message parsing method according to claim 10, characterized in that: The structural attributes of the substructure include: bit structural attributes; The calling of the substructure defined by the substructure attribute to parse the extracted information includes: If the bit identification attribute of the substructure is "Y", the extracted information is converted into bit type data, and then the substructure is recursively called for parsing; If the bit identification attribute is "N", the substructure is directly recursively called to parse the extracted information.

12. The communication message parsing method according to claim 4 or 5, characterized in that: The determination method includes: Determine whether the value of the variable is the same as the expected value. If so, it is determined to meet the conditions. If not, it is determined to meet the conditions. Determine whether the value of the variable is different from the expected value. If different, it is determined to meet the conditions. If the same, it is determined not to meet the conditions. Determine whether the value of the variable is greater than the expected value. If so, it is determined to meet the conditions. If not, it is determined to not meet the conditions. Determine whether the value of the variable is less than the expected value. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions. Determine whether the value of the variable is an odd number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions. Determine whether the value of the variable is an even number. If so, it is determined to meet the conditions. If not, it is determined not to meet the conditions.

13. A communication message parsing device, used to parse data corresponding to all message types from a message to be parsed, characterized in that: include: An acquisition module is used to acquire a message to be parsed and a corresponding configuration file, wherein the configuration file defines information on parsing structures of all message types, and the parsing structure contains information on a number of key values; The parsing module is used to perform the following processing for each message type to be parsed: obtaining the parsing structure of the message type, performing structural parsing according to the structural attributes defined in the parsing structure, and successively parsing the key values ​​contained in the parsing structure according to the defined key value attributes, and recording the parsing result of each key value in the parsing data record dictionary; The output module is used to output the parsed data record dictionary after completing the parsing of all message types.

14. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 12 when executing a program stored in a memory.

15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 12 are implemented.