Data packet analysis method and device, computer device, and storage medium

By acquiring and verifying the packet header, data length, and packet trailer, the packet parsing process is unified, solving the problem of low parsing code efficiency caused by different protocols in embedded products and improving writing efficiency.

CN116346958BActive Publication Date: 2026-02-13AMBULANC (SHENZHEN) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211695524.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-28
Publication Date
2026-02-13
Estimated Expiration
2042-12-28

AI Technical Summary

Technical Problem

In embedded products, existing technologies require software engineers to write corresponding parsing code to deal with different data communication protocols, which increases the workload and makes it difficult to guarantee parsing efficiency and quality.

Method used

A packet parsing method is provided, which unifies the packet parsing process by obtaining the packet header from the received data stream and determining its validity, obtaining the length of the received data and determining its validity, and finally obtaining the packet trailer and determining its validity.

Benefits of technology

It enables packet parsing compatible with different data communication protocols, improving the efficiency of writing parsing code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116346958B_ABST
    Figure CN116346958B_ABST
Patent Text Reader

Abstract

The application relates to the field of data transmission, and discloses a data packet analysis method and device, computer equipment and a storage medium, which comprises the following steps: obtaining a packet header of a to-be-acquired data packet from a data stream in reception; judging the validity of the packet header; if the packet header is valid, obtaining the received data length of the to-be-acquired data packet, judging the validity of the received data length; if the received data length is valid, obtaining a packet tail of the to-be-acquired data packet; judging the validity of the packet tail; and if the packet tail is valid, obtaining the to-be-acquired data packet according to the packet header and the packet tail. The application obtains the packet header, judges the validity of the packet header, obtains the received data length of the data packet, judges the validity of the received data length, obtains the packet tail of the to-be-acquired data packet, judges the validity of the packet tail, and finally obtains the data packet, so that a unified analysis process of a data communication protocol is realized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data transmission, and in particular to a data packet analysis method and device, a computer device and a storage medium. BACKGROUND

[0002] At present, in embedded products, it is often necessary to parse data packets according to data communication protocols. Usually, a software engineer will write a protocol analysis code according to a specific protocol. Since there are many different types of protocol definition formats, the analysis codes are also different. In the face of different data communication protocols, the software engineer needs to write corresponding analysis codes, which not only increases the workload of the software engineer, but also cannot guarantee the efficiency and quality of data analysis. SUMMARY

[0003] Therefore, it is necessary to provide a data packet analysis method, device, computer device and storage medium to unify the data packet analysis process and improve the efficiency of writing analysis codes.

[0004] A data packet analysis method comprises the following steps:

[0005] A packet header of a to-be-acquired data packet is acquired from a data stream being received.

[0006] The validity of the packet header is determined.

[0007] If the packet header is valid, the received data length of the to-be-acquired data packet is acquired, and the validity of the received data length is determined.

[0008] If the received data length is valid, a packet trailer of the to-be-acquired data packet is acquired.

[0009] The validity of the packet trailer is determined.

[0010] If the packet trailer is valid, the to-be-acquired data packet is acquired according to the packet header and the packet trailer.

[0011] A data packet analysis device comprises the following modules:

[0012] A packet header acquisition module is configured to acquire a packet header of a to-be-acquired data packet from a data stream being received.

[0013] A packet header determination module is configured to determine the validity of the packet header.

[0014] A data validity determination module is configured to, if the packet header is valid, acquire the received data length of the to-be-acquired data packet and determine the validity of the received data length.

[0015] a packet tail acquisition module, configured to acquire a packet tail of the data packet to be acquired if the received data length is valid;

[0016] a packet tail judgment module, configured to judge validity of the packet tail;

[0017] a data packet acquisition module, configured to acquire the data packet to be acquired according to the packet head and the packet tail if the packet tail is valid.

[0018] A computer device comprises a memory, a processor, and computer readable instructions stored in the memory and executable on the processor, and the processor implements the above data packet analysis method when executing the computer readable instructions.

[0019] A computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the above data packet analysis method.

[0020] In the above data packet analysis method, device, computer device and storage medium, the packet head of the data packet to be acquired is acquired from the data stream being received, and the validity of the packet head is judged. If the packet head is valid, the received data length of the data packet to be acquired is acquired, and the validity of the received data length is judged. If the received data length is valid, the packet tail of the data packet to be acquired is acquired, and the validity of the packet tail is judged. Finally, if the packet tail is valid, the data packet to be acquired is acquired according to the packet head and the packet tail. The packet head of the data packet to be acquired is acquired from the data stream being received, and the validity of the packet head is judged. The validity of the received data length is judged, and finally the packet tail is acquired and the validity of the packet tail is judged. The data packet analysis process is unified, different data communication protocols can be compatible, and the coding efficiency of the analysis code is greatly improved. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0022] Figure 1 is a flowchart of a data packet analysis method in an embodiment of the present application;

[0023] Figure 2 is a structural schematic diagram of a data packet analysis device in an embodiment of the present application;

[0024] Figure 3 is a schematic diagram of a computer device in an embodiment of the present application. DETAILED DESCRIPTION

[0025] The technical solutions in the embodiments of the present application will be clearly and completely described with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative effort are within the scope of the present application.

[0026] In an embodiment, as shown in FIG. 1, a data packet parsing method is provided, comprising the following steps S10-S60. Figure 1

[0027] S10, obtaining a packet header of a to-be-acquired data packet from a received data stream.

[0028] Understandably, the received data stream can be a data stream received uninterruptedly through a preset communication protocol, where the preset communication protocol can be an MQTT (Message Queue Telemetry Transport) serial communication protocol or a USB (Universal Serial Bus). The to-be-acquired data packet can be a data packet to be acquired in the data stream. The data packet comprises a packet header, an effective data length and a packet tail, where the packet header can be a kind of mark of a start position of the data packet, the effective data length can be a length of data in the data packet, and the packet tail can be a kind of mark of an end position of the data packet.

[0029] Specifically, the data stream is received uninterruptedly through the preset communication protocol, and the packet header of the to-be-acquired data packet is obtained from the received data stream.

[0030] S20, judging validity of the packet header.

[0031] S30, if the packet header is valid, obtaining a received data length of the to-be-acquired data packet, and judging validity of the received data length.

[0032] Understandably, the validity of the packet header can be verified according to a preset packet header verification method. The preset packet header verification method can be set according to actual needs. It can be judged whether the received data length of the data packet is greater than or equal to a maximum length of the data packet, if the received data length is greater than or equal to the maximum length of the data packet, the received data length of the data packet is invalid, and if the received data length is less than the maximum length of the data packet, the received data length of the data packet is valid. The received data length of the to-be-acquired data packet can be a data length received after the obtained packet header is valid.

[0033] ​Specifically, it is judged whether the packet header is valid. If the packet header is valid, it indicates that the packet header of the data packet to be acquired has been acquired in the received data stream, and then the length of the received data after the packet header is acquired, and whether the length of the received data is valid is judged.

[0034] S40, if the length of the received data is valid, the packet tail of the data packet to be acquired is acquired.

[0035] S50, judging the validity of the packet tail.

[0036] Specifically, if the length of the received data is valid, it indicates that the current data packet has been received, and the packet tail can be identified from the received data, and the validity of the packet tail is judged.

[0037] S60, if the packet tail is valid, the data packet to be acquired is acquired according to the packet header and the packet tail.

[0038] Specifically, if the packet tail is valid, the data packet to be acquired is determined according to the packet header and the packet tail.

[0039] The embodiment realizes the triple verification of the data packet and unifies the process of data packet analysis by acquiring the packet header, judging the validity of the packet header, acquiring the length of the received data of the data packet to be acquired and judging the validity of the length of the received data, then acquiring the packet tail of the data packet to be acquired and judging the validity of the packet tail, and finally acquiring the data packet to be acquired according to the packet header and the packet tail.

[0040] Optionally, the step S10, that is, acquiring the packet header of the data packet to be acquired from the data stream in the receiving, comprises:

[0041] S101, setting a first data start position of the packet header to be evaluated when the packet header flag indicates that the packet header is not detected.

[0042] S102, recording a to-be-evaluated data length of the data received from the first data start position.

[0043] Understandably, the packet header flag can be a flag indicating the detection or non-detection state of the packet header, for example, when the packet header is not detected, the packet header flag is flag=0, and when the packet header is detected, the packet header flag is flag=1. The first data start position can be the position when the data is acquired from the data stream.

[0044] Specifically, when the packet header flag indicates that the packet header is not detected, the first data start position of the packet header to be evaluated is set, and the length of the received data from the first data start position is recorded. For example, when the packet header flag is flag=0, it indicates that the packet header is in a non-detection state, the first data start position of the packet header to be evaluated is set as A, the position of the current received data is B, and the length of the received data from the data start position A is BA.

[0045] S103, obtaining the to-be-evaluated packet header when the to-be-evaluated data length is not less than the preset length of the packet header.

[0046] S104, verifying the validity of the to-be-evaluated packet header according to a preset packet header verification method.

[0047] S105, if the to-be-evaluated packet header is valid, determining the to-be-evaluated packet header as the packet header of the to-be-obtained data packet, and modifying the packet header flag so that the packet header flag indicates that the packet header has been detected.

[0048] Understandably, the preset length of the packet header can be a packet header length set by a user in advance. The to-be-evaluated packet header can be a piece of to-be-evaluated data. The preset packet header verification method can be a packet header verification method set by the user in advance according to a type of a preset communication protocol. Here, the preset packet header verification method can be in the form of a callback function, so as to be applicable to different types of communication protocols.

[0049] Specifically, when the length of the received data is not less than the preset length of the packet header, the to-be-evaluated packet header can be cut from the received data, the validity of the to-be-evaluated packet header is verified according to the preset packet header verification method, if the to-be-evaluated packet header conforms to the preset packet header verification method, it is determined that the to-be-evaluated packet header is valid, and the to-be-evaluated packet header is determined as the packet header of the to-be-obtained data packet; the packet header flag is modified so that the packet header flag indicates that the packet header has been detected. For example, when the length of the received data BA is equal to the preset length of the packet header, the received data BA is cut as the to-be-evaluated packet header C, the validity of the to-be-evaluated packet header C is verified according to the preset packet header callback function verification method, if the to-be-evaluated packet header C conforms to the preset packet header callback function, the to-be-evaluated packet header C is the packet header of the to-be-obtained data packet, and the packet header flag is modified to flag = 1, indicating that the packet header is in a detected state.

[0050] The embodiment obtains the to-be-evaluated packet header by recording the to-be-evaluated data length of the data received from the data starting position, verifies the validity of the to-be-evaluated packet header according to the preset packet header verification method, and thus obtains the packet header of the to-be-obtained data packet, thereby realizing the function of obtaining the packet header and performing multiple verifications on the packet header.

[0051] Optionally, step S102, that is, recording the to-be-evaluated data length of the data received from the first data starting position, further includes:

[0052] S1021, determining whether the to-be-evaluated data length is greater than or equal to the maximum length of the data packet.

[0053] S1022, if the to-be-evaluated data length is greater than or equal to the maximum length of the data packet, storing the data received from the first data starting position into a cache area.

[0054] It is understandable that the maximum length of the data packet can be determined according to the maximum length of the data packet allowed by the preset communication protocol. The buffer area is an object for storing and manipulating data.

[0055] Specifically, the maximum length of the data packet allowed by the preset communication protocol is obtained according to the type of the communication protocol, it is judged whether the length of the received data is greater than or equal to the maximum length of the data packet, and if the length of the received data is greater than or equal to the maximum length of the data packet, the received data starting from the first data starting position is stored in the buffer area. For example, when the received data is BA, the maximum length DE of the data packet allowed by the preset communication protocol is obtained according to the type of the communication protocol, and if the received data BA is greater than or equal to the maximum length DE of the data packet, the received data BA is stored in the buffer area.

[0056] The embodiment improves the efficiency of subsequent repeated processing of data by storing the received data starting from the first data starting position in the buffer area when the length of the data to be evaluated is greater than or equal to the maximum length of the data packet.

[0057] Optionally, after step S102, that is, after recording the length of the data to be evaluated received from the first data starting position, the method further comprises:

[0058] S1023, if the length of the data to be evaluated is less than the preset length of the packet header, continue to receive data.

[0059] Specifically, if the length of the data to be evaluated is less than the preset length of the packet header, it indicates that the length of the data to be evaluated does not reach the preset length of the packet header, and the data continues to be received.

[0060] Optionally, after step S104, that is, after verifying the validity of the packet header to be evaluated according to the preset packet header verification method, the method further comprises:

[0061] S1041, if the packet header to be evaluated is invalid, the data position of the specified number after the first data starting position is set as the second data starting position of the packet header to be evaluated.

[0062] It is understandable that the data position of the specified number can be one byte length. The second data starting position can be the position of the start of the data obtained for the second time.

[0063] Specifically, if the to-be-evaluated packet header is invalid, a position one byte length after the first data start position is set as the second data start position, and the to-be-evaluated packet header is reacquired according to the second data start position. For example, when the to-be-evaluated packet header is invalid and the first data start position is 0, position 1 one byte length after 0 is set as the second data start position, and the to-be-evaluated packet header is reacquired according to the second data start position 1.

[0064] The embodiment achieves data shifting when data is invalid by setting a position one byte length after the first data start position as the second data start position of the to-be-evaluated packet header when the to-be-evaluated packet header is invalid. Commonly used data shifting is discarding of an entire data packet, and the data shifting of the embodiment enhances anti-interference capability during data parsing and improves effectiveness of sorting interference data.

[0065] Optionally, the step S30, that is, the acquired received data length of the to-be-acquired data packet is judged for validity, includes:

[0066] S301, whether the received data length is smaller than a minimum data packet length is judged.

[0067] S302, if the received data length is not smaller than the minimum data packet length, whether the received data length is not larger than a maximum data packet length is judged.

[0068] Understandably, the minimum data packet length can be a minimum data packet length allowed according to a preset communication protocol.

[0069] Specifically, whether the received data length is smaller than the minimum data packet length is judged, if the received data length is not smaller than the minimum data packet length, whether the received data length is not larger than the maximum data packet length is judged, and if the received data length is smaller than the minimum data packet length, data continues to be received.

[0070] S303, if the received data length is smaller than the maximum data packet length, whether a start receiving position of a current data packet is same as a preset start position of the data packet is judged.

[0071] S304, if the start receiving position of the current data packet is same as the preset start position of the data packet, the minimum data packet length is determined as a total length of the first data packet, and the received data length is determined as valid.

[0072] Understandably, the preset start position of the data packet can be a start position of the data packet set by a user according to actual needs of acquired data packets.

[0073] In particular, the starting position of the data packet is acquired, if the length of the received data is less than the maximum length of the data packet, the starting receiving position of the current data packet is acquired, it is judged whether the starting receiving position of the current data packet is same as the starting position of the data packet, if the starting receiving position of the current data packet is same as the starting position of the data packet, the minimum length of the data packet is determined as the total length of the data packet, and it is determined that the length of the received data is valid. For example, the starting receiving position of the current data packet is H, the starting position of the data packet is POS, if POS = H, the total length of the data packet to be acquired is the minimum length of the data packet allowed by the preset communication protocol.

[0074] S305, if the starting receiving position of the current data packet is not same as the starting position of the data packet, the total length of the second data packet is calculated.

[0075] S306, it is judged whether the length of the received data is equal to the total length of the second data packet.

[0076] S307, if the length of the received data is equal to the total length of the second data packet, it is determined that the length of the received data is valid.

[0077] It can be understood that the total length of the second data packet includes the length of the second data packet and the extra length of the data packet, here, the length of the second data packet can be calculated according to the storage mode of the data bytes in the data stream.

[0078] In the big-end mode, the formula of the length of the data packet can be:

[0079] Big-end data packet length = (data[POS] << 8*(L-1)) + … + (data[POS+L-1] << 8*0).

[0080] POS is the starting position of the data packet;

[0081] L is the number of bytes occupied by the data packet (L can be 0, 1, 2, 3 or 4);

[0082] POS and L are set according to actual needs.

[0083] In the little-end mode, the formula of the length of the data packet can be:

[0084] Little-end data packet length = (data[POS] << 8*0) + … + (data[POS+L-1] << 8*(L-1)).

[0085] The extra length of the data packet is set according to actual needs.

[0086] Specifically, if the starting receiving position of the current data packet is not the same as the starting position of the data packet preset, the storage mode of the data bytes in the data stream is acquired, the second data packet length is calculated according to the storage mode of the data bytes in the data stream, the data packet additional length is acquired, and the second data packet total length is acquired according to the second data packet length and the data packet additional length. It is judged whether the received data length is equal to the second data packet total length. If the received data length is equal to the second data packet total length, it is determined that the received data length is valid; if the received data length is less than the second data packet total length, the data is continuously acquired.

[0087] The embodiment acquires the length of the received data, and judges whether the starting receiving position of the current data packet is the same as the starting position of the data packet preset, thereby acquiring the valid data length under different conditions, and realizing the acquisition of the data packet data length and the multiple verification of the validity of the data packet data length.

[0088] Optionally, after step S50, that is, after judging the validity of the packet tail, the method further comprises:

[0089] S501, if the packet tail is invalid, setting the packet head flag to indicate that the packet head is not detected, and reacquiring the packet head of the data packet to be acquired.

[0090] Specifically, if the packet tail is invalid, the packet head flag is set to indicate that the packet head is not detected, one byte length position after the data starting position is set as a new data starting position, and the packet head to be evaluated is reacquired according to the new data starting position.

[0091] It should be understood that the size of the serial number of each step in the above embodiment does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the application.

[0092] In an embodiment, a data packet parsing device is provided, which corresponds to the data packet parsing method in the above embodiment. As shown in the figure, the data packet parsing device comprises a packet head acquisition module 10, a packet head judgment module 20, a data validity judgment module 30, a packet tail acquisition module 40, a packet tail judgment module 50 and a data packet acquisition module 60. The functions of each module are described in detail as follows: Figure 2

[0093] The packet head acquisition module 10 is used to acquire the packet head of the data packet to be acquired from the data stream being received;

[0094] The packet head judgment module 20 is used to judge the validity of the packet head;

[0095] ​The data validity judging module 30 is configured to, if the packet header is valid, acquire a received data length of the data packet to be acquired, and judge the validity of the received data length.

[0096] The packet tail acquiring module 40 is configured to, if the received data length is valid, acquire a packet tail of the data packet to be acquired.

[0097] The packet tail judging module 50 is configured to judge the validity of the packet tail.

[0098] The data packet acquiring module 60 is configured to, if the packet tail is valid, acquire the data packet to be acquired according to the packet header and the packet tail.

[0099] Preferably, the packet header acquiring module 10 comprises:

[0100] The first data start position setting unit is configured to, when the packet header flag indicates that the packet header is not detected, set a first data start position of a packet header to be evaluated.

[0101] The to-be-evaluated data length recording unit is configured to record a to-be-evaluated data length of data received from the first data start position.

[0102] The to-be-evaluated packet header acquiring unit is configured to, when the to-be-evaluated data length is not less than a preset packet header length, acquire the to-be-evaluated packet header.

[0103] The to-be-evaluated packet header validity verifying unit is configured to verify the validity of the to-be-evaluated packet header according to a preset packet header verifying method.

[0104] The data packet to be acquired packet header determining unit is configured to, if the to-be-evaluated packet header is valid, determine the to-be-evaluated packet header as a packet header of the data packet to be acquired, and modify the packet header flag so that the packet header flag indicates that the packet header is detected.

[0105] Preferably, the to-be-evaluated data length recording unit comprises:

[0106] The to-be-evaluated data length judging subunit is configured to judge whether the to-be-evaluated data length is greater than or equal to a maximum data packet length.

[0107] The cache area data storing subunit is configured to, if the to-be-evaluated data length is greater than or equal to the maximum data packet length, store the data received from the first data start position into a cache area.

[0108] Preferably, the to-be-evaluated data length recording unit further comprises:

[0109] The data continuing receiving subunit is configured to, if the to-be-evaluated data length is less than the preset packet header length, continue to receive data.

[0110] Preferably, the above-mentioned to-be-evaluated packet header validity verification unit further comprises:

[0111] a to-be-evaluated packet header invalid sub-unit, configured to, if the to-be-evaluated packet header is invalid, set a specified number of data positions after the first data start position as a second data start position of the to-be-evaluated packet header.

[0112] Preferably, the data validity judgment module 30 comprises:

[0113] a first received data length judgment unit, configured to judge whether the received data length is less than the minimum data packet length;

[0114] a second received data length judgment unit, configured to, if the received data length is not less than the minimum data packet length, judge whether the received data length is not greater than the maximum data packet length;

[0115] a data packet start receiving position judgment unit, configured to, if the received data length is less than the maximum data packet length, judge whether the start receiving position of the current data packet is the same as the preset start position of the data packet;

[0116] a first data packet total length calculation unit, configured to, if the start receiving position of the current data packet is the same as the preset start position of the data packet, determine the minimum data packet length as the first data packet total length, and determine that the received data length is valid;

[0117] a second data packet total length calculation unit, configured to, if the start receiving position of the current data packet is not the same as the preset start position of the data packet, calculate the second data packet total length;

[0118] a third received data length judgment unit, configured to judge whether the received data length is equal to the second data packet total length;

[0119] a received data length validity determination unit, configured to, if the received data length is equal to the second data packet total length, determine that the received data length is valid.

[0120] Preferably, the packet tail judgment module 50 comprises:

[0121] a packet tail invalid unit, configured to, if the packet tail is invalid, set the packet header flag to indicate that the packet header is not detected, and re-acquire the packet header of the to-be-acquired data packet.

[0122] For specific limitations regarding the packet parsing device, please refer to the limitations on the packet parsing method above, which will not be repeated here. Each module in the aforementioned packet parsing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0123] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 3 As shown, the computer device includes a processor, memory, network interface, display screen, and input device connected via a system bus. The processor provides computing and control capabilities. The memory includes a readable storage medium and internal memory. The non-volatile storage medium stores the operating system and computer-readable instructions. The internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The network interface is used to communicate with an external server via a network connection. When the computer-readable instructions are executed by the processor, they implement a data packet parsing method. The readable storage medium provided in this embodiment includes both non-volatile and volatile readable storage media.

[0124] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the data packet parsing method described in the above embodiment.

[0125] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the data packet parsing method described in the above embodiment.

[0126] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing relevant hardware through computer readable instructions, and the computer readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When the computer readable instructions are executed, the processes of the above-mentioned embodiments of the method can be included. Any reference to memory, storage, database or other medium used in each embodiment provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0127] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of functional units and modules is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.

[0128] The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not to limit it; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; 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 embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A data packet parsing method, characterized in that, The method comprises the following steps: acquiring a packet header of a data packet to be acquired from a data stream being received; judging validity of the packet header; if the packet header is valid, acquiring a received data length of the data packet to be acquired, and judging validity of the received data length; judging whether the received data length is less than a minimum length of a data packet; if the received data length is not less than the minimum length of the data packet, judging whether the received data length is not greater than a maximum length of the data packet; if the received data length is less than the maximum length of the data packet, judging whether a starting receiving position of a current data packet is the same as a preset starting position of the data packet; if the starting receiving position of the current data packet is the same as the preset starting position of the data packet, determining the minimum length of the data packet as a first total length of the data packet, and determining that the received data length is valid; if the starting receiving position of the current data packet is not the same as the preset starting position of the data packet, calculating a second total length of the data packet; judging whether the received data length is equal to the second total length of the data packet; if the received data length is equal to the second total length of the data packet, determining that the received data length is valid; if the received data length is valid, acquiring a packet tail of the data packet to be acquired; judging validity of the packet tail; if the packet tail is valid, acquiring the data packet to be acquired according to the packet header and the packet tail.

2. The data packet parsing method of claim 1, wherein, The step of acquiring the packet header of the data packet to be acquired from the data stream being received comprises the following steps: when a packet header flag indicates that the packet header has not been detected, setting a first data starting position of a packet header to be evaluated; recording an evaluated data length of data received from the first data starting position; when the evaluated data length is not less than a preset length of the packet header, acquiring the packet header to be evaluated; judging validity of the packet header to be evaluated according to a preset packet header verification method; if the packet header to be evaluated is valid, determining the packet header to be evaluated as the packet header of the data packet to be acquired; and modifying the packet header flag so that the packet header flag indicates that the packet header has been detected.

3. The data packet parsing method of claim 2, wherein, The step of recording the evaluated data length of the data received from the first data starting position further comprises the following steps: judging whether the evaluated data length is greater than or equal to a maximum length of a data packet; if the evaluated data length is greater than or equal to the maximum length of the data packet, storing the data received from the first data starting position in a cache area.

4. The data packet parsing method of claim 2, wherein, The step of recording the evaluated data length of the data received from the first data starting position further comprises the following steps: if the evaluated data length is less than the preset length of the packet header, continuing to receive data.

5. The data packet parsing method of claim 2, wherein, The step of judging validity of the packet tail further comprises the following steps: if the packet tail is invalid, setting a second data starting position of a packet header to be evaluated at a specified number of data positions after the first data starting position.

6. The data packet parsing method of claim 1, wherein, The step of judging validity of the packet tail further comprises the following steps: if the packet tail is invalid, setting a packet header flag to indicate that the packet header has not been detected, and re-acquiring the packet header of the data packet to be acquired.

7. A data packet parsing apparatus, characterized by comprising: The method comprises the following steps: a packet header acquisition module is configured to acquire a packet header of a data packet to be acquired from a data stream being received; a packet header judging module, configured to judge validity of the packet header; a data validity judging module, configured to, if the packet header is valid, acquire a received data length of the data packet to be acquired, judge validity of the received data length, judge whether the received data length is less than a minimum data packet length, and judge whether the received data length is not greater than a maximum data packet length if the received data length is not less than the minimum data packet length; if the received data length is less than the maximum data packet length, judge whether a starting receiving position of a current data packet is same as a preset starting position of the data packet, determine the minimum data packet length as a first total data packet length and determine the received data length as valid if the starting receiving position of the current data packet is same as the preset starting position of the data packet, calculate a second total data packet length if the starting receiving position of the current data packet is not same as the preset starting position of the data packet, judge whether the received data length is equal to the second total data packet length, and determine the received data length as valid if the received data length is equal to the second total data packet length; a packet tail acquiring module, configured to acquire a packet tail of the data packet to be acquired if the received data length is valid; a packet tail judging module, configured to judge validity of the packet tail; a data packet acquiring module, configured to acquire the data packet to be acquired according to the packet header and the packet tail if the packet tail is valid.

8. A computer device comprising a memory, a processor, and computer readable instructions stored in the memory and executable on the processor, wherein, The processor implements the data packet analysis method in any one of claims 1 to 6 when executing the computer readable instructions.

9. One or more readable storage media storing computer readable instructions, which are executed by one or more processors to cause the one or more processors to implement the data packet analysis method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method for capturing attitude information of virtual reality device

    CN106648085A

  • Universal serial port data analysis method

    CN110704356A