CN115801927A - Message parsing method and device - Google Patents
Message parsing method and device Download PDFInfo
- Publication number
- CN115801927A CN115801927A CN202211457115.4A CN202211457115A CN115801927A CN 115801927 A CN115801927 A CN 115801927A CN 202211457115 A CN202211457115 A CN 202211457115A CN 115801927 A CN115801927 A CN 115801927A
- Authority
- CN
- China
- Prior art keywords
- message
- frame
- data
- key
- value
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Computer And Data Communications (AREA)
- Machine Translation (AREA)
Abstract
Description
技术领域technical field
本发明涉及通信技术领域,尤其涉及一种报文解析方法及装置。The present invention relates to the field of communication technology, in particular to a message analysis method and device.
背景技术Background technique
在轨道交通信号通信领域,UDP(User Datagram Protocol,用户数据报协议)具有时延小、实时性高等特点,广泛应用于报文数据传输。In the field of rail transit signal communication, UDP (User Datagram Protocol) has the characteristics of small delay and high real-time performance, and is widely used in message data transmission.
相关技术中,在应对一个客户端或服务器接收到来自其他客户端或服务器多种不同类型的UDP报文,且报文包含多种类型的消息时,需要多次修改原有的UDP报文解析程序,对多类型的报文信息进行解析或存储的效率低。In related technologies, when a client or server receives multiple different types of UDP packets from other clients or servers, and the packets contain multiple types of messages, it is necessary to modify the original UDP packet analysis multiple times. program, the efficiency of parsing or storing multi-type message information is low.
发明内容Contents of the invention
本发明提供一种报文解析方法,用以解决现有技术中对多类型的报文信息进行解析或存储的效率低,处理周期长的缺陷,提高了对多类型报文的处理效率。The invention provides a message parsing method, which is used to solve the defects of low efficiency in parsing or storing multi-type message information and long processing period in the prior art, and improves the processing efficiency of multi-type message.
本发明提供一种报文解析方法,包括:The present invention provides a message parsing method, comprising:
在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,所述待解析的报文数据包括多个帧消息;When multiple clients perform message communication with multiple server ends, determine message data to be parsed, where the message data to be parsed includes multiple frame messages;
基于预设的帧消息解析表对所述帧消息进行解析,得到所述帧消息对应的key-value数据,所述帧消息解析表包括多个有序排列的标识信息,所述多个有序排列的标识信息的数量基于所述帧消息的数据长度确定,所述多个有序排列的标识信息用于指示所述帧数据的类别;The frame message is parsed based on the preset frame message parsing table to obtain the key-value data corresponding to the frame message, the frame message parsing table includes a plurality of orderly arranged identification information, and the plurality of orderly The number of arranged identification information is determined based on the data length of the frame message, and the plurality of ordered identification information is used to indicate the category of the frame data;
将所述帧消息对应的key-value数据存储在所述报文数据中,得到字典数据结构。根据本发明提供的一种报文解析方法,所述帧消息包括帧头和帧数据,所述标识信息包括标识序号和标识值,每个标识序号对应多个标识值;storing the key-value data corresponding to the frame message in the message data to obtain a dictionary data structure. According to a message parsing method provided by the present invention, the frame message includes a frame header and frame data, and the identification information includes an identification number and an identification value, and each identification number corresponds to a plurality of identification values;
所述基于预设的帧消息解析表对所述帧消息进行解析,得到所述帧消息对应的key-value数据,包括:The frame message is parsed based on the preset frame message parsing table to obtain key-value data corresponding to the frame message, including:
以所述帧头的位置为起始位置,将多个所述标识序号依次填充至所述帧数据对应的数据结构,得到所述帧消息对应的外层key数据;Taking the position of the frame header as the starting position, sequentially filling a plurality of the identification serial numbers into the data structure corresponding to the frame data to obtain the outer key data corresponding to the frame message;
基于所述帧消息解析表查找所述多个标识序号对应的目标标识值,所述目标标识值为所述多个标识值中的一项;Searching for target identification values corresponding to the plurality of identification numbers based on the frame message parsing table, where the target identification value is one of the plurality of identification values;
基于所述外层key数据和所述目标标识值,得到所述帧消息对应的key-value数据。Based on the outer key data and the target identification value, key-value data corresponding to the frame message is obtained.
根据本发明提供的一种报文解析方法,所述将所述帧消息对应的key-value数据存储在所述报文数据中,得到字典数据结构,包括:According to a message parsing method provided by the present invention, the key-value data corresponding to the frame message is stored in the message data to obtain a dictionary data structure, including:
将每个帧消息对应的key-value数据分别存储在所述帧消息的帧类型结构,得到所述字典数据结构。The key-value data corresponding to each frame message is respectively stored in the frame type structure of the frame message to obtain the dictionary data structure.
根据本发明提供的一种报文解析方法,所述标识值包括数字、字母或数字和字母的组合中的至少一项。According to a message parsing method provided by the present invention, the identification value includes at least one of numbers, letters or a combination of numbers and letters.
根据本发明提供的一种报文解析方法,在所述得到所述报文数据的字典数据结构之后,所述方法还包括:According to a message parsing method provided by the present invention, after the dictionary data structure of the message data is obtained, the method further includes:
将所述字典数据结构存储于消息队列对应的数据集群。The dictionary data structure is stored in the data cluster corresponding to the message queue.
本发明还提供一种报文解析装置,包括:The present invention also provides a message parsing device, including:
确认模块,用于在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,所述待解析的报文数据包括多个帧消息;A confirmation module, configured to determine message data to be parsed when multiple clients perform message communications with multiple server ends, and the message data to be parsed includes multiple frame messages;
第一处理模块,用于基于预设的帧消息解析表对所述帧消息进行解析,得到所述帧消息对应的key-value数据,所述帧消息解析表包括多个有序排列的标识信息,所述多个有序排列的标识信息的数量基于所述帧消息的数据长度确定,所述多个有序排列的标识信息用于指示所述帧数据的类别;The first processing module is configured to parse the frame message based on a preset frame message parsing table to obtain key-value data corresponding to the frame message, and the frame message parsing table includes a plurality of identification information arranged in an orderly manner , the quantity of the plurality of ordered identification information is determined based on the data length of the frame message, and the plurality of ordered identification information is used to indicate the category of the frame data;
第二处理模块,用于将所述帧消息对应的key-value数据存储在所述报文数据中,得到字典数据结构。The second processing module is configured to store the key-value data corresponding to the frame message in the message data to obtain a dictionary data structure.
根据本发明提供的一种报文解析装置,所述装置还包括:According to a message parsing device provided by the present invention, the device also includes:
第三处理模块,用于在所述得到所述报文数据的字典数据结构之后,将所述字典数据结构存储于消息队列对应的数据集群。The third processing module is configured to store the dictionary data structure in a data cluster corresponding to the message queue after the dictionary data structure of the message data is obtained.
本发明还提供一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现如上述任一种所述报文解析方法。The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and operable on the processor. When the processor executes the program, it implements message analysis as described in any of the above method.
本发明还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如上述任一种所述报文解析方法。The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any one of the message parsing methods described above can be implemented.
本发明还提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上述任一种所述报文解析方法。The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, any one of the message parsing methods described above is implemented.
本发明提供的报文解析方法和装置,通过帧消息在报文数据中的位置信息和每条消息的数据长度获取每条帧消息的key-value数据,并将key-value数据添加至每条帧消息的帧类型结构中,组成新的值的字典结构;通过提取帧消息的key-value数据与帧消息的帧类型组成新的数据结构,提高了对多种不同类型的报文数据解析、归类和存储的效率。The message parsing method and device provided by the present invention obtain the key-value data of each frame message through the position information of the frame message in the message data and the data length of each message, and add the key-value data to each In the frame type structure of the frame message, a new value dictionary structure is formed; by extracting the key-value data of the frame message and the frame type of the frame message to form a new data structure, it improves the analysis of various types of message data, Sorting and storage efficiency.
附图说明Description of drawings
为了更清楚地说明本发明或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the present invention or the technical solutions in the prior art, the accompanying drawings that need to be used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings in the following description are the present invention. For some embodiments of the invention, those skilled in the art can also obtain other drawings based on these drawings without creative effort.
图1是本发明提供的报文解析方法的流程示意图之一;Fig. 1 is one of the schematic flow charts of the message parsing method provided by the present invention;
图2是本发明提供的帧消息的结构示意图;Fig. 2 is a schematic structural diagram of a frame message provided by the present invention;
图3是本发明提供的帧消息解析表的结构示意图;Fig. 3 is a schematic structural diagram of a frame message parsing table provided by the present invention;
图4是本发明提供的报文解析方法的流程示意图之二;Fig. 4 is the second schematic flow diagram of the message parsing method provided by the present invention;
图5是本发明提供的报文解析装置的结构示意图;Fig. 5 is a schematic structural diagram of a message parsing device provided by the present invention;
图6是本发明提供的电子设备的结构示意图。Fig. 6 is a schematic structural diagram of an electronic device provided by the present invention.
具体实施方式Detailed ways
为使本发明的目的、技术方案和优点更加清楚,下面将结合本发明中的附图,对本发明中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention , but not all examples. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.
下面结合图1-图4描述本发明的报文解析方法。The message parsing method of the present invention will be described below in conjunction with FIGS. 1-4 .
图1是本发明提供的报文解析方法的流程示意图之一,该报文解析方法包括:Fig. 1 is one of the schematic flow charts of the message analysis method provided by the present invention, and the message analysis method comprises:
步骤110、在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,待解析的报文数据包括多个帧消息。
在该步骤中,待解析的报文数据可以是UDP报文或基于其他通信协议而构建的报文。In this step, the packet data to be parsed may be a UDP packet or a packet constructed based on other communication protocols.
在该实施例中,报文数据的发送端可以是一个客户端,也可以是包括多个客户端的客户端集群,例如,客户端集群为Client i(i=1、2、3、4…),相应的,报文数据的接收端可以是一个服务端,也可以包括多个服务端的服务端集群,例如,服务端集群可以是Serveri(i=1、2、3、4…)。In this embodiment, the sender of the message data may be a client, or a client cluster including multiple clients, for example, the client cluster is Client i (i=1, 2, 3, 4...) Correspondingly, the receiver of message data may be a server, or may include a server cluster of multiple servers, for example, the server cluster may be Serveri (i=1, 2, 3, 4...).
在该实施例中,当Client1同时接收来自Server2和Server3的UDP报文,Server2的报文数据类型为TYPE2,Server3的报文类型为TYPE3,报文数据的格式如下:In this embodiment, when Client1 receives the UDP message from Server2 and Server3 simultaneously, the message data type of Server2 is TYPE2, and the message type of Server3 is TYPE3, and the format of message data is as follows:
其他数据+TYPE2-帧1消息-帧2消息-帧3消息-…-帧n消息。Other data + TYPE2-
其中,其他数据-TYPE2为该报文数据的报文头,每帧消息的格式如下:Among them, other data-TYPE2 is the header of the message data, and the format of each frame message is as follows:
目标标识-源-类型-长度-帧数据。Destination ID-Source-Type-Length-Frame Data.
其中,目标标识表示接收端地址信息,源表示发送端地址信息,类型表示报文类型,长度为表示该报文数据的帧数据长度,为计数值,帧数据表示该报文数据中包含的帧消息;目标标识、源、类型和长度均占一个字节,比特数为8,帧数据长度可调整,例如,帧数据比特数为8*8bit。Among them, the target identifier represents the address information of the receiving end, the source represents the address information of the sending end, the type represents the message type, the length represents the frame data length of the message data, and is a count value, and the frame data represents the frame contained in the message data Message; target identification, source, type and length all occupy one byte, the number of bits is 8, and the length of frame data can be adjusted, for example, the number of bits of frame data is 8*8bit.
图2是本发明提供的帧消息的结构示意图,在图2所示的实施例中,Server2发送给Client1的报文数据中,第一个帧消息(对应帧1)的目标标识假设为Client1的编号0xE0;“源”占一个字节,这里假设为Server2的编号0x81;类型占一个字节,代表帧1消息的类型,假设为0x01;长度占一个字节,代表后面帧数据所占的字节长度,假设为0x08。Fig. 2 is the structural representation of the frame message that the present invention provides, and in the embodiment shown in Fig. 2, in the message data that Server2 sends to Client1, the target identification of the first frame message (corresponding frame 1) is assumed to be Client1's The number is 0xE0; "source" occupies one byte, here it is assumed to be the number of Server2 0x81; the type occupies one byte, representing the type of
步骤120、基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,帧消息解析表包括多个有序排列的标识信息,多个有序排列的标识信息的数量基于帧消息的数据长度确定,多个有序排列的标识信息用于指示帧数据的类别。Step 120: Analyze the frame message based on the preset frame message analysis table to obtain the key-value data corresponding to the frame message. The frame message analysis table includes a plurality of orderly arranged identification information, and the number of orderly arranged identification information The quantity is determined based on the data length of the frame message, and a plurality of sequentially arranged identification information is used to indicate the type of the frame data.
在该步骤中,报文数据中的帧消息可以有多个不同的标识信息,例如,帧数据长度为8个字节时,可以保存至少20种标识信息,每种标识信息所占的比特位最小为1,最大为8,对应给的标识值为1和0的有限种组合。In this step, the frame message in the message data can have a plurality of different identification information, for example, when the frame data length is 8 bytes, at least 20 kinds of identification information can be saved, and the bits occupied by each identification information The minimum is 1, and the maximum is 8, which corresponds to a limited number of combinations of 1 and 0.
在该实施例中,帧消息的不同标识信息对应的初始位置可以是报文数据的多个帧消息的帧头出现的第一个位置,例如,由于报文数据的组成包括报文头和帧消息,每帧消息包括目标标识、源、类型、长度和帧数据,其中,目标标识的初始位置可以记为0,即目标标识对应的比特位为0,由于目标标识在报文数据中占1个字节,包含的信息量为8比特,则源对应的初始位置可以记为8,目标标识的初始位置与原的初始位置之间的位置距离为目标标识所包含的比特数目。In this embodiment, the initial position corresponding to different identification information of the frame message may be the first position where the frame headers of multiple frame messages of the message data appear, for example, since the composition of the message data includes the message header and the frame message, each frame message includes target ID, source, type, length and frame data, wherein the initial position of the target ID can be recorded as 0, that is, the bit corresponding to the target ID is 0, since the target ID occupies 1 in the message data bytes, the amount of information contained is 8 bits, then the initial position corresponding to the source can be recorded as 8, and the position distance between the initial position of the target identification and the original initial position is the number of bits contained in the target identification.
在该步骤中,帧消息的信息量可以是帧消息包含的比特数目。In this step, the information amount of the frame message may be the number of bits contained in the frame message.
在该步骤中,帧消息对应的key-value数据由标识信息中的目标标识值确定,例如,对于帧类型为0xE001的帧消息,对应的key-value数据可以是“标识信息1:数字或字符串类型值”的组合,例如:“标识信息1:1”、“标识信息2:5”、“标识信息3:hello”或“标识信息20:2”。In this step, the key-value data corresponding to the frame message is determined by the target identification value in the identification information. For example, for a frame message whose frame type is 0xE001, the corresponding key-value data can be "identification information 1: number or character string type value", for example: "identification information 1:1", "identification information 2:5", "identification information 3: hello" or "identification information 20:2".
在一些实施例中,在报文数据中的帧消息被解析之前,会先进行帧消息类型校验,通过目标标识与帧消息类型的组合,判断目标标识是否为当前客户端集群,对应的帧消息的类型是否为所需解析的类型。In some embodiments, before the frame message in the message data is parsed, the frame message type check will be performed first, and through the combination of the target identifier and the frame message type, it is judged whether the target identifier is the current client cluster, and the corresponding frame Whether the type of the message is the type that needs to be parsed.
步骤130、将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构。
在该步骤中,将解析得到的key-value数据可以存储在对应帧消息的帧类型下,得到新的帧存储结构。In this step, the parsed key-value data can be stored under the frame type of the corresponding frame message to obtain a new frame storage structure.
在一些实施例中,将原报文数据解析后生成的新的帧存储结构可以是值的字典数据结构。In some embodiments, the new frame storage structure generated after parsing the original message data may be a value dictionary data structure.
在该实施例中,将报文数据中的每个帧消息按照上述解析规则进行解析后,将解析得到的帧消息分别存储在每个帧消息对应的帧类型所在的结构下,得到报文数据的值的字典。In this embodiment, after each frame message in the message data is parsed according to the above parsing rules, the parsed frame messages are respectively stored in the structure where the frame type corresponding to each frame message is located, and the message data is obtained A dictionary of values.
图3是本发明提供的帧消息类型的示意图,在图3所示的实施例中,帧类型对应1个字节,包含的比特数为8,帧数据长度假设为8个字节,可用于保存标识信息1-标识信息20的数据,每种标识信息所占的bit位最小为1,最大为8,值为1和0的有限种组合。Fig. 3 is the schematic diagram of the frame message type that the present invention provides, and in the embodiment shown in Fig. 3, frame type corresponds to 1 byte, and the bit number that comprises is 8, and the frame data length is assumed to be 8 bytes, can be used for Save the data of identification information 1-identification information 20, the minimum bit occupied by each type of identification information is 1, the maximum is 8, and the value is a limited number of combinations of 1 and 0.
根据本发明提供的一种报文解析方法,通过帧消息在报文数据中的位置信息和每条消息的数据长度获取每条帧消息的,并将添加至每条帧消息的帧类型对应的结构中,组成新的值的字典结构;这种通过提取帧消息的与原帧消息组成新的数据结构以实现对报文数据解析,提高了对多种不通类型的报文数据解析和存储的效率。According to a message parsing method provided by the present invention, each frame message is obtained through the position information of the frame message in the message data and the data length of each message, and is added to the frame type corresponding to each frame message In the structure, a dictionary structure of new values is formed; this kind of new data structure is formed by extracting the frame message and the original frame message to realize the parsing of the message data, which improves the parsing and storage of various different types of message data efficiency.
在一些实施例中,帧消息包括帧头和帧数据,标识信息包括标识序号和标识值,每个标识序号对应多个标识值;基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,包括:以帧头的位置为起始位置,将多个标识序号依次填充至帧数据对应的数据结构,得到帧消息的外层key数据;基于帧消息解析表确定多个标识序号对应的目标标识值,目标标识值为多个标识值中的一项;基于外层key数据和目标标识值,得到帧消息对应的key-value数据。In some embodiments, the frame message includes a frame header and frame data, and the identification information includes an identification number and an identification value, and each identification number corresponds to multiple identification values; the frame message is parsed based on a preset frame message analysis table to obtain a frame The key-value data corresponding to the message includes: taking the position of the frame header as the starting position, filling multiple identification serial numbers into the data structure corresponding to the frame data in sequence to obtain the outer key data of the frame message; determined based on the frame message parsing table Target identification values corresponding to multiple identification serial numbers, the target identification value is one of the multiple identification values; based on the outer key data and the target identification value, the key-value data corresponding to the frame message is obtained.
在该实施例中,报文数据中的每条帧消息按数据长度可以设置多个标识信息,每个标识信息包括标识序号和多个标识值,例如,帧消息的一个标识信息可以设置为“标识信息1,值1:0001,值2:0010,值3:0011”。In this embodiment, each frame message in the message data can be provided with a plurality of identification information according to the data length, and each identification information includes an identification sequence number and a plurality of identification values. For example, one identification information of a frame message can be set as "
在该实施例中,目标标识值为每个标识信息中包含多个标识值中的一个,例如,上述帧消息的目标标识值为2(对应0010)。In this embodiment, the target identification value includes one of multiple identification values in each identification information, for example, the target identification value of the above frame message is 2 (corresponding to 0010).
在该实施例中,当Client1接收到来自Server2的一份报文数据后,首先识别报文头为TYPE2时,开始进行报文解析,依次解析帧1消息、帧2消息、帧3消息…,解析每帧消息前,会先进行帧消息类型校验,通过目标标识与类型的组合,判断目标标识是否为Client1,帧类型是否为所需解析的类型;帧类型校验通过后,根据帧消息解析规则,开始按每个帧消息的比特起始位和所占比特位数进行解析,帧消息解析规则如下:In this embodiment, after Client1 receives a piece of message data from Server2, it first recognizes that the message header is TYPE2, and starts message parsing, and then parses
"目标标识":{"start":0,"length":8},"Target ID":{"start":0,"length":8},
"源":{"start":8,"length":8},"source":{"start":8,"length":8},
"类型":{"start":16,"length":8},"type":{"start":16,"length":8},
"长度":{"start":24,"length":8},"length":{"start":24,"length":8},
"0xE001":{"标识信息1":{"start":32,"length":4},"0xE001":{"
"标识信息2":{"start":36,"length":4},"
"标识信息3":{"start":40,"length":2},"Identification information 3":{"start":40,"length":2},
"标识信息4":{"start":42,"length":2}},"Identification information 4":{"start":42,"length":2}},
"0xE002":{"标识信息1":{"start":32,"length":2},"0xE002":{"
"标识信息2":{"start":34,"length":4},"
"标识信息3":{"start":38,"length":4},"Identification information 3":{"start":38,"length":4},
"标识信息4":{"start":42,"length":2。"Identification information 4":{"start":42,"length":2.
其中,start表示起始bit位,length表示所占bit位数,“目标标识”处在帧头第一个字节,占8个bit位,则对应的start记为0,length为8;“源”处在帧头第二个字节,占8个bit位,对应的start为8,length为8;“类型”处在帧头第三个字节,占8个bit位,对应的start为16,length为8;“长度”处在帧头第四个字节,占8个bit位,对应的start为24,length为8;帧数据从第五个字节开始,对应的标识信息1的start为32,length由标识信息1所占的bit位数决定,其他标识信息的start由该标识信息所处的bit位决定,标识信息n的start等于标识信息n-1的start加标识信息n-1的length。Among them, start indicates the starting bit, length indicates the number of bits occupied, and the "target identification" is in the first byte of the frame header, occupying 8 bits, then the corresponding start is recorded as 0, and the length is 8; " Source" is in the second byte of the frame header, occupying 8 bits, corresponding to start is 8, and length is 8; "type" is in the third byte of the frame header, occupying 8 bits, corresponding to start is 16, and length is 8; "length" is in the fourth byte of the frame header, which occupies 8 bits, and the corresponding start is 24, and the length is 8; the frame data starts from the fifth byte, and the corresponding identification information The start of 1 is 32, the length is determined by the number of bits occupied by the
根据本发明提供的一种报文解析方法,通过预设的帧消息解析表确定的报文数据中每个帧消息的解析方式,以获取帧消息的key-value数据,这种解析方式可扩展性强,若需要增加新的报文类型、帧消息、标识信息,直接通过修改帧消息解析表来修改帧消息解析规则即,减少程序开发量。According to a message analysis method provided by the present invention, the analysis method of each frame message in the message data determined by the preset frame message analysis table is used to obtain the key-value data of the frame message. This analysis method can be extended Strong performance, if you need to add new message types, frame messages, and identification information, directly modify the frame message parsing rules by modifying the frame message parsing table, that is, reduce the amount of program development.
在一些实施例中,将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构,包括:将每个帧消息对应的key-value数据分别存储在帧消息的帧类型结构,得到字典数据结构。In some embodiments, the key-value data corresponding to the frame message is stored in the message data to obtain a dictionary data structure, including: storing the key-value data corresponding to each frame message in the frame type structure of the frame message, Get the dictionary data structure.
在该实施例中,帧消息的帧类型结构用于指示帧消息的类别信息。In this embodiment, the frame type structure of the frame message is used to indicate the type information of the frame message.
在该实施例中,将每个帧消息对应的key-value数据分别存储在帧消息的帧类型结构中,构成新的数据结构。In this embodiment, the key-value data corresponding to each frame message is respectively stored in the frame type structure of the frame message to form a new data structure.
图4是本发明提供的报文解析方法的流程示意图之二,在图4所示的实施例中,客户接收端(对应Client1)接收服务端集群发送的报文,先确定该报文类型(对应TYPE2)为待解析类型,具体为根据报文数据中的n个帧消息的内容,分别校验各帧消息包含的目标标识与Client1类型是否匹配,帧类型与预设的类型是否相同,在目标标识与Client1类型匹配,且帧类型与预设的类型相同的情况下,对每个帧消息进行解析,分别得到获取每个帧类型和对应的key-value数据(对应帧1,…n类型+标识信息:值)构成的新的数据结构,即以key-value数据(标识信息:值)与帧消息类型构成值的字典数据,得到更新后的报文数据。Fig. 4 is the second schematic flow diagram of the message parsing method provided by the present invention. In the embodiment shown in Fig. 4, the client receiving end (corresponding to Client1) receives the message sent by the server cluster, and first determines the message type ( Corresponding to TYPE2) is the type to be parsed. Specifically, according to the content of the n frame messages in the message data, check whether the target identifier contained in each frame message matches the Client1 type, and whether the frame type is the same as the preset type. When the target ID matches the Client1 type, and the frame type is the same as the preset type, each frame message is parsed to obtain each frame type and corresponding key-value data (corresponding to frame 1,...n type + new data structure composed of identification information: value), that is, dictionary data composed of key-value data (identification information: value) and frame message type to obtain updated message data.
根据本发明提供的一种报文解析方法,通过提取报文数据中帧消息的key-value,并与帧消息对应的帧类型共同构成新的结构数据,帧消息的解析方式便捷高效,便于后续应用的开发和调试。According to a message analysis method provided by the present invention, by extracting the key-value of the frame message in the message data, and forming new structural data together with the frame type corresponding to the frame message, the analysis method of the frame message is convenient and efficient, and is convenient for follow-up Application development and debugging.
在一些实施例中,待解析的报文数据包括多个,确定待解析的报文数据,包括:确定目标报文数据,目标报文数据为多个待解析的报文数据中的一项。In some embodiments, the packet data to be parsed includes multiple packets, and determining the packet data to be parsed includes: determining target packet data, where the target packet data is one of the multiple packet data to be parsed.
可以理解的是,不同类型的客户端或服务器产生的UDP报文数据也包括多种,每种报文包含多种类型消息的数据,在对报文数据进行解析之前,需要完成确定待解析的报文数据的类型。It can be understood that the UDP message data generated by different types of clients or servers also includes multiple types, and each message contains data of multiple types of messages. Before analyzing the message data, it is necessary to complete the determination of the data to be analyzed The type of message data.
在该实施例中,Client1能够同时接收Server2和Server3发送的UDP报文,Server2的报文数据类型为TYPE2,Server3的报文类型为TYPE3,Client1识别出报文头包含TYPE2的类型信息后,对TYPE2对应的报文数据中的帧消息进行解析。In this embodiment, Client1 can receive the UDP message that Server2 and Server3 send at the same time, and the message data type of Server2 is TYPE2, and the message type of Server3 is TYPE3, and after Client1 recognizes that message head contains the type information of TYPE2, to The frame message in the message data corresponding to TYPE2 is parsed.
根据本发明提供的一种报文解析方法,通过对报文数据的类型进行校验便于对各类型给的报文数据进行归类,提高了对多种类型的报文数据的解析效率。According to the message analysis method provided by the present invention, by checking the type of message data, it is convenient to classify the message data of various types, and the analysis efficiency of various types of message data is improved.
在一些实施例中,标识值包括数字、字母或数字和字母的组合中的至少一项。In some embodiments, the identification value includes at least one of numbers, letters, or a combination of numbers and letters.
在该实施例中,每个帧消息对应的标识信息可以包括多个标识序号,每个标识序号对应多个标识值,为了区分不同帧消息的类型,标识值的内容可以根据用户实际需求自定义设定。In this embodiment, the identification information corresponding to each frame message may include multiple identification numbers, and each identification number corresponds to multiple identification values. In order to distinguish the types of different frame messages, the content of the identification value can be customized according to the actual needs of users set up.
可选的,一个标识序号下的标识值可以为数字或字符串类型的值,例如,标识值可以是1、hello等。Optionally, the identification value under an identification number can be a value of number or string type, for example, the identification value can be 1, hello, etc.
根据本发明提供的一种报文解析方法,通过对帧消息设置多种类型的标识值,便于区分不同帧消息的类型,提高报文解析的准确率。According to the message analysis method provided by the present invention, by setting multiple types of identification values for frame messages, it is convenient to distinguish the types of different frame messages and improve the accuracy of message analysis.
在一些实施例中,在得到报文数据的字典数据结构之后,该方法还包括:将字典数据结构存储于消息队列对应的数据集群。In some embodiments, after obtaining the dictionary data structure of the message data, the method further includes: storing the dictionary data structure in a data cluster corresponding to the message queue.
在该实施例中,将字典数据结构存储在消息队列中,可以通过消息队列管理工具直接分析或修改数据,相比分析原始UDP报文更加直观,效率更高,更便于上层应用开发、调试使用。In this embodiment, the dictionary data structure is stored in the message queue, and the data can be directly analyzed or modified through the message queue management tool, which is more intuitive and efficient than analyzing the original UDP message, and is more convenient for upper-layer application development and debugging. .
在图4所示的实施例中,获取帧消息标识信息和值的字典数据后,将该字典数据存储于消息队列。In the embodiment shown in FIG. 4, after acquiring the dictionary data of frame message identification information and values, the dictionary data is stored in the message queue.
根据本发明提供的一种报文解析方法,通过使用值字典数据结构供上层应用开发、调试,提高了对发送数据集群的管理效率。According to the message parsing method provided by the present invention, the management efficiency of the sending data cluster is improved by using the value dictionary data structure for upper layer application development and debugging.
下面对本发明提供的报文解析装置进行描述,下文描述的报文解析装置与上文描述的报文解析方法可相互对应参照。The message parsing device provided by the present invention is described below, and the message parsing device described below and the message parsing method described above may refer to each other correspondingly.
图5是本发明提供的报文解析装置的结构示意图,如图5所示,本发明还提供一种报文解析装置,包括确认模块510、第一处理模块520和第二处理模块530。FIG. 5 is a schematic structural diagram of a message parsing device provided by the present invention. As shown in FIG. 5 , the present invention also provides a message parsing device, including a
确认模块510,用于在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,待解析的报文数据包括多个帧消息;A
第一处理模块520,用于基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,帧消息解析表包括多个有序排列的标识信息,多个有序排列的标识信息的数量基于帧消息的数据长度确定,多个有序排列的标识信息用于指示帧数据的类别;The
第二处理模块530,用于将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构。The
根据本发明提供的一种报文解析装置,通过帧消息在报文数据中的位置信息和每条消息的数据长度获取每条帧消息的key-value数据,并将key-value数据添加至每条帧消息的帧类型对应的结构中,组成新的值的字典结构;这种通过提取帧消息的key-value数据与帧消息的帧类型组成新的数据结构,提高了对多种不通类型的报文数据解析、归类和存储的效率。According to a message parsing device provided by the present invention, the key-value data of each frame message is obtained through the position information of the frame message in the message data and the data length of each message, and the key-value data is added to each In the structure corresponding to the frame type of the frame message, a dictionary structure of a new value is formed; this kind of new data structure is formed by extracting the key-value data of the frame message and the frame type of the frame message, which improves the compatibility of various types of incompatibility. The efficiency of message data parsing, classification and storage.
根据本发明提供的一种报文解析装置,装置还包括:According to a message parsing device provided by the present invention, the device also includes:
第三处理模块,用于在得到报文数据的字典数据结构之后,将字典数据结构存储于消息队列对应的数据集群。The third processing module is configured to store the dictionary data structure in the data cluster corresponding to the message queue after obtaining the dictionary data structure of the message data.
根据本发明提供的一种报文解析装置,通过使用值字典数据结构供上层应用开发、调试,提高了对发送数据集群的管理效率。According to the message parsing device provided by the present invention, the management efficiency of the sending data cluster is improved by using the value dictionary data structure for upper layer application development and debugging.
图6示例了一种电子设备的实体结构示意图,如图6所示,该电子设备可以包括:处理器(processor)610、通信接口(Communications Interface)620、存储器(memory)630和通信总线640,其中,处理器610,通信接口620,存储器630通过通信总线640完成相互间的通信。处理器610可以调用存储器630中的逻辑指令,以执行报文解析方法,该方法包括:在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,待解析的报文数据包括多个帧消息;基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,帧消息解析表包括多个有序排列的标识信息,多个有序排列的标识信息的数量基于帧消息的数据长度确定,多个有序排列的标识信息用于指示帧数据的类别;将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构。FIG. 6 illustrates a schematic diagram of the physical structure of an electronic device. As shown in FIG. 6, the electronic device may include: a processor (processor) 610, a communication interface (Communications Interface) 620, a memory (memory) 630 and a
此外,上述的存储器630中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the logic instructions in the above-mentioned
另一方面,本发明还提供一种计算机程序产品,所述计算机程序产品包括计算机程序,计算机程序可存储在非暂态计算机可读存储介质上,所述计算机程序被处理器执行时,计算机能够执行上述各方法所提供的报文解析方法,该方法包括:在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,待解析的报文数据包括多个帧消息;基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,帧消息解析表包括多个有序排列的标识信息,多个有序排列的标识信息的数量基于帧消息的数据长度确定,多个有序排列的标识信息用于指示帧数据的类别;将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构。On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can Executing the message parsing method provided by each of the above methods, the method includes: when multiple clients communicate with multiple servers, determine the message data to be parsed, the message data to be parsed includes multiple frames Message; based on the preset frame message analysis table, the frame message is analyzed to obtain the key-value data corresponding to the frame message. The frame message analysis table includes a plurality of orderly arranged identification information, and the number of orderly arranged identification information Based on the determination of the data length of the frame message, a plurality of sequentially arranged identification information is used to indicate the category of the frame data; the key-value data corresponding to the frame message is stored in the message data to obtain a dictionary data structure.
又一方面,本发明还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现以执行上述各方法提供的报文解析方法,该方法包括:在多个客户端与多个服务端进行报文通信时,确定待解析的报文数据,待解析的报文数据包括多个帧消息;基于预设的帧消息解析表对帧消息进行解析,得到帧消息对应的key-value数据,帧消息解析表包括多个有序排列的标识信息,多个有序排列的标识信息的数量基于帧消息的数据长度确定,多个有序排列的标识信息用于指示帧数据的类别;将帧消息对应的key-value数据存储在报文数据中,得到字典数据结构。In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it is implemented to execute the message parsing method provided by the above-mentioned methods, the method includes : When multiple clients communicate with multiple servers, determine the message data to be parsed, the message data to be parsed includes multiple frame messages; parse the frame messages based on the preset frame message parsing table , to obtain the key-value data corresponding to the frame message, the frame message parsing table includes a plurality of orderly arranged identification information, the number of the orderly arranged identification information is determined based on the data length of the frame message, and the multiple orderly arranged identification information The information is used to indicate the category of the frame data; the key-value data corresponding to the frame message is stored in the message data to obtain a dictionary data structure.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. It can be understood and implemented by those skilled in the art without any creative efforts.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the above description of the implementations, those skilled in the art can clearly understand that each implementation can be implemented by means of software plus a necessary general hardware platform, and of course also by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or equivalent replacements are made to some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211457115.4A CN115801927B (en) | 2022-11-16 | 2022-11-16 | Message parsing method and device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211457115.4A CN115801927B (en) | 2022-11-16 | 2022-11-16 | Message parsing method and device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN115801927A true CN115801927A (en) | 2023-03-14 |
| CN115801927B CN115801927B (en) | 2025-11-28 |
Family
ID=85439440
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202211457115.4A Active CN115801927B (en) | 2022-11-16 | 2022-11-16 | Message parsing method and device |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN115801927B (en) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116634042A (en) * | 2023-05-23 | 2023-08-22 | 成都赛力斯科技有限公司 | Big data message analysis method, device and storage medium |
| CN117319529A (en) * | 2023-11-29 | 2023-12-29 | 成都赛力斯科技有限公司 | Message analysis method and device applied to vehicle end, electronic equipment and storage medium |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5276616A (en) * | 1989-10-16 | 1994-01-04 | Sharp Kabushiki Kaisha | Apparatus for automatically generating index |
| CN108243168A (en) * | 2016-12-27 | 2018-07-03 | 比亚迪股份有限公司 | Method and device for message parsing and grouping, and message processing system |
| CN108881172A (en) * | 2018-05-22 | 2018-11-23 | 阿里巴巴集团控股有限公司 | The analysis method and device of message |
| CN110012002A (en) * | 2019-03-29 | 2019-07-12 | 深圳智链物联科技有限公司 | Message parsing method, device and server, computer readable storage medium |
| CN110750442A (en) * | 2019-09-06 | 2020-02-04 | 平安医疗健康管理股份有限公司 | Test case generation method, device, equipment and storage medium |
| CN114827290A (en) * | 2021-01-22 | 2022-07-29 | 北京汽车股份有限公司 | Message forwarding method and device, vehicle-mounted network system and readable storage medium |
| CN115334177A (en) * | 2022-07-07 | 2022-11-11 | 浙江众合科技股份有限公司 | Binary data message analysis method based on xml configuration file recursion |
-
2022
- 2022-11-16 CN CN202211457115.4A patent/CN115801927B/en active Active
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5276616A (en) * | 1989-10-16 | 1994-01-04 | Sharp Kabushiki Kaisha | Apparatus for automatically generating index |
| CN108243168A (en) * | 2016-12-27 | 2018-07-03 | 比亚迪股份有限公司 | Method and device for message parsing and grouping, and message processing system |
| CN108881172A (en) * | 2018-05-22 | 2018-11-23 | 阿里巴巴集团控股有限公司 | The analysis method and device of message |
| CN110012002A (en) * | 2019-03-29 | 2019-07-12 | 深圳智链物联科技有限公司 | Message parsing method, device and server, computer readable storage medium |
| CN110750442A (en) * | 2019-09-06 | 2020-02-04 | 平安医疗健康管理股份有限公司 | Test case generation method, device, equipment and storage medium |
| CN114827290A (en) * | 2021-01-22 | 2022-07-29 | 北京汽车股份有限公司 | Message forwarding method and device, vehicle-mounted network system and readable storage medium |
| CN115334177A (en) * | 2022-07-07 | 2022-11-11 | 浙江众合科技股份有限公司 | Binary data message analysis method based on xml configuration file recursion |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116634042A (en) * | 2023-05-23 | 2023-08-22 | 成都赛力斯科技有限公司 | Big data message analysis method, device and storage medium |
| CN116634042B (en) * | 2023-05-23 | 2025-12-16 | 重庆赛力斯凤凰智创科技有限公司 | Big data message analysis method, device and storage medium |
| CN117319529A (en) * | 2023-11-29 | 2023-12-29 | 成都赛力斯科技有限公司 | Message analysis method and device applied to vehicle end, electronic equipment and storage medium |
| CN117319529B (en) * | 2023-11-29 | 2024-02-02 | 成都赛力斯科技有限公司 | Message analysis method and device applied to vehicle end, electronic equipment and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN115801927B (en) | 2025-11-28 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111211980B (en) | Transmission link management method, transmission link management device, electronic equipment and storage medium | |
| CN103916294B (en) | The recognition methods of protocol type and device | |
| WO2022088779A1 (en) | Deep packet processing method and apparatus, electronic device, and storage medium | |
| CN114157502B (en) | Terminal identification method and device, electronic equipment and storage medium | |
| CN104144156B (en) | Message processing method and device | |
| CN111782140A (en) | Network data packet storage method and device, computer equipment and storage medium | |
| US9092319B2 (en) | State memory management, wherein state memory is managed by dividing state memory into portions each portion assigned for storing state information associated with a specific message class | |
| CN103647869B (en) | A kind of matching method of terminal, terminal and system | |
| CN110460488B (en) | Service flow identification method and device, and model generation method and device | |
| WO2012171166A1 (en) | Method and apparatus for protocol parsing | |
| US20060104278A1 (en) | Apparatus and method for compressing headers in a broadband wireless communication system | |
| CN102932285B (en) | Message encapsulating method, analytic method and device | |
| CN115801927A (en) | Message parsing method and device | |
| CN111371887B (en) | Internet of things log transmission method, client, server, equipment and storage medium | |
| CN112751833A (en) | RTP message identification method and device, electronic equipment and readable storage medium | |
| CN114979094A (en) | Data transmission method, device, equipment and medium based on RTP | |
| CN112019393A (en) | A method and device for determining time delay | |
| CN111277449A (en) | Security testing method and device for voice service equipment | |
| CN116233317A (en) | Real-time VoLTE voice restoration and detection method and device for network traffic | |
| CN114422624B (en) | Data receiving method | |
| CN114579490B (en) | Data transmission method and device, electronic equipment and storage medium | |
| CN113992364B (en) | Network data packet blocking optimization method and system | |
| CN102938733A (en) | Message forwarding method as well as routing equipment and recognition equipment thereof | |
| CN115766914A (en) | Message transmission method, device and system and electronic equipment | |
| CN119211150B (en) | Message forwarding method, network card, gateway device, storage medium and program |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |