Message analysis method, electronic device, and readable storage medium

By obtaining the remaining parsing length and data parsing parameters of the message to be parsed, the moving cursor parses the non-contiguous buffer segments, which solves the problem of low message parsing efficiency in the existing technology and realizes the rapid location and parsing of target data in non-contiguous buffer segments.

CN116980501BActive Publication Date: 2026-05-26PENG CHENG LAB
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
PENG CHENG LAB
Filing Date
2023-07-25
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

In existing technologies, the parsing efficiency of jumbo frames is low, mainly because it is difficult to locate the accurate location of the stored message data in the non-contiguous buffer segments, resulting in the repeated writing of parsing code.

Method used

By obtaining the remaining parsing length of the message to be parsed, checking whether the message header length is less than the remaining parsing length, obtaining the data parsing parameters of the current cursor's buffer segment, and moving the cursor within the message to be parsed to parse the target data, fast location and parsing of non-contiguous buffer segments can be achieved.

Benefits of technology

It improves the efficiency of message parsing, avoids repeatedly writing parsing code, and quickly locates and parses target data in non-contiguous cache segments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116980501B_ABST
    Figure CN116980501B_ABST
Patent Text Reader

Abstract

This application discloses a message parsing method, an electronic device, and a readable storage medium. The message parsing method includes: obtaining the remaining parsing length of the message to be parsed; if it is detected that the header length of the message to be parsed is less than the remaining parsing length, obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located; parsing the target data of the buffer segment where the current cursor is located according to the data parsing parameters, and parsing the message to be parsed by moving the current cursor within the message to be parsed to obtain the message parsing result. This application solves the technical problem of low parsing efficiency in message parsing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a message parsing method, electronic device, and readable storage medium. Background Technology

[0002] When performing high-throughput data exchange such as file transfer or video message transmission, it is usually transmitted through jumbo frames with a payload of more than 1,500 bytes. However, when the system needs to support both jumbo frames and non-jambo frames, parsing the messages transmitted by jumbo frames becomes an urgent problem to be solved.

[0003] Currently, due to memory cost considerations, contiguous memory is not typically allocated for caching jumbo frames. Therefore, parsing packets usually requires parsing data packets stored in multiple non-contiguous buffer segments. However, since it is difficult to locate the exact location of the stored packet data in non-contiguous buffer segments, it is easy to repeatedly write parsing code to parse packets. As a result, the parsing efficiency of current packet parsing is low. Summary of the Invention

[0004] The main objective of this application is to provide a message parsing method, electronic device, and readable storage medium, aiming to solve the technical problem of low parsing efficiency in the prior art.

[0005] To achieve the above objectives, this application provides a message parsing method, the message parsing method comprising:

[0006] Get the remaining parsing length of the message to be parsed;

[0007] If the header length of the message to be parsed is detected to be less than the remaining parsing length, then the data parsing parameters of the current cursor of the message to be parsed are obtained.

[0008] Based on the data parsing parameters, the target data in the buffer segment where the current cursor is located is parsed, and the message to be parsed is parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0009] To achieve the above objectives, this application also provides a message parsing apparatus, the message parsing apparatus comprising:

[0010] The acquisition module is used to obtain the remaining parsing length of the message to be parsed;

[0011] The detection module is used to obtain the data parsing parameters of the current cursor cache segment of the message to be parsed if the message header length of the message to be parsed is less than the remaining parsing length.

[0012] The parsing module is used to parse the target data in the buffer segment where the current cursor is located according to the data parsing parameters, and to parse the message to be parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0013] This application also provides an electronic device, the electronic device comprising: at least one processor and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the steps of the message parsing method described above.

[0014] This application also provides a computer-readable storage medium storing a program implementing a message parsing method, wherein when the program is executed by a processor, it implements the steps of the message parsing method as described above.

[0015] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the message parsing method described above.

[0016] This application provides a message parsing method, electronic device, and readable storage medium. Specifically, it obtains the remaining parsing length of the message to be parsed; if it is detected that the header length of the message to be parsed is less than the remaining parsing length, it obtains the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located; according to the data parsing parameters, it parses the target data of the buffer segment where the cursor is located, and parses the message to be parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0017] When parsing a message to be parsed, this application can obtain the remaining parsing length of the message to be parsed and detect whether the message header length is less than the remaining parsing length. If the message header length is found to be less than the remaining parsing length, that is, there is still a data area in the message to be parsed that needs to be parsed, the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located are obtained. Based on the data parsing parameters, the target data of the buffer segment where the current cursor is located is directly parsed. By moving the current cursor within the message to be parsed, the data of each buffer segment of the message to be parsed can be parsed, and the message parsing result can be obtained. Thus, the purpose of quickly locating a certain buffer segment of multiple non-contiguous buffer segments of the message to be parsed by the movable cursor of the message to be parsed and parsing the target data cached on that buffer segment can be achieved.

[0018] Since the current cursor can move within the message to be parsed, in parsing the message to be parsed, it is only necessary to traverse and move the current cursor to each cache segment of the message to be parsed, that is, to quickly locate the cache segment of the target data of the message to be parsed, and then to parse the target data cached on that cache segment. Therefore, the purpose of quickly parsing the message to be parsed that is cached in non-contiguous cache segments is achieved.

[0019] Based on this, this application locates the data region to be parsed within the message to be parsed using the current cursor, and then parses the data region according to the data parsing parameters. Furthermore, by moving the current cursor arbitrarily within the message to be parsed, all data requiring parsing within the message can be parsed; that is, the data region to be parsed is precisely located using the current cursor, rather than repeatedly writing parsing code to locate the data stored in non-contiguous buffer segments. Therefore, it overcomes the technical defect that makes it difficult to locate the accurate location of message data in non-contiguous buffer segments, leading to the tendency to repeatedly write parsing code for message parsing, thus improving the parsing efficiency. Attached Figure Description

[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 A flowchart illustrating the message parsing method provided in Embodiment 1 of this application;

[0023] Figure 2 A schematic diagram of the structure of the message to be parsed in the message parsing method provided in Embodiment 1 of this application;

[0024] Figure 3 A schematic diagram of the cached data access class interface of the message parsing method provided in Embodiment 1 of this application;

[0025] Figure 4 A schematic diagram illustrating the composition of the cursor in the message parsing method provided in Embodiment 1 of this application;

[0026] Figure 5 A schematic diagram of the data packet structure for the message parsing method provided in Embodiment 1 of this application.

[0027] Figure 6A schematic diagram of the cursor movement class interface for the message parsing method provided in Embodiment 1 of this application;

[0028] Figure 7 A flowchart illustrating the message parsing method provided in Embodiment 2 of this application;

[0029] Figure 8 A schematic diagram of the message truncation class interface for the message parsing method provided in Embodiment 2 of this application;

[0030] Figure 9 This is a schematic diagram of the message parsing device provided in Embodiment 3 of this application;

[0031] Figure 10 This is a schematic diagram of the structure of the electronic device provided in Embodiment 4 of this application.

[0032] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0033] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0034] Example 1

[0035] First, it should be understood that, under normal circumstances, when a system needs to support both jumbo frames and non-jambo frames, due to memory cost considerations, the system cannot allocate a contiguous block of memory to store jumbo frames. If it is necessary to quickly parse or access the specific content of the data packets stored in non-contiguous memory, it will result in additional runtime overhead and memory copying. Without using the above methods, the packet parsing process will result in an excessively long parsing cycle due to the difficulty in accurately locating data in non-contiguous memory. Therefore, there is an urgent need for a method to improve the parsing efficiency of packet parsing.

[0036] This application provides a message parsing method. In the first embodiment of the message parsing method of this application, refer to... Figure 1 The message parsing method includes:

[0037] Step S10: Obtain the remaining parsing length of the message to be parsed;

[0038] Step S20: If it is detected that the header length of the message to be parsed is less than the remaining parsing length, then obtain the data parsing parameters of the current cursor of the message to be parsed in the buffer segment.

[0039] Step S30: Based on the data parsing parameters, parse the target data in the buffer segment where the current cursor is located, and parse the message to be parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0040] In this embodiment, it should be noted that, although Figure 1 The logical order is shown, but in some cases, the steps shown or described may be performed in a different order than that shown here. The message parsing method is applied to a message parsing device deployed with a communication system supporting jumbo frame transmission, such as a high-speed base station system or a high-speed core network system for mobile communication. These high-speed base station systems or high-speed core network systems typically utilize kernel bypass technology and the DPDK (Data Plane Development Kit) library to process message data in user space. For example, in the DPDK library, refer to... Figure 1 , Figure 1 To illustrate the storage of jumbo frames in a memory buffer, multiple storage data blocks such as A1, A2, and An are allocated for the jumbo frame. For any storage data block, its NEXT pointer points to the next storage data block. This process proceeds from the outside in, sequentially constructing the Ethernet header, then the IP header, then the UDP header, and finally filling in the internal payload message. After processing, the total length of the message and the fields within the checksum are calculated. However, because the messages obtained by this processing method are distributed across non-contiguous memory, subsequent message parsing is not as simple as for messages in contiguous memory. Therefore, this embodiment of the application abstracts a cache segment for storing message data and a cursor pointing to a byte index value in the cache segment. The shape characteristics of the cache segment are not restricted, and the cursor can move freely back and forth on the cache segment. Since the message consists of multiple non-contiguous cache segments, any byte of the message data can be located by moving the cursor, that is, the cursor can point to bytes in each cache segment.

[0041] Additionally, it should be noted that the message to be parsed is used to represent a message waiting to be parsed. Specifically, the message to be parsed can consist of a header and a data area. The header can be determined by the Ethernet communication protocol, which can be TCP / IP (Transmission Control Protocol / Internet Protocol), UDP (User Datagram Protocol), or ICMP (Internet Control Message Protocol). The Internet Control Message Protocol (ICP-35) stores the message to be parsed in multiple non-contiguous buffer segments with a cursor before parsing. The remaining parsing length represents the remaining length of data waiting to be parsed. Since the cursor moves, and parsing of the message can proceed either from the outside in (from front to back) or from the inside out (from back to front), the remaining parsing length for a given time step is determined by the byte pointed to by the cursor at the current time step and the first byte that has already been parsed. Specifically, it can be the total length of bytes from the byte pointed to by the cursor to the last byte of the message to be parsed, or the total length of bytes from the byte pointed to by the cursor to the first byte of the message to be parsed. (See reference...) Figure 2 , Figure 2 To illustrate the structure of the message to be parsed, X represents the message to be parsed, and B1, B2, and B3 represent different non-contiguous buffer segments. For a certain buffer segment 10, the byte pointed to by the cursor P divides the buffer segment into two main areas: the accessible buffer segment header space 11 and the accessible buffer segment space 12. The accessible buffer segment space contains the byte pointed to by the cursor of the buffer segment and all bytes after the cursor. The accessible buffer segment header space contains all bytes before the cursor of the buffer segment. If the message to be parsed is parsed from the outside in, then d1 represents the remaining parsing length, that is, the total length of bytes from the byte pointed to by the current cursor to the end byte of the message to be parsed.

[0042] Additionally, it should be noted that since the message to be parsed carries a header, and the header does not contain actual user or business data, during the parsing process, after parsing each segment of data, it is necessary to check the length relationship between the remaining parsing length and the header length. If the header of the message to be parsed is greater than or equal to the remaining parsing length, it indicates that there is no more data to be parsed in the message, that is, the message to be parsed has been completed. If the header of the message to be parsed is less than the remaining parsing length, the data parsing parameters are obtained through the corresponding cached data access interface. The data parsing parameters are used to parse the message data, specifically the cursor address and the length of the accessible cache segment space. The cached data access interface includes a read-only accessible cache segment access interface (API_chunk) and a read-write accessible cache segment access interface (API_chunk_mut). Neither has input parameters, and the returned data parsing parameters are used to parse the target data, that is, the message data cached in the cache segment. Figure 3 , Figure 3 This diagram illustrates the interface for accessing cached data. The shaded area represents the target data. If the read-only access cache segment interface is used, only the target data can be read. If the read-write access cache segment interface is used, both the target data and the cached data can be read and written.

[0043] Additionally, it should be noted that the cursor is used to represent the index value pointing to the byte of the message to be parsed. Specifically, it can be composed of the buffer segment start address (buf_addr), buffer segment length (buf_len), accessible buffer segment start address (chunk_addr), and accessible buffer segment length (chunk_len). The buffer segment start address is a pointer pointing to the first address of the buffer segment; the buffer segment length is an integer representing the length of the buffer segment; the accessible buffer address is a pointer pointing to the byte where the cursor is located; and the accessible buffer segment length is an integer representing the length from the start of the cursor to the end of the buffer segment where the cursor is located. (Refer to...) Figure 4 , Figure 4 This is a schematic diagram illustrating the components of a vernier.

[0044] Additionally, it should be noted that, referring to Figure 5 , Figure 5To illustrate the structure of a data packet, the components of the data (message data packet) that need to be parsed include a descriptor header (head_PD), a current descriptor (cur_PD), a cumulative length of accessed buffer segments (segs_len), the starting address of accessible buffer segments (chunk_addr), and the length of accessible buffer segments (chunk_len). The length of accessible buffer segments is the length of the accessible buffer space. The descriptor header is a pointer to the descriptor (PD) of the first buffer segment storing the message, which can be used to traverse all buffer segments storing the message. The current descriptor is a pointer specifically pointing to the descriptor of the buffer segment where the cursor is located. The cumulative length of accessed buffer segments is an integer, specifically the sum of the lengths from the first buffer segment storing the message to the buffer segment where the cursor is located. The starting address of accessible buffer segments is an integer. The pointer represents the address of the byte where the cursor is located. The accessible buffer segment length is an integer representing the length from the cursor to the end of its buffer segment. The accessible buffer segment length and the cumulative length of the accessed buffer segments can be used to characterize the target data. For any buffer segment of a buffered message, it can be composed of the buffer address (buf_addr), buffer length (buf_len), total length (total_len), and next address (next_PD). ​​The buffer address is a pointer to the beginning address of the buffer segment. The buffer length is an integer representing the specific length of the buffer segment. The total length is an integer representing the total length of the message. Only the total length of the descriptor header has actual meaning; the total length of the other descriptors is meaningless. The next address is a pointer to the PD of the next buffer segment.

[0045] As an example, steps S10 to S30 include: obtaining the remaining length of the message to be parsed that is waiting to be parsed; if it is detected that the header length of the message to be parsed is less than the remaining length waiting to be parsed, then obtaining the address of the cursor of the current cursor in the buffer segment of the message to be parsed and the length of the accessible buffer segment space; parsing the target data of the buffer segment where the current cursor is located according to the address of the cursor and the length of the accessible buffer segment space, and parsing the message to be parsed by moving the current cursor within the message to be parsed to obtain the message parsing result.

[0046] In one feasible approach, if the header length of the message to be parsed is detected to be greater than or equal to the remaining parsing length, then the message parsing result is obtained, indicating that the message parsing is complete.

[0047] The message parsing result includes a first message parsing result and a second message parsing result. The step of parsing the message to be parsed by moving the current cursor within the message to be parsed to obtain the message parsing result includes:

[0048] Step A10: After the current cursor moves by the data length of the target data, detect whether the moved current cursor is located within the message to be parsed;

[0049] Step A20: If yes, then update the cursor parameters of the current cursor according to the data length to obtain the updated current cursor;

[0050] Step A30: Use the updated current cursor as the current cursor, and return to execute the step of obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located and subsequent steps, until the parsing result of the first message is obtained, wherein the parsing result of the first message is used to indicate that the parsing of the message to be parsed is complete;

[0051] Step A40: If not, then the parsing error information of the message to be parsed is taken as the result of the second message.

[0052] In this embodiment, it should be noted that when controlling the cursor to move within the message to be parsed, the cursor can be controlled to move with any data length. However, to ensure the effectiveness of data parsing with each cursor movement, and at the same time, to consider message parsing efficiency, the current cursor can always be moved with the data length of the target data to parse the remaining parsing length. Specifically, the movement can be forward or backward. After the movement, the cursor address can be used to detect whether the cursor is still within the message to be parsed. The message parsing result includes a first message parsing result and a second message parsing result. The first message parsing result indicates that the message to be parsed has been parsed, and the second message parsing result indicates that the message to be parsed has encountered an error. After the current cursor moves, it indicates that the parsing of the corresponding data has been completed. Therefore, for the current cursor that is still in a new position within the message to be parsed, the cursor parameters need to be updated.

[0053] As an example, steps A10 to A40 include: after the current cursor moves by the data length of the target data, detecting whether the moved current cursor is located within the message to be parsed; if the moved current cursor is detected to be located within the message to be parsed, updating the cursor parameters of the current cursor according to the data length to obtain the updated current cursor; using the updated current cursor as the current cursor, and returning to execute the step of obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located, and subsequent steps, until the first message parsing result is obtained; if the moved current cursor is detected not to be located within the message to be parsed, generating parsing error information for the message to be parsed, and using the parsing error information as the second message result, wherein the parsing error information can specifically be "message parsing error".

[0054] In this embodiment of the application, when parsing the message to be parsed, the current cursor carried in the message to be parsed is moved based on the data length of the target data. Then, it is detected whether the current cursor after the movement is within the message to be parsed. If the current cursor after the movement is not within the message to be parsed, the cursor parameters are updated first after the movement to locate the current position and state of the cursor. Then, the steps of obtaining data parsing parameters and parsing the target are repeated until all the data that needs to be parsed for the remaining parsing length is parsed. Finally, the first message parsing result of the message to be parsed is obtained. That is, parsing effectiveness and parsing efficiency are taken into account in the process of parsing the message to be parsed.

[0055] The cursor parameters include the cache segment identifier of the cache segment where the cursor is located, the cache space length of the cache segment where the cursor is located, and the byte address pointed to by the cursor in the cache segment. The step of updating the cursor parameters of the current cursor according to the data length to obtain the updated current cursor includes:

[0056] Step B10: If the current cursor is detected to be moving within the cache segment based on the data length, the updated current cursor is obtained by updating the cache space length and the byte address.

[0057] Step B20: If the current cursor is detected to be moving within the cache segment based on the data length, the updated current cursor is obtained by updating the cache space length and the byte address.

[0058] In this embodiment, it should be noted that the cache space length is used to characterize the space length of the accessible cache segment, and the cache segment identifier is used to characterize the description symbol of the cache segment. Due to the varying lengths of the target data and the limited space length of the accessible cache segment, the cursor may move between segments or within segments during the movement process. When moving within a segment, since the cache segment where the current cursor and the moved cursor are located do not change, there is no need to update the description symbol of the cache segment. When moving between segments, since the cache segment where the cursor is located changes, it is necessary to update the description symbol of the cache segment where the cursor is located. Controlling the movement of the current cursor can be implemented based on the cursor movement class interface. The cursor movement class interface includes the cursor forward movement interface API_advance and the cursor backward movement interface API_move_back. The input parameter of the cursor forward movement interface is the forward movement distance, and its function is to control the cursor to move forward a certain distance. The input parameter of the cursor backward movement interface is the backward movement distance, and its function is to control the cursor to move backward a certain distance. (Refer to...) Figure 6 , Figure 6To illustrate the cursor movement interface, the upper layer doesn't need to worry about whether the cursor moves within or between buffer segments. Determining whether the cursor moves within or between buffer segments can be done by measuring the movement range within the data length. The basic interfaces in the message parsing device also include buffer length query interfaces. These interfaces specifically include API_headroom and API_remaining. API_headroom has no input parameters and returns the length from the start address of the buffer segment where the cursor is located to the cursor's current location, and the total length in bytes from the start address of the buffer segment to the byte pointed to by the cursor within that buffer segment. API_remaining has no input parameters and returns the length from the end of the message to the cursor's current location, i.e., the total length in bytes from the byte pointed to by the cursor within the buffer segment to the byte at the end of the message.

[0059] As an example, steps B10 to B20 include: if the current cursor is detected to be moving within the cache segment based on the data length, then the updated current cursor is obtained by updating the cache space length and the byte address; if the current cursor is detected to be moving within the cache segment based on the data length, then the updated current cursor is obtained by updating the cache segment identifier, the cache segment space length, and the byte address.

[0060] Prior to the step of updating the cursor parameters of the current cursor based on the data length to obtain the updated current cursor, the message parsing method further includes:

[0061] Step C10: Obtain the first length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located; and obtain the second length difference between the parsing length of the cache segment and the cache segment length of the cache segment where the current cursor is located.

[0062] Step C20: Detect whether the second length difference is less than the third length difference between the first length difference and the data length;

[0063] Step C30: If the value is less than the specified value, then it is determined that the current cursor is moving within the current buffer segment.

[0064] As an example, steps C10 to C30 include: subtracting the cache segment parsing length of the message to be parsed from the cache space length of the cache segment where the current cursor is located to obtain a first length difference; and subtracting the cache segment parsing length from the cache segment length of the cache segment where the current cursor is located to obtain a second length difference. The cache segment length and cache space length can be obtained through a base class interface query. The cache segment parsing length is used to characterize the sum of the lengths of the cache segments already parsed within the message to be parsed. For example, in one implementable approach, assuming the message to be parsed is parsed from the outside in, the cache segment parsing length is the sum of the lengths from the first cache segment storing the message to the cache segment where the current cursor is located. The second length difference is detected to be less than a third length difference between the first length difference and the data length. If the second length difference is detected to be less than the third length difference, the current cursor is determined to move within the cache segment. If the second length difference is detected to be greater than or equal to the third length difference, the current cursor is determined to move between cache segments.

[0065] In one feasible approach, the process for detecting the cursor movement type (movement within or between buffer segments) during the current cursor shift is as follows: Input the shift length, calculate the lengths of the current cursor and the target cursor. The length of the current cursor is equal to `segs_len - chunk_len`, and the length of the target cursor is equal to the length of the current cursor minus the required shift length. Then, by checking if the length of the target cursor is less than 0, it is determined whether the current cursor, after the shift, is within the parsed message. If it is less than 0, an error is reported, indicating that the current cursor is not within the parsed message. If it is greater than 0, it is checked whether `segs_len - cur_PD`'s `buf_len` is less than the length of the target cursor (inclusive or inter-buf segment movement). (Determine whether the current cursor is moving forward within a cache segment or between cache segments). For different types of movement, different cursor parameters will be updated accordingly. That is, when moving between cache segments, segs_len will be updated to segs_len minus buf_len of cur_PD, and cur_PD will be set to point to the previous PD in the cache list. Then, the cursor parameters that will also be updated when moving within a cache segment will be updated. That is, chunk_len will be updated to segs_len minus the length of the target cursor, and chunk_addr will be updated to buf_addr of cur_PD plus buf_len of cur_PD minus chunk_len.

[0066] Prior to the step of updating the cursor parameters of the current cursor based on the data length to obtain the updated current cursor, the message parsing method further includes:

[0067] Step D10: Obtain the fourth length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located, and obtain the first length sum value between the fourth length difference and the data length;

[0068] Step D20: Detect whether the parsed length of the cache segment is greater than the first length and value;

[0069] Step D30: If the value is greater than the specified value, then it is determined that the current cursor is moving between the current cache segments.

[0070] Step D40: If it is less than or equal to, then determine that the current cursor has moved within the current buffer segment.

[0071] As an example, steps D10 to D40 include: subtracting the buffer segment parsing length of the message to be parsed from the buffer space length of the buffer segment where the current cursor is located to obtain a fourth length difference value; and summing the buffer segment parsing length and the data length to obtain a first length sum value; detecting whether the buffer segment parsing length is greater than the first length sum value; if the buffer segment parsing length is detected to be greater than the first length sum value, determining that the current cursor moves between the buffer segments; if the buffer segment parsing length is detected to be less than or equal to the first length sum value, determining that the current cursor moves within the current buffer segment.

[0072] In one feasible approach, the process for detecting the cursor movement type (movement within or between buffer segments) during the current cursor forward movement is as follows: Input the forward movement length; calculate the lengths of the current cursor and the target cursor. The length of the current cursor is equal to `segs_len` minus `chunk_len`, and the length of the target cursor is equal to the length of the current cursor plus the forward movement length. Then, by determining whether the length of the target cursor is greater than `head_PD_total_len`, it is determined whether the moved current cursor is within the parsed message. If the former is less than or greater than the latter, an error is reported, indicating that it is not within the parsed message. If the former is greater than the latter, it is determined whether `segs_len` is greater than the length of the target cursor (to determine whether the current cursor is moving forward within or between buffer segments). (Inter-cache segment shift) For different shift types, different cursor parameters will be updated accordingly. That is, when shifting between cache segments, segs_len will be updated to segs_len minus cur_PD's buf_len, and cur_PD will be set to point to the next PD in the cache list. Then, the cursor parameters that will also be updated when shifting within the cache segment will be updated. That is, chunk_len will be updated to segs_len minus the length of the target cursor, and chunk_addr will be updated to cur_PD's buf_addr plus cur_PD's buf_len minus chunk_len. Among these, forward shift parsing has a better foolproof effect than backward shift parsing because it is parsed from the outside in.

[0073] This application provides a message parsing method, namely, obtaining the remaining parsing length of the message to be parsed; if it is detected that the header length of the message to be parsed is less than the remaining parsing length, obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located; parsing the target data of the buffer segment where the cursor is located according to the data parsing parameters, and parsing the message to be parsed by moving the current cursor within the message to be parsed to obtain the message parsing result.

[0074] In this embodiment of the application, when parsing a message to be parsed, the remaining parsing length of the message to be parsed can be obtained, and it can be detected whether the message header length of the message to be parsed is less than the remaining parsing length. If the message header length is detected to be less than the remaining parsing length, that is, there is still a data area in the message to be parsed that needs to be parsed, the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located can be obtained. Based on the data parsing parameters, the target data of the buffer segment where the current cursor is located can be directly parsed. By moving the current cursor within the message to be parsed, the data of each buffer segment of the message to be parsed can be parsed, and the message parsing result can be obtained. Thus, the purpose of quickly locating a certain buffer segment of multiple non-contiguous buffer segments of the message to be parsed by the movable cursor of the message to be parsed, and parsing the target data cached on the buffer segment can be achieved.

[0075] Since the current cursor can move within the message to be parsed, in parsing the message to be parsed, it is only necessary to traverse and move the current cursor to each cache segment of the message to be parsed, that is, to quickly locate the cache segment of the target data of the message to be parsed, and then to parse the target data cached on that cache segment. Therefore, the purpose of quickly parsing the message to be parsed that is cached in non-contiguous cache segments is achieved.

[0076] Based on this, this application locates the data region to be parsed within the message to be parsed using the current cursor, and then parses the data region according to the data parsing parameters. Furthermore, by moving the current cursor arbitrarily within the message to be parsed, all data requiring parsing within the message can be parsed; that is, the data region to be parsed is precisely located using the current cursor, rather than repeatedly writing parsing code to locate the data stored in non-contiguous buffer segments. Therefore, it overcomes the technical defect that makes it difficult to locate the accurate location of message data in non-contiguous buffer segments, leading to the tendency to repeatedly write parsing code for message parsing, thus improving the parsing efficiency.

[0077] Example 2

[0078] Furthermore, referring to Figure 7 In another embodiment of this application, content that is the same as or similar to that in Embodiment 1 described above can be referred to the above description and will not be repeated hereafter. Based on this, before the step of obtaining the remaining parsing length of the message to be parsed, the message parsing method further includes:

[0079] Step E10: Obtain the accessible cache segment header space of the current cursor segment;

[0080] Step E20: If it is detected that the accessible cache segment header space is less than the header length of the message to be parsed, then after moving the header length, at least one message cache segment in the preset message cache segment group is selected as the message cache space.

[0081] Step E30: Cache the target data of the message to be parsed into the message cache space.

[0082] In this embodiment, it should be noted that before parsing the message to be parsed, the message to be parsed needs to be constructed in advance and stored in the corresponding message cache space. Based on the above, this embodiment sets up a variety of basic interfaces when parsing and constructing the message, such as the cursor forward movement interface (API_advance), the cursor backward movement interface (API_move_back), the read-only accessible cache segment access interface (API_chunk), the read-write accessible cache segment access interface (API_chunk_mut), the accessible cache header length query interface (API_headroom), the remaining length query interface (API_remaining), and the tail truncation interface (API_trimoff). Then, through interface calls and algorithm logic, the message to be parsed stored in multiple non-contiguous cache segments with a cursor can be constructed. Among them, the return value of API_headroom is chunk_addr minus cur_PD of buf_addr, and the return value of API_remaining is head_PD of total_len minus segs_len plus chunk_len.

[0083] Additionally, it should be noted that during message construction, since the message header does not carry actual data, a cache area needs to be set up for the message header. Typically, since the length of the cache header is greater than or equal to the length of the message header to be parsed, data can be cached directly based on the current cursor position. That is, the message header is stored in the accessible cache segment header space of the cache segment, and the message data is stored in the accessible cache segment space of the cache segment. However, if the accessible cache segment header space is less than the length of the message header to be parsed, the current cursor position needs to be moved to ensure that the message header is cached in the accessible cache segment header space of the cache segment. The default message cache segment group has multiple message cache segments. During the construction of the message to be parsed, the current cursor can traverse each message cache segment that needs to store message data.

[0084] As an example, steps E10 to E30 include: obtaining the accessible cache segment header space of the current cursor's cache segment by calling the accessible cache header length query interface; if the cache segment header space is detected to be smaller than the message header length of the message to be parsed, then after moving the message header length, selecting at least one message cache segment in a preset message cache group as the message cache space; and caching the target data of the message to be parsed into the message cache space.

[0085] In one feasible approach, taking the construction of a UDP header as an example: API_headroom is called to query the accessible buffer header space; it is then determined whether the length of the accessible buffer header space is less than the length of the UDP header; if less, the process ends; if not less, API_move_back is called to move the cursor backward by the length of the UDP header; API_chunk_mut is called to obtain a readable and writable chunk; the UDP header length is automatically set, equal to the remaining length plus the length of the UDP header, and the values ​​of each field are set simultaneously.

[0086] The message parsing method further includes, after the step of caching the target data of the message to be parsed into the message cache space:

[0087] Step F10: Obtain the length of the cache space to be truncated;

[0088] Step F20: If it is detected that the length of the cache space to be truncated is less than or equal to the length of the free cache of the message cache space, then when the length of the cache space to be truncated is less than the length of the truncated cache segment of the message cache space, the length of the cache space to be truncated is truncated in the truncated cache segment, and the length of the truncated cache segment and the total length of the message to be parsed are updated.

[0089] Step F30: If the length of the buffer space to be truncated is detected to be greater than the length of the free buffer, then a truncation error message for the message to be parsed is generated.

[0090] In this embodiment, it should be noted that, due to the varying data sizes of the messages to be parsed, the accessible buffer space for the last stored message data segment may exceed the data length. Therefore, a truncation operation is necessary to ensure the parsing efficiency and accuracy in subsequent message parsing processes. (Refer to...) Figure 8 , Figure 8This is a schematic diagram of a message truncation interface. In this diagram, 21 represents the length of the cache space to be truncated, which is the length of the space in the cache segment waiting to be truncated. The free cache length represents the length of the cache space without cached message data, and the truncated cache segment represents the cache segment in which the truncation operation is performed. Based on the length relationship between the length of the cache space to be truncated and the free cache length, it is ensured that the truncation operation will not affect the cached message data. The cache data needs to be updated after truncation is completed.

[0091] As an example, steps F10 to F30 include: obtaining the length of the cache space to be truncated; if it is detected that the length of the cache space to be truncated is less than or equal to the free cache length of the message cache space, then when the length of the cache space to be truncated is less than the cache segment length of the truncated cache segment of the message cache space, the length of the cache space to be truncated is truncated in the truncated cache segment, and the cache segment length of the truncated cache segment and the total message length of the message to be parsed are updated; if it is detected that the length of the cache space to be truncated is greater than the free cache length, then a truncation error message for the message to be parsed is generated, wherein the truncation error message may specifically be "valid data is truncated".

[0092] In one feasible approach, the process of truncating the length of the buffer space to be truncated is as follows: Input the length to be truncated at the end; call API_remaining, which returns the remaining length; determine if the truncated length is greater than the remaining length; if so, end the process. Otherwise, proceed to: determine if the truncated length is greater than the buf_len of the last PD. If it is greater, end the process. Otherwise, proceed to: subtract the truncated length from the buf_len of the last PD, and subtract the truncated length from the total_len of the head_PD.

[0093] The message parsing method further includes, after the step of truncating the length of the cache space to be truncated in the truncated cache segment:

[0094] Step G10: Detect whether the current cursor of the message to be parsed is in the truncated buffer segment;

[0095] Step G20: If the cache is in the truncated cache segment, then update the cache space length of the truncated cache segment.

[0096] In this embodiment, it should be noted that since the current cursor is dynamic, if the cache segment where the current cursor is located is truncated, the length of the corresponding cache segment needs to be updated to avoid parsing errors in subsequent messages to be parsed.

[0097] As an example, steps G10 to G20 include: detecting whether the current cursor of the message to be parsed is in the truncated buffer segment; if the current cursor of the message to be parsed is detected to be in the truncated buffer segment, then updating the buffer space length of the truncated buffer segment, wherein the update method can be either the buffer space length of the buffer segment minus the length of the truncated buffer space, or the buffer space length of the buffer segment minus a portion of the length of the truncated buffer space.

[0098] This application provides a method for constructing a message to be parsed. Specifically, it involves obtaining the accessible cache segment header space of the current cursor's cache segment; if the accessible cache segment header space is detected to be smaller than the message header length of the message to be parsed, then after moving the message header length, at least one message cache segment within a preset message cache segment group is selected as the message cache space; and the target data of the message to be parsed is cached in the message cache space. When constructing a message to be parsed, this application can obtain the accessible cache segment header space of the current cursor's cache segment. If the accessible cache segment header space is detected to be smaller than the message header length of the message to be parsed, meaning the message header cannot be completely cached within the accessible cache segment header space of the cache segment, then after moving the message header length, at least one message cache segment within a preset message cache segment group is selected as the message cache space. Finally, the target data of the message to be parsed is cached in the message cache space, ensuring that the target data of the message to be parsed is completely cached within the accessible cache segment space of the cache segment, thus laying the foundation for high-speed parsing of the message to be parsed.

[0099] Example 3

[0100] This application also provides a message parsing device, referring to... Figure 9 The message parsing device includes:

[0101] The acquisition module 101 is used to obtain the remaining parsing length of the message to be parsed;

[0102] The detection module 102 is used to obtain the data parsing parameters of the current cursor of the message to be parsed if the message header length of the message to be parsed is less than the remaining parsing length.

[0103] The parsing module 103 is used to parse the target data in the buffer segment where the current cursor is located according to the data parsing parameters, and to parse the message to be parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0104] Optionally, the message parsing result includes a first message parsing result and a second message parsing result, and the parsing module 103 is further configured to:

[0105] After the current cursor moves by the length of the target data, it is detected whether the current cursor is located within the message to be parsed after the move;

[0106] If so, then based on the data length, the cursor parameters of the current cursor are updated to obtain the updated current cursor;

[0107] The updated current cursor is used as the current cursor, and the process returns to the step of obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located and the subsequent steps, until the parsing result of the first message is obtained, wherein the parsing result of the first message is used to indicate that the parsing of the message to be parsed has been completed;

[0108] If not, the parsing error information of the message to be parsed is taken as the result of the second message.

[0109] Optionally, the cursor parameters include the cache segment identifier of the cache segment where the cursor is located, the cache space length of the cache segment where the cursor is located, and the byte address pointed to by the cursor in the cache segment. The parsing module 103 is further used for:

[0110] If the current cursor is detected to be moving within the cache segment based on the data length, the updated current cursor is obtained by updating the cache space length and the byte address;

[0111] If the current cursor is detected to be moving between cache segments based on the data length, the updated current cursor is obtained by updating the cache segment identifier, the cache space length, and the byte address.

[0112] Optionally, the message parsing device is further configured to:

[0113] Obtain a first length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located, and obtain a second length difference between the parsing length of the cache segment and the cache segment length of the cache segment where the current cursor is located;

[0114] Detect whether the second length difference is less than the third length difference between the first length difference and the data length;

[0115] If it is less than, then it is determined that the current cursor is moving within the current buffer segment;

[0116] If it is greater than or equal to, then the current cursor is determined to move between the current cache segments.

[0117] Optionally, the message parsing device is further configured to:

[0118] Obtain a fourth length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located, and obtain a first length sum between the fourth length difference and the data length;

[0119] Detect whether the parsed length of the cache segment is greater than the first length and value;

[0120] If it is greater than, then it is determined that the current cursor is moving between the current cache segments;

[0121] If it is less than or equal to, then the current cursor is determined to move within the current buffer segment.

[0122] Optionally, the message parsing device is further configured to:

[0123] Get the accessible cache segment header space of the current cursor segment;

[0124] If it is detected that the accessible cache segment header space is less than the header length of the message to be parsed, then after moving the header length, at least one message cache segment in the preset message cache segment group is selected as the message cache space.

[0125] The target data of the message to be parsed is cached in the message cache space.

[0126] Optionally, the message parsing device is further configured to:

[0127] Get the length of the cache space to be truncated;

[0128] If it is detected that the length of the cache space to be truncated is less than or equal to the length of the free cache of the message cache space, then when the length of the cache space to be truncated is less than the length of the truncated cache segment of the message cache space, the length of the cache space to be truncated is truncated in the truncated cache segment, and the length of the truncated cache segment and the total length of the message to be parsed are updated.

[0129] If the length of the cache space to be truncated is detected to be greater than the length of the free cache, a truncation error message for the message to be parsed is generated.

[0130] The message parsing apparatus provided by this invention employs the message parsing method in the above embodiments, solving the technical problem of low parsing efficiency. Compared with the prior art, the beneficial effects of the message parsing apparatus provided by the embodiments of this invention are the same as those of the message parsing method provided in the above embodiments, and other technical features in this message parsing apparatus are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0131] Example 4

[0132] This invention provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the message parsing method in Embodiment 1 above.

[0133] The following is for reference. Figure 10 The diagram illustrates a structural schematic of an electronic device suitable for implementing embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, data communication products such as routers, switches, gateway devices, etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 10 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0134] like Figure 10 As shown, the electronic device may include a processing unit 1001 (e.g., a central processing unit, a graphics processor, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the electronic device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus.

[0135] Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. The communication devices allow electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although electronic devices with various systems are shown in the figures, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems may be implemented alternatively.

[0136] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 1009, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of embodiments of this disclosure.

[0137] The electronic device provided by this invention employs the message parsing method in the above embodiments, solving the technical problem of low parsing efficiency. Compared with the prior art, the beneficial effects of the electronic device provided by the embodiments of this invention are the same as those of the message parsing method provided in the above embodiments, and other technical features in this electronic device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0138] It should be understood that various parts of this disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics may be combined in any suitable manner in one or more embodiments or examples.

[0139] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

[0140] Example 5

[0141] This embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon, which are used to execute the message parsing method in the above embodiment.

[0142] The computer-readable storage medium provided in this embodiment of the invention may be, for example, a USB flash drive, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0143] The aforementioned computer-readable storage medium may be included in an electronic device or may exist independently without being assembled into an electronic device.

[0144] The aforementioned computer-readable storage medium carries one or more programs. When the aforementioned one or more programs are executed by an electronic device, the electronic device causes the electronic device to: obtain the remaining parsing length of the message to be parsed; if it is detected that the header length of the message to be parsed is less than the remaining parsing length, obtain the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located; parse the target data of the buffer segment where the current cursor is located according to the data parsing parameters, and parse the message to be parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result.

[0145] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0146] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0147] The modules described in the embodiments of this disclosure can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0148] The computer-readable storage medium provided by this invention stores computer-readable program instructions for executing the above-described message parsing method, thus solving the technical problem of low parsing efficiency in message parsing. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiments of this invention are the same as the beneficial effects of the message parsing method provided in the above-described embodiments, and will not be repeated here.

[0149] Example 6

[0150] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the message parsing method described above.

[0151] The computer program product provided in this application solves the technical problem of low parsing efficiency in message parsing. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiments of this invention are the same as the beneficial effects of the message parsing method provided in the above embodiments, and will not be repeated here.

[0152] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent scope of this application.

Claims

1. A message parsing method, characterized in that, The message parsing method includes: Get the remaining parsing length of the message to be parsed; If the header length of the message to be parsed is detected to be less than the remaining parsing length, then the data parsing parameters of the current cursor of the message to be parsed are obtained. Based on the data parsing parameters, the target data in the buffer segment where the current cursor is located is parsed, and the message to be parsed is parsed by moving the current cursor within the message to be parsed, thereby obtaining the message parsing result; The message parsing results include the first message parsing result and the second message parsing result. The step of parsing the message to be parsed by moving the current cursor within the message to be parsed to obtain the message parsing result includes: After the current cursor moves by the length of the target data, it is detected whether the current cursor is located within the message to be parsed after the move; If so, then based on the data length, the cursor parameters of the current cursor are updated to obtain the updated current cursor; The updated current cursor is used as the current cursor, and the process returns to the step of obtaining the data parsing parameters of the buffer segment where the current cursor of the message to be parsed is located and the subsequent steps, until the parsing result of the first message is obtained, wherein the parsing result of the first message is used to indicate that the parsing of the message to be parsed has been completed; If not, the parsing error information of the message to be parsed shall be taken as the parsing result of the second message; The cursor parameters include the cache segment identifier of the cache segment where the cursor is located, the cache space length of the cache segment where the cursor is located, and the byte address pointed to by the cursor in the cache segment. The cache space length is used to characterize the space length of the accessible cache segment. The step of updating the cursor parameters of the current cursor according to the data length to obtain the updated current cursor includes: If the current cursor is detected to be moving within the cache segment based on the data length, the updated current cursor is obtained by updating the cache space length and the byte address; If the current cursor is detected to be moving between cache segments based on the data length, the updated current cursor is obtained by updating the cache segment identifier, the cache space length, and the byte address.

2. The message parsing method as described in claim 1, characterized in that, Before the step of updating the cursor parameters of the current cursor according to the data length to obtain the updated current cursor, the message parsing method further includes: The system obtains a first length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located, and a second length difference between the parsing length of the cache segment and the cache segment length of the cache segment where the current cursor is located; the cache segment length is used to characterize the length of the cache segment; the cache segment parsing length is used to characterize the sum of the lengths of the cache segments that have been parsed in the message to be parsed. Detect whether the second length difference is less than the third length difference between the first length difference and the data length; If it is less than, then it is determined that the current cursor is moving within the current buffer segment; If it is greater than or equal to, then the current cursor is determined to move between the current cache segments.

3. The message parsing method as described in claim 1, characterized in that, Before the step of updating the cursor parameters of the current cursor according to the data length to obtain the updated current cursor, the message parsing method further includes: Obtain a fourth length difference between the parsing length of the cache segment of the message to be parsed and the cache space length of the cache segment where the current cursor is located, and obtain a first length sum between the fourth length difference and the data length; Detect whether the parsed length of the cache segment is greater than the first length and value; If it is greater than, then it is determined that the current cursor is moving between the current cache segments; If it is less than or equal to, then the current cursor is determined to move within the current buffer segment.

4. The message parsing method as described in claim 1, characterized in that, Before the step of obtaining the remaining parsing length of the message to be parsed, the message parsing method further includes: Get the accessible cache segment header space of the current cursor segment; If it is detected that the accessible cache segment header space is less than the header length of the message to be parsed, then after moving the header length, at least one message cache segment in the preset message cache segment group is selected as the message cache space. The target data of the message to be parsed is cached in the message cache space.

5. The message parsing method as described in claim 4, characterized in that, After the step of caching the target data of the message to be parsed into the message cache space, the message parsing method further includes: Get the length of the cache space to be truncated; If it is detected that the length of the cache space to be truncated is less than or equal to the length of the free cache of the message cache space, then when the length of the cache space to be truncated is less than the length of the truncated cache segment of the message cache space, the length of the cache space to be truncated is truncated in the truncated cache segment, and the length of the truncated cache segment and the total length of the message to be parsed are updated. If the length of the cache space to be truncated is detected to be greater than the length of the free cache, a truncation error message for the message to be parsed is generated.

6. The message parsing method as described in claim 5, characterized in that, After the step of truncating the length of the buffer space to be truncated in the truncated buffer segment, the message parsing method further includes: Detect whether the current cursor of the message to be parsed is in the truncated buffer segment; If the cache is in the truncated cache segment, then update the cache space length of the truncated cache segment.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; A memory that is communicatively connected to the at least one processor; The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the steps of the message parsing method according to any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program that implements the message parsing method, which is executed by a processor to implement the steps of the message parsing method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Network message analysis method and device

    CN115277880A

  • Network message analysis method and device

    CN115277881A