Message processing method, device, storage medium and electronic device
By determining the bit width and priority of the message fields and processing the message fields in order, the problem of low efficiency of message checksum calculation is solved, and efficient and fast checksum calculation is achieved.
Patent Information
- Application Number
- CN202111663239.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2041-12-30
AI Technical Summary
In the prior art, message checksum calculation efficiency is low and requires complex preliminary operations and field editing.
By determining the bit width and priority of the message fields, processing the message fields in a processing order, and calculating the target checksum, the operation process is simplified and the calculation speed is improved.
The calculation efficiency of the message checksum is improved while ensuring the accuracy of the checksum calculation.
Smart Images

Figure CN116418752B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of message processing, and in particular, to a message processing method, device, storage medium, and electronic device. Background Art
[0002] In recent years, with the rapid development of information technology, the amount of data exchange on the network has become larger and larger, and the processing capacity of chips has continued to increase, which requires the processing of data messages to become more and more flexible. In practical applications, in order to ensure the consistency of messages after processing, checksums are widely used as a means of verifying message consistency.
[0003] Traditional checksum calculations are based on editing specific fields, such as changes in the IP packet's TTL or DSCP field. Therefore, when updating a checksum, an incremental calculation method is used. For example, the original checksum in the packet is incrementally calculated, taking into account the original and updated TTL values to obtain a new checksum. This incremental calculation then takes into account the original and updated DSCP values to obtain the final checksum, which is then entered into the packet. This calculation method requires pre-editing and partitioning each packet field, as well as setting specific fields, which necessitates complex preliminary operations.
[0004] Currently, no effective solution has been proposed to the problem of low message checksum calculation efficiency in related technologies. Summary of the Invention
[0005] Embodiments of the present invention provide a message processing method, device, storage medium, and electronic device to at least solve the problem of low message checksum calculation efficiency existing in related technologies.
[0006] According to one embodiment of the present invention, a method for processing a message is provided, comprising: obtaining a target message for which a checksum is to be calculated in a message processing device; determining a processing order of the multiple message fields based on the field bit width and field priority of each message field in the multiple message fields included in the target message, wherein the processing order is used to indicate the processing timing of each message field in the multiple message fields in the message checksum determination process, and the field priority is the priority between message fields with the same field bit width; in accordance with the processing order, the multiple message fields are processed according to the field bit width of each message field and the field position of each message field in the target message to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message.
[0007] Optionally, the processing order of the multiple message fields is determined based on the field information field width and field priority of each message field in the multiple message fields included in the target message, including: determining the message fields whose corresponding field bit width is a first value in the multiple message fields as a first field set, and determining the message fields whose corresponding field bit width is a second value in the multiple message fields as a second field set, wherein the field bit width of the message field is divided into the first value and the second value; determining the processing order to first process the first message field in the first field set according to the field priority corresponding to the first message field included in the first field set, and then process the second message field in the second field set according to the field priority corresponding to the second message field included in the second field set.
[0008] Optionally, the method of determining the message fields whose corresponding field bit width in the multiple message fields is a first value as a first field set, and determining the message fields whose corresponding field bit width in the multiple message fields is a second value as a second field set, includes: determining that the first value is 8 bits and the second value is 4 bits; determining the message fields whose corresponding field bit width in the multiple message fields is 8 bits as the first field set, and determining the message fields whose corresponding field bit width in the multiple message fields is 4 bits as the second field set.
[0009] Optionally, the multiple message fields are processed in accordance with the processing order and according to the field bit width of each message field and the field position of each message field in the target message to obtain the target checksum corresponding to the target message, including: traversing each message field as the target message field in the processing order; storing the target message field in the target collection position of the collector corresponding to the target field bit width and target field position of the target message field in multiple initial collectors to obtain multiple target collectors, wherein each of the initial collectors is divided into multiple collection positions that conform to the field bit width of the message field; calculating the check value of the message field stored in each target collector in the multiple target collectors to obtain multiple check values; and determining the cumulative sum of the multiple check values as the target checksum.
[0010] Optionally, the storing of the target message field at the target collection position of a collector corresponding to the target field bit width and target field position of the target message field in multiple initial collectors includes: determining the target scale position of the target field position in the target unit scale, wherein the target message is divided into multiple unit scales, and the target unit scale is the unit scale where the target message field is located in the multiple unit scales; according to the collection order of the multiple initial collectors, obtaining from the multiple initial collectors candidate collectors whose collection positions corresponding to the target scale positions do not store data, wherein the data collection amount of each of the initial collectors is equal to the data amount of one unit scale; and storing the target message field at the collection position corresponding to the target scale position in the candidate collector as the target collection position.
[0011] Optionally, before determining the target scale position of the target field position in the target unit scale, the method further includes: obtaining the checksum calculation granularity corresponding to the message checksum determination process; and determining the checksum calculation granularity as the data amount of one unit scale.
[0012] Optionally, after processing the multiple message fields to obtain a target checksum corresponding to the target message, the method further includes: when the message processing device is a message sending device, adding the target checksum to the target message to obtain a message to be sent, wherein the message sending device is used to send the message to be sent; when the message processing device is a message receiving device, comparing the target checksum with a reference checksum carried in the target message to obtain a first comparison result, wherein the message receiving device is used to perform a message processing operation corresponding to the first comparison result on the target message; when the message processing device is a message conversion device, and the target message includes a message before conversion and a message after conversion, comparing the target checksum corresponding to the message before conversion with the target checksum corresponding to the message after conversion to obtain a second comparison result, wherein the message conversion device is used to determine that the message conversion is successful when the second comparison result indicates that the target checksum corresponding to the message before conversion matches the target checksum corresponding to the message after conversion.
[0013] According to another embodiment of the present invention, a message processing device is also provided, including: a first acquisition module, used to acquire a target message for which a checksum is to be calculated in a message processing device; a first determination module, used to determine a processing order of the multiple message fields according to the field bit width and field priority of each message field in the multiple message fields included in the target message, wherein the processing order is used to indicate the processing timing of each message field in the multiple message fields in the message checksum determination process, and the field priority is the priority between message fields with the same field bit width; a processing module, used to process the multiple message fields according to the field bit width of each message field and the field position of each message field in the target message in accordance with the processing order, to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message.
[0014] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.
[0015] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.
[0016] According to the present invention, a target message to be checked and calculated in a message processing device is obtained; a processing order of the plurality of message fields is determined according to the field bit width and field priority of each message field in the plurality of message fields included in the target message, wherein the processing order is used to indicate the processing timing of each message field in the message checksum determination process, and the field priority is the priority between message fields with the same field bit width; according to the processing order, the plurality of message fields are processed according to the field bit width of each message field and the field position of each message field in the target message, to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message, that is, according to the field bit width, word position and field priority of the message. The checksum of the message is calculated based on the segment priority and field position, and the processing order of multiple message fields in the target message is determined according to the field width and field priority of the message, so as to know the processing time of each field in the message. When performing the checksum processing of the message, multiple fields of the message are processed according to the field width and the position of the field in the message, thereby realizing the calculation of the checksum of the message according to the field width of the message, without the need to perform complicated labeling work on the field names in the message when performing the checksum calculation, simplifying the operation process and calculation speed, thereby realizing efficient and fast calculation of the checksum while ensuring the accuracy of the checksum calculation, and thus solving the problem of low efficiency of message checksum calculation in the related technology, and achieving the effect of improving the calculation efficiency of the message checksum. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 This is a block diagram of the hardware structure of a mobile terminal according to the message processing method of an embodiment of the present invention;
[0018] Figure 2 is a flowchart of a method for processing a message according to an embodiment of the present invention;
[0019] Figure 3 is a schematic diagram of message calibration according to an embodiment of the present invention;
[0020] Figure 4 is a schematic diagram of optional message editing information according to an embodiment of the present invention;
[0021] Figure 5 is a schematic diagram of an optional message field writing collector according to an embodiment of the present invention;
[0022] Figure 6 is an optional checksum calculation flow chart according to an embodiment of the present invention;
[0023] Figure 7 It is a structural block diagram of a message processing device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with embodiments.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0026] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG is a block diagram of the hardware structure of a mobile terminal according to the method for processing messages in an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0027] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the message processing method in the embodiment of the present invention. The processor 102 executes the computer program stored in the memory 104 to execute various functional applications and data processing, that is, to implement the above-mentioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0028] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the mobile terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In one embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0029] In this embodiment, a method for processing a message is provided. Figure 2 Flowchart of a method for processing a message according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0030] Step S202: Obtain the target message for which the checksum is to be calculated from the message processing device;
[0031] Step S204: Determine a processing order of the multiple message fields included in the target message based on the field width and field priority of each message field, wherein the processing order is used to indicate the processing timing of each message field in the message checksum determination process, and the field priority is the priority between message fields with the same field width.
[0032] Step S206: Process the multiple message fields in accordance with the processing order and based on the field bit width of each message field and the field position of each message field in the target message to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message.
[0033] Through the above steps, the checksum of the message is calculated according to the field bit width, field priority and field position of the message, and the processing order of multiple message fields in the target message is determined according to the field bit width and field priority of the message, thereby knowing the processing timing of each field in the message, and processing the multiple fields of the message according to the field bit width and the position of the field in the message when performing the checksum processing of the message, thereby realizing the calculation of the checksum of the message according to the field bit width of the message, without the need to perform complicated labeling work on the field names in the message when performing the checksum calculation, simplifying the operation process and calculation speed, thereby realizing efficient and fast calculation of the checksum while ensuring the accuracy of the checksum calculation, thereby solving the problem of low efficiency of message checksum calculation existing in the related art, and achieving the effect of improving the calculation efficiency of the message checksum.
[0034] In the technical solution provided in the above step S202, the message processing device may include but is not limited to a router, a switch, a server, etc.
[0035] Optionally, in this embodiment, the format of the target message of this solution is not limited. For example, the target message may include, but is not limited to, a message in IPv4 format or a message in IPv6 format.
[0036] In the technical solution provided in the above step S204, the priority of the field can be determined according to the order of the fields in the message, or according to the order of editing when editing the message, or according to the bit width of the field. This solution does not limit this.
[0037] Optionally, in this embodiment, the processing order can be the processing order of each field classification after multiple fields are classified. The field classification can be classified according to the field bit width, or according to the characters included in the field. This solution does not limit this.
[0038] In the technical solution provided in the above step S206, the processing of multiple message fields may include, but is not limited to, field sorting, field grouping, editing, checking and calculating the fields in the storage area in the sorted order, and the like.
[0039] Optionally, in this embodiment, the message processing operation may include but is not limited to message editing, message forwarding, and other operations.
[0040] As an optional embodiment, determining the processing order of the multiple message fields according to the field information field bit width and field priority of each message field in the multiple message fields included in the target message includes:
[0041] Determining message fields whose corresponding field bit widths among the multiple message fields are a first value as a first field set, and determining message fields whose corresponding field bit widths among the multiple message fields are a second value as a second field set, wherein the field bit widths of the message fields are divided into the first value and the second value;
[0042] The processing order is determined to first process the first message field in the first field set according to the field priority corresponding to the first message field included in the first field set, and then process the second message field in the second field set according to the field priority corresponding to the second message field included in the second field set.
[0043] Optionally, in this embodiment, the first value may be set to 4, 6, 8, etc.
[0044] Optionally, in this embodiment, the second value can be set to 4, 8, 12, 16, etc.
[0045] Optionally, in this embodiment, the first message field in the first field set and the second message field in the second field set are used to determine the calculation timing of the first message field and the second message field when performing the calculation. This can be done by storing the first message field and the second message field in a target register, wherein the target register includes multiple register units, and the bit width of each register unit is equal to the calculation granularity of the checksum calculation. By storing the first message field and the second message field in the register in sequence, the calculation unit obtained by combining the first message field and the second message field can meet the calculation granularity of the checksum calculation.
[0046] As an optional embodiment, determining the message fields whose corresponding field bit widths among the multiple message fields are the first value as the first field set, and determining the message fields whose corresponding field bit widths among the multiple message fields are the second value as the second field set, includes:
[0047] Determine that the first value is 8 bits and the second value is 4 bits;
[0048] The corresponding message fields with a field width of 8 bits among the multiple message fields are determined as a first field set, and the corresponding message fields with a field width of 4 bits among the multiple message fields are determined as a second field set.
[0049] Optionally, in this embodiment, the first value and the second value may also be set to other values, such as 12 bits, 16 bits, etc.
[0050] As an optional embodiment, the processing of the multiple message fields according to the processing order and the field bit width of each message field and the field position of each message field in the target message to obtain a target checksum corresponding to the target message includes:
[0051] Traversing each message field as a target message field in the processing order;
[0052] Storing the target message field at a target collection position of a collector corresponding to a target field bit width and a target field position of the target message field in a plurality of initial collectors, to obtain a plurality of target collectors, wherein each of the initial collectors is divided into a plurality of collection positions that conform to the field bit width of the message field;
[0053] Performing check value calculation on the message field stored in each target collector of the multiple target collectors to obtain multiple check values;
[0054] An accumulated sum of the multiple check values is determined as the target check sum.
[0055] Optionally, in this embodiment, the field bit width that the initial collector can store matches the calculation granularity during checksum calculation. For example, if the checksum calculation is performed at a granularity of 16 bits, the maximum field bit width that the initial collector can store can be set to 8, 16, etc.
[0056] Through the above steps, by setting the collector, the target message field is stored in the target collection position of the corresponding collector according to the field bit width and the target field position, thereby ensuring the calculation order between the various message fields during the checksum calculation, avoiding the impact of different calculation orders on the consistency of the message field checksum, and improving the reliability and consistency of the calculated checksum.
[0057] As an optional embodiment, storing the target message field at a target collection position of a collector corresponding to a target field bit width and a target field position of the target message field in the multiple initial collectors includes:
[0058] Determining a target scale position of the target field position in a target unit scale, wherein the target message is divided into a plurality of unit scales, and the target unit scale is a unit scale where the target message field is located in the plurality of unit scales;
[0059] According to the collection order of the multiple initial collectors, candidate collectors having no data stored in the collection position corresponding to the target scale position are obtained from the multiple initial collectors, wherein the data collection amount of each initial collector is equal to the data amount of one unit scale;
[0060] The target message field is stored by taking the collection position corresponding to the target scale position in the candidate collector as the target collection position.
[0061] Optionally, in this embodiment, the data volume of a unit ruler matches the calculation granularity of the checksum. For example, the data volume of a unit ruler can be set to be equal to the calculation granularity or a multiple of the calculation granularity. This solution does not limit this.
[0062] Figure 3 : is a schematic diagram of message calibration according to an embodiment of the present invention, such as Figure 3 As shown, it can include but is not limited to the following: the data volume of a unit ruler is 16 bits, and the unit ruler is used to calibrate the editing position in the message. Figure 3In the , multiple unit rulers are used to calibrate a message. Each unit ruler can be divided into four 4-bit editing positions and two 8-bit editing positions, thereby calibrating the relative positions of various bit-width fields in the message.
[0063] Figure 4 This is a schematic diagram of optional message editing information according to an embodiment of the present invention. This embodiment is only an illustrative example. Figure 4 As shown, it can include but is not limited to the following contents: the message includes 5 groups of 4-bit editing information (i.e., message fields) and 5 groups of 8-bit editing information (i.e., message fields). The editing information is sorted according to the importance or order of each editing information when editing the message, so as to determine the order of each message field in being stored in the collector. The figure shows the order of each field in the message. Figure 3 The relative position of the ruler in the message and the order in which each message field is edited into the memory are shown in the figure. As shown in the figure, g4[0] is the first to be edited into the collector in the 4-bit editing information, and g4[0] is the second position in the 4-bit relative position. g8[0] is the first to be edited into the collector in the 8-bit editing information, and g8[0] is the eighth position in the 8-bit relative position.
[0064] Figure 5 This is a schematic diagram of an optional message field writing collector according to an embodiment of the present invention, which is applied to Figure 3 and Figure 4 Examples of Figure 5 As shown, it can include but is not limited to the following steps. The message includes 5 groups of 4-bit message fields (4-bit editing information) and 5 groups of 8-bit message fields (8-bit editing information). When editing the message fields into the editor, the 8-bit message fields are edited into the collector first, and each 8-bit message field is edited into the mobile phone according to its relative position in the unit ruler in the message to occupy a place, as shown in FIG. Figure 4 and Figure 5As shown, g8[0] is located at the last 8-bit edit position of the unit ruler, so g8[0] is stored at the 8-bit edit position 2 of collector 0, and g8[1] is also located at the last 8-bit edit position of the unit ruler, so the free area of the last 8-bit edit position is searched in the collector in ascending order of the collector number, so g8[1] is edited to the 8-bit edit position 2 of collector 1. Similarly, after editing the other 8-bit messages into the collector, the 4-bit message is edited into the collector according to the same principle. After the 8-bit message and the 4-bit message are all edited, if there is an edit position that is empty, it is filled with the character "0". In this way, all the message fields in the message are edited in the collector. Because the checksum is calculated with a 16-bit granularity, the checksum of one editor is calculated each time, and the checksums of all editors are accumulated to obtain the checksum of the message.
[0065] Figure 6 is an optional checksum calculation flow chart according to an embodiment of the present invention, applied to Figures 3 to 5 In the embodiment, Figure 6 As shown, it may include but is not limited to the following:
[0066] S601, message editing processing information includes 4-bit editing and 8-bit editing. 4-bit editing can find the editable position of the message according to the granularity of 4 bits, that is, the editing offset (offset) is 4 bits, and a 16-bit unit ruler is set for the message to find the relative position of the ruler of each 4-bit field in the message.
[0067] S602, 8-bit editing can find the editable position of the message according to the granularity of 8 bits, that is, the editing offset is 8 bits, and the relative position of each 8-bit field in the message is found.
[0068] S603, in accordance with the priority of placing the 8-bit field, write the edited message field into the corresponding position of the 16-bit collector according to the relative position of the field in the message ruler, and then put in the 4-bit message field. When editing, edit in the order of the collectors, that is, if collector 0 is used up, put it in collector 1 until all mobile phones are full.
[0069] S604: Perform checksum calculation on the fields in each collector, and perform cumulative calculation on the checksums of each collector to obtain the checksum of the message.
[0070] Through the above steps, by setting the unit scale, a basis is provided for placing each message field in the message in the corresponding storage location of the mobile phone, thereby ensuring that the calculation order of the message fields does not change when multiple checksum calculations are performed on a message, thereby improving the consistency of the checksum.
[0071] As an optional embodiment, before determining the target scale position of the target field position in the target unit scale, the method further includes:
[0072] Obtain the checksum calculation granularity corresponding to the message checksum determination process;
[0073] The checksum calculation granularity is determined as the amount of data per unit scale.
[0074] Optionally, in this embodiment, the checksum calculation granularity can be, but is not limited to, set to 16 bits, 32 bits, etc., and this solution does not impose any limitation on this.
[0075] As an optional embodiment, after processing the multiple message fields to obtain the target checksum corresponding to the target message, the method further includes:
[0076] In a case where the message processing device is a message sending device, adding the target checksum to the target message to obtain a message to be sent, wherein the message sending device is used to send the message to be sent;
[0077] When the message processing device is a message receiving device, comparing the target checksum with a reference checksum carried in the target message to obtain a first comparison result, wherein the message receiving device is configured to perform a message processing operation corresponding to the first comparison result on the target message;
[0078] When the message processing device is a message conversion device and the target message includes a message before conversion and a message after conversion, the target checksum corresponding to the message before conversion is compared with the target checksum corresponding to the message after conversion to obtain a second comparison result, wherein the message conversion device is used to determine that the message conversion is successful when the second comparison result indicates that the target checksum corresponding to the message before conversion matches the target checksum corresponding to the message after conversion.
[0079] Optionally, in this embodiment, the target checksum corresponding to the message before conversion and the target checksum corresponding to the message after conversion may be matched but is not limited to being equal to the target checksum corresponding to the message before conversion and the target checksum corresponding to the message after conversion, and this solution does not limit this.
[0080] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0081] This embodiment also provides a message processing device. Figure 7 is a structural block diagram of a message processing device according to an embodiment of the present invention, such as Figure 7 As shown, the device includes:
[0082] A first acquisition module 72 is configured to acquire a target message for which a checksum is to be calculated in a message processing device;
[0083] a first determining module 74, configured to determine a processing order of the multiple message fields included in the target message based on a field width and a field priority of each message field, wherein the processing order indicates a processing timing of each message field in the message checksum determination process, and the field priority is a priority between message fields having the same field width;
[0084] The processing module 76 is used to process the multiple message fields in accordance with the processing order and based on the field bit width of each message field and the field position of each message field in the target message, so as to obtain the target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform the message processing operation corresponding to the target checksum on the target message.
[0085] Optionally, the first determination module includes: a first determination unit, used to determine the message fields whose corresponding field bit widths in the multiple message fields are the first value as a first field set, and to determine the message fields whose corresponding field bit widths in the multiple message fields are the second value as a second field set, wherein the field bit widths of the message fields are divided into the first value and the second value; a second determination unit, used to determine the processing order to first process the first message field in the first field set according to the field priority corresponding to the first message field included in the first field set, and then process the second message field in the second field set according to the field priority corresponding to the second message field included in the second field set.
[0086] Optionally, the first determination unit is used to: determine that the first value is 8 bits and the second value is 4 bits; determine the message fields with a corresponding field width of 8 bits in the multiple message fields as a first field set, and determine the message fields with a corresponding field width of 4 bits in the multiple message fields as a second field set.
[0087] Optionally, the processing module includes: a processing unit, used to traverse each message field as the target message field in the processing order; a storage unit, used to store the target message field in the target collection position of the collector corresponding to the target field bit width and target field position of the target message field in multiple initial collectors, to obtain multiple target collectors, wherein each of the initial collectors is divided into multiple collection positions that conform to the field bit width of the message field; a calculation unit, used to perform check value calculation on the message field stored in each target collector in the multiple target collectors, to obtain multiple check values; a third determination unit, used to determine the cumulative sum of the multiple check values as the target checksum.
[0088] Optionally, the storage unit is used to: determine the target scale position of the target field position in the target unit scale, wherein the target message is divided into multiple unit scales, and the target unit scale is the unit scale where the target message field is located in the multiple unit scales; according to the collection order of the multiple initial collectors, obtain from the multiple initial collectors a candidate collector in which the collection position corresponding to the target scale position does not store data, wherein the data collection amount of each initial collector is equal to the data amount of one unit scale; and store the target message field in the collection position corresponding to the target scale position in the candidate collector as the target collection position.
[0089] Optionally, the device also includes: a second acquisition module, used to obtain the checksum calculation granularity corresponding to the message checksum determination process before determining the target field position at the target scale position in the target unit scale; a second determination module, used to determine the checksum calculation granularity as the data amount of a unit scale.
[0090] Optionally, the device further includes: an adding module for, after processing the multiple message fields to obtain the target checksum corresponding to the target message, adding the target checksum to the target message when the message processing device is a message sending device to obtain a message to be sent, wherein the message sending device is used to send the message to be sent; a first comparison module for, when the message processing device is a message receiving device, comparing the target checksum with a reference checksum carried in the target message to obtain a first comparison result, wherein the message receiving device A device for performing a message processing operation corresponding to the first comparison result on the target message; a second comparison module is used to compare the target checksum corresponding to the message before conversion with the target checksum corresponding to the message after conversion when the message processing device is a message conversion device and the target message includes a message before conversion and a message after conversion, to obtain a second comparison result, wherein the message conversion device is used to determine that the message conversion is successful when the second comparison result indicates that the target checksum corresponding to the message before conversion matches the target checksum corresponding to the message after conversion.
[0091] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0092] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.
[0093] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0094] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0095] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0096] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.
[0097] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0098] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A method for processing a message, characterized in that: include: Obtaining a target message for which a checksum is to be calculated from a message processing device; Determining a processing order of the multiple message fields according to a field bit width and a field priority of each message field in the multiple message fields included in the target message, wherein the processing order is used to indicate a processing timing of each message field in the message checksum determination process, the field priority is a priority between message fields with the same field bit width, and the processing order is a processing order of each field classification obtained after classifying the multiple message fields included in the target message according to the field bit width; In accordance with the processing order, the multiple message fields are processed according to the field bit width of each message field and the field position of each message field in the target message to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message.
2. The method according to claim 1, characterized in that The determining, based on the field information field bit width and field priority of each message field in the multiple message fields included in the target message, a processing order of the multiple message fields includes: Determining message fields whose corresponding field bit widths among the multiple message fields are a first value as a first field set, and determining message fields whose corresponding field bit widths among the multiple message fields are a second value as a second field set, wherein the field bit widths of the message fields are divided into the first value and the second value; The processing order is determined to first process the first message field in the first field set according to the field priority corresponding to the first message field included in the first field set, and then process the second message field in the second field set according to the field priority corresponding to the second message field included in the second field set.
3. The method according to claim 2, characterized in that The determining, among the multiple message fields, message fields whose corresponding field bit width is a first value as a first field set, and determining, among the multiple message fields, message fields whose corresponding field bit width is a second value as a second field set, includes: Determine that the first value is 8 bits and the second value is 4 bits; The corresponding message fields with a field width of 8 bits among the multiple message fields are determined as a first field set, and the corresponding message fields with a field width of 4 bits among the multiple message fields are determined as a second field set.
4. The method according to claim 1, wherein The processing of the plurality of message fields according to the processing order and based on the field bit width of each message field and the field position of each message field in the target message to obtain a target checksum corresponding to the target message includes: Traversing each message field as a target message field in the processing order; Storing the target message field at a target collection position of a collector corresponding to a target field bit width and a target field position of the target message field in a plurality of initial collectors, to obtain a plurality of target collectors, wherein each of the initial collectors is divided into a plurality of collection positions that conform to the field bit width of the message field; Performing check value calculation on the message field stored in each target collector of the multiple target collectors to obtain multiple check values; An accumulated sum of the multiple check values is determined as the target check sum.
5. The method according to claim 4, characterized in that The step of storing the target message field at a target collection position of a collector corresponding to a target field bit width and a target field position of the target message field in the plurality of initial collectors comprises: Determining a target scale position of the target field position in a target unit scale, wherein the target message is divided into a plurality of unit scales, and the target unit scale is a unit scale where the target message field is located in the plurality of unit scales; According to the collection order of the multiple initial collectors, candidate collectors having no data stored in the collection position corresponding to the target scale position are obtained from the multiple initial collectors, wherein the data collection amount of each initial collector is equal to the data amount of one unit scale; The target message field is stored by taking the collection position corresponding to the target scale position in the candidate collector as the target collection position.
6. The method according to claim 5, characterized in that Before determining the target scale position of the target field position in the target unit scale, the method further includes: Obtain the checksum calculation granularity corresponding to the message checksum determination process; The checksum calculation granularity is determined as the amount of data per unit scale.
7. The method according to claim 6, characterized in that After processing the multiple message fields to obtain a target checksum corresponding to the target message, the method further includes: In a case where the message processing device is a message sending device, adding the target checksum to the target message to obtain a message to be sent, wherein the message sending device is used to send the message to be sent; When the message processing device is a message receiving device, comparing the target checksum with a reference checksum carried in the target message to obtain a first comparison result, wherein the message receiving device is configured to perform a message processing operation corresponding to the first comparison result on the target message; When the message processing device is a message conversion device and the target message includes a message before conversion and a message after conversion, the target checksum corresponding to the message before conversion is compared with the target checksum corresponding to the message after conversion to obtain a second comparison result, wherein the message conversion device is used to determine that the message conversion is successful when the second comparison result indicates that the target checksum corresponding to the message before conversion matches the target checksum corresponding to the message after conversion.
8. A message processing device, characterized in that: include: A first acquisition module is used to acquire a target message for which a checksum is to be calculated in a message processing device; a first determination module, configured to determine a processing order of the multiple message fields included in the target message based on a field bit width and a field priority of each message field in the multiple message fields, wherein the processing order is used to indicate a processing timing of each message field in the message checksum determination process, the field priority is a priority between message fields with the same field bit width, and the processing order is a processing order of each field classification obtained after classifying the multiple message fields included in the target message according to the field bit width; A processing module is used to process the multiple message fields in accordance with the processing order and based on the field bit width of each message field and the field position of each message field in the target message, so as to obtain a target checksum corresponding to the target message, wherein the target checksum is used to instruct the message processing device to perform a message processing operation corresponding to the target checksum on the target message.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data processing method among multiple FPGA chips and conversion device
CN107786471A
Implementation method and equipment for multi-rule flow classification and storage medium
CN112866139A