CN110896391B - Message processing method and device - Google Patents

Message processing method and device Download PDF

Info

Publication number
CN110896391B
CN110896391B CN201811069058.6A CN201811069058A CN110896391B CN 110896391 B CN110896391 B CN 110896391B CN 201811069058 A CN201811069058 A CN 201811069058A CN 110896391 B CN110896391 B CN 110896391B
Authority
CN
China
Prior art keywords
instruction
character
message
character string
header
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811069058.6A
Other languages
Chinese (zh)
Other versions
CN110896391A (en
Inventor
陈晓涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811069058.6A priority Critical patent/CN110896391B/en
Publication of CN110896391A publication Critical patent/CN110896391A/en
Application granted granted Critical
Publication of CN110896391B publication Critical patent/CN110896391B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers

Abstract

The invention discloses a message processing method and device, and relates to the technical field of computers. One embodiment of the method comprises: the following intercepting steps are repeatedly executed on the message until no character exists in the message: determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string exists in the message; when the instruction character string exists, intercepting the instruction character string; when the command front-segment character string exists, storing the command front-segment character string; when the character string of the rear section of the instruction exists, splicing the character string of the rear section of the instruction to the character string of the front section of the instruction, and intercepting the formed instruction character string; and when the condition is not met, searching the instruction head identifier, deleting the characters in front of the instruction head identifier, and when the instruction head identifier is not found, deleting all the characters. The implementation method can completely acquire all instructions in the message.

Description

Message processing method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for processing a packet.
Background
At present, in an intelligent warehouse, a shuttle vehicle is generally configured with a PLC control system, and the PLC control system of the shuttle vehicle obtains an instruction from a warehouse equipment control system by communicating a TCP/IP packet with the warehouse equipment control system.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: since the warehouse equipment control system is a multi-thread system, a plurality of instructions may be sent simultaneously, and in this case, a message sent by the warehouse equipment control system will include a plurality of instructions and there may be a case where the instructions are incomplete. The existing message processing method cannot completely acquire all instructions in the message under the condition, and the problem of instruction loss exists.
Therefore, a message processing method and device capable of completely acquiring all instructions in a message when the message includes multiple instructions are needed.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for processing a message, so that when the message includes multiple instructions, all the instructions in the message can be completely acquired.
In order to achieve the above object, according to an aspect of the embodiments of the present invention, a method for processing a message is provided, where the method is configured to intercept an instruction string from the message, where the instruction string is configured with a head and tail identifier, and the method includes: repeating the following intercepting steps on the message until no character exists in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with a current message header character exists in the message according to the instruction header identifier and/or the instruction tail identifier;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to an instruction front-end character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction back-end character string in the message;
when the message does not have an instruction character string starting from the current message header character, an instruction front-segment character string or an instruction rear-segment character string, searching an instruction header identifier backwards from the current message header character, deleting the character before the found instruction header identifier, and deleting all characters in the message when the instruction header identifier is not found.
Further, the instruction character string is further configured with instruction length information, and determining whether an instruction character string starting with a header character of the current message exists in the message includes:
if the current message header character is an instruction header identification and the instruction length information can be read, determining whether the instruction length is less than or equal to the current message character length, and if so, searching an instruction tail character corresponding to the instruction header identification according to the instruction length;
and judging whether the instruction tail character is an instruction tail identification, and if so, determining that the current message header character, the instruction tail character and the character between the current message header character and the instruction tail character are instruction character strings.
Further, the instruction character string is further configured with instruction length information, and determining whether there is an instruction preceding segment character string starting with a current message header character in the message includes:
if the current message header character is an instruction head identifier and the instruction length information can be read, determining whether the instruction length is greater than the current message character length, and if so, determining all characters in the current message as an instruction front-segment character string; or alternatively
And if the current message header character is an instruction header identifier and the instruction length character segment cannot be read, determining all characters in the current message as the character string of the instruction front segment.
Further, an instruction intercepting state is maintained for the message, after the instruction character string is intercepted, the instruction intercepting state is updated to be completed, after the character string at the front section of the instruction is saved, the instruction intercepting state is updated to be unfinished, after the character before the instruction header identification is found out by deleting, and after all characters in the message are deleted, the instruction intercepting state is updated to be completed;
determining whether there is a post-command string in the message beginning with the current header character includes:
if the current message head character is not the instruction head identification and the current instruction interception state is incomplete, searching an instruction tail identification backwards from the current message head character;
when the instruction tail identification is found, determining the instruction tail identification and the character in the message before the instruction tail identification as the character string of the instruction rear segment;
and determining whether the splicing character string is an instruction character string according to the length of the splicing character string.
In order to achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided a message processing apparatus, where the apparatus is configured to intercept an instruction string from a message, where the instruction string is configured with head and tail identifiers, and the apparatus includes:
the instruction intercepting module is used for repeatedly executing the following intercepting steps on the message until no character exists in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with a current message header character exists in the message according to the instruction header identifier and/or the instruction tail identifier;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction rear-segment character string starting from a current message head character exists, splicing the instruction rear-segment character string to an instruction front-segment character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction rear-segment character string in a message;
when the message does not have an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with the current message header character, searching an instruction header identifier backwards from the current message header character, deleting the character before the found instruction header identifier, and deleting all characters in the message when the instruction header identifier is not found.
Further, the instruction character string is also configured with instruction length information, and the instruction intercepting module is further configured to determine whether the instruction length is smaller than or equal to the current message character length if the current message header character is an instruction header identifier and the instruction length information can be read, and if so, search an instruction tail character corresponding to the instruction header identifier according to the instruction length;
and judging whether the instruction tail character is an instruction tail identification, and if so, determining that the current message header character, the instruction tail character and the character between the current message header character and the instruction tail character are instruction character strings.
Further, the instruction character string is also configured with instruction length information, and the instruction intercepting module is further configured to determine whether the instruction length is greater than the character length of the current message if the current header character of the message is an instruction header identifier and the instruction length information can be read, and determine all characters in the current message as instruction front segment character strings if the instruction length is greater than the character length of the current message; or
And if the current message header character is an instruction head identifier and the instruction length character segment cannot be read, determining all characters in the current message as the instruction front segment character string.
Further, the instruction intercepting module further maintains an instruction intercepting state for the message, updates the instruction intercepting state to be completed after intercepting the instruction character string, updates the instruction intercepting state to be unfinished after saving the character string at the front section of the instruction, updates the instruction intercepting state to be completed after finding the character before the instruction header mark and after deleting all the characters in the message;
the instruction intercepting module is further used for searching an instruction tail identifier backwards from the current message head character if the current message head character is not the instruction head identifier and the current instruction intercepting state is incomplete;
when the instruction tail identification is found, determining the instruction tail identification and the character in the message before the instruction tail identification as the character string of the instruction rear segment;
and determining whether the splicing character string is an instruction character string according to the length of the splicing character string.
In order to achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided a message processing electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the message processing method provided by the embodiment of the invention.
To achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the message processing method provided by the embodiments of the present invention.
Compared with the prior art, the message processing method and the message processing device have the advantages that the message adopts an indefinite-length instruction structure, the phenomenon that excessive placeholders occupy a data receiving cache region is avoided, all contents are disassembled and analyzed after the message is received, the method is suitable for the condition that a plurality of instructions exist in one message, and when an incomplete instruction exists at the tail of the message, the message is temporarily stored and combined with the next received message, so that the instruction loss is avoided as much as possible. Therefore, the defects of the prior art are avoided, and when a plurality of instructions exist in the message, all the instructions in the message can be completely acquired.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram of a main flow of a message processing method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a packet provided in the embodiment of the present invention;
fig. 3 is a schematic diagram of an application flow of a message processing method according to an embodiment of the present invention;
fig. 4 is a schematic diagram of main modules of a message processing apparatus according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 6 is a schematic block diagram of a computer system suitable for use with the electronic device to implement an embodiment of the invention.
Detailed Description
Exemplary embodiments of the invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The embodiment of the invention provides a message processing method, which is used for intercepting an instruction character string from a message, wherein the instruction character string is configured with head and tail identification, and the method comprises the following steps: and repeating the intercepting step on the message until no character exists in the message. As shown in fig. 1, the intercepting step includes: step S101 and step S102.
In step S101, it is determined whether an instruction character string, an instruction preceding-stage character string, or an instruction succeeding-stage character string starting with a header character of the current message exists in the message according to the instruction header identifier and/or the instruction trailer identifier.
In step S102, when there is an instruction string starting with the current message header character, the instruction string is intercepted and deleted in the message.
And when the command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message.
And when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to the instruction front-end character string to form a spliced character string, and intercepting the instruction character string and deleting the instruction back-end character string in the message after determining that the spliced character string is the instruction character string.
When the message does not have an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with the current message header character, searching an instruction header identifier backwards from the current message header character, deleting the character before the found instruction header identifier, and deleting all characters in the message when the instruction header identifier is not found.
In an embodiment of the present invention, the instruction character string is further configured with instruction length information, and in step S101, the process of determining whether an instruction character string starting with a header character of the current packet exists in the packet specifically includes:
if the current message header character is the instruction header identification and the instruction length information can be read, determining whether the instruction length is less than or equal to the current message character length, and if so, searching the instruction tail character corresponding to the instruction header identification according to the instruction length.
And then judging whether the instruction tail character is an instruction tail identification, and if so, determining that the current message header character, the instruction tail character and the character between the two are instruction character strings.
In an embodiment of the present invention, the instruction character string is further configured with instruction length information, and in step S101, the process of determining whether there is an instruction previous-segment character string starting with a header character of the current message in the message specifically includes:
if the current message header character is the instruction head identification and the instruction length information can be read, determining whether the instruction length is larger than the current message character length, and if so, determining all characters in the current message as the instruction front segment character string.
Or if the current message header character is the instruction head identifier and the instruction length character segment cannot be read, determining all characters in the current message as the instruction front segment character string.
In one embodiment of the present invention, an instruction interception status is maintained for a packet, the instruction interception status is updated to be completed after intercepting an instruction string, the instruction interception status is updated to be incomplete after saving a preceding-stage character string of the instruction, and the instruction interception status is updated to be completed after deleting a character found before an instruction header identification and after deleting all characters in the packet.
In step S101, the process of determining whether there is a command post-segment character string starting with the header character of the current message in the message is specifically:
if the current message head character is not the instruction head identification and the current instruction interception state is incomplete, searching the instruction tail identification backwards from the current message head character.
And then when the instruction tail identification is found, determining that the instruction tail identification and the character in the message before the instruction tail identification are the character string of the instruction rear segment. And then determining whether the spliced character string is an instruction character string or not according to the length of the spliced character string.
The message processing method provided by the present invention is further described below with a specific application scenario. In the application scene, the method is applied to a shuttle car in an intelligent warehouse, and is used for processing the TCP/IP message received by the shuttle car and sent by a warehouse equipment control system and intercepting the control instruction in the message.
In the application scenario, the instruction content includes the length of the character string occupied by the content of the instruction content. The specific instruction format is shown in fig. 2, and includes: a head character "[" of 1Byte, instruction length information of 2Byte, instruction contents of XXByte, and a tail character "]" of 1 Byte.
In the application scenario, the number of instructions contained in each message does not exceed 10, and a command array STR [10] of a character string type is set at the shuttle end, and the command buffer STR _ Buff and the completion status bit Fin are intercepted.
As shown in fig. 3, after receiving the message, the message is stored in the character string Data.
First, the array pointer M is set to 0. The following steps are circularly executed to process the message Until no character exists in the Data any more by utilizing Repeat 8230and Until 8230.
When the first character of the message is correct, the instruction length can be obtained:
obtaining the instruction length, and obtaining the position of the tail character according to the instruction length;
it is determined whether the position of the tail character is "]", if so, the instruction is validated, the intercepted instruction is placed in STR [ M ], and the instruction is deleted from Data. The pointer M is automatically increased by 1 to finish the setting of the state position Fin to 1;
if not, the proving instruction is invalid and the invalid instruction is deleted. Searching a first character "[", if found, deleting the content in front of the "[", and setting a completion status Fin to be 1; otherwise, all the characters of Data are deleted, and the completion status Fin is set to 1.
For example, a message of [19ACKPTR 5033859100] [19ACKSTR 5033860002] "is used:
the length of the first instruction in the message Data is 19 characters (not including the beginning character and the end character [ ]) and the message length character, and one space occupies one character).
Counting from the character "A", it is judged whether the 20 th (= 19+ 1) character is "]". If yes, the first instruction is proved to be valid, the first instruction is intercepted into STR [1], and then the first instruction in the message is deleted.
The instruction store is complete, M changes from 1 to 2, and the value of the completion status bit Fin is set to 1.
If not, the first instruction is proved to be invalid, the first character "[" is searched from the 2 nd character, and if the first character "[" can be found, the message is proved to possibly contain other valid instructions, and invalid data in front of the first character "[" is deleted; if not, it is proved that there is no other effective instruction in the message, and all the information in the message is deleted.
The invalid instruction deletes completion, setting the value of the completion status bit Fin to 1.
When the first character of the message is correct, the instruction length is not available:
this is typically the case when the instruction has only 2 characters in this message, the rest being in the next message.
All Data contents are copied into STR _ Buff, all Data contents are deleted, and a completion status bit Fin is set to be 0.
For example, the message of [19ACKPTR 5033859100] [19ACKSTR 5033860002] [1 ":
the first character is correct, and the third instruction is not completely received due to the limited length of the Data of the message, and other contents of the third instruction are definitely in the next message.
When the third instruction is processed, the content in the message Data is "[1 ].
And storing the content in the message Data in a Data cache STR _ Buff, deleting all the content in the message Data, wherein the instruction is not completely stored, and setting the value of a completion state Fin to be 0.
When the first character of the message is incorrect, the completion status bit is 1:
in this case, the interception of the previous instruction is completed, the first character check of the current instruction fails, and the current instruction is invalid. And deleting the invalid instruction.
Searching the first character "[", if found, deleting the content before "[", and setting the completion status bit Fin to be 1; otherwise, all the characters of Data are deleted, and the completion status Fin is set to 1.
For example, the message of "3] [19ACKPTR 5033859100] [19ACKSTR 5033860002]" is used as follows:
the completion status bit has a value of 1, indicating that the previous instruction has completed storing and that the data cache STR _ Buff has no data.
If a message Data is lost, two effective instructions in the message can be deleted if the whole message is deleted, and in order to avoid the situation, the first character "[" can be searched in the current message Data.
If the data is found, the current message possibly contains other effective instructions, and invalid data in front of the first character is deleted; if not, it is proved that there is no other effective instruction in the message, and all the information in the message is deleted.
The invalid instruction deletes completion, setting the value of the completion status bit Fin to 1.
When the first character of the message is incorrect, the completion status bit is 0:
in this case, the first half of the current instruction is in the previous message, and the two parts of the current instruction need to be merged, and then checked whether the instruction is valid, and if the instruction is invalid, the instruction is deleted.
Searching the tail character "]", if found, cutting out the contents before "]" and "]", splicing the contents behind STR _ Buff, and storing the contents in STR _ Buff.
The instruction length is obtained in STR _ Buff:
if the instruction is correct based on the instruction length, the instruction is intercepted to STR [ M ], and the STR _ Buff, as well as the portion of the Data that is the contents of the instruction, is deleted. The pointer M is self-increased by 1, and the completion status Fin is set to be 1.
If the instruction length is incorrect, searching the first character "[", if found, deleting the content before "[", and setting the completion status Fin to be 1; if not, all the characters in Data are deleted and the completion status Fin is set to 1.
For example, a message of 9ACKPTR 5033859100] [19ACKSTR 5033860002 ]:
the completion status bit has a value of 0, indicating that the previous instruction did not complete the store, and that there is data in the data buffer STR _ Buff.
First, the tail character "]" is searched in the message Data.
If not, it indicates that there are no other effective instructions in the message, and deletes all the information in the message Data.
The invalid instruction deletes completion, setting the value of the completion status bit Fin to 1.
If found, the tail character "]" and its preceding contents are intercepted, concatenated with the contents of the data buffer STR _ Buff, and placed back into the data buffer STR _ Buff.
If the previous data in the cache region STR _ Buff is '1', the spliced data becomes '19ACKPTR 5033859100', the instruction is successfully verified, the instruction is stored into the STR [2], and the data cache region STR _ Buff is emptied. The instruction store is complete, M changes from 2 to 3, and the completion status bit Fin is set to a value of 1.
If the previous data in the buffer STR _ Buff is "[", the spliced data becomes "[ 9acktr 5033859100]", the instruction verification is unsuccessful, and the data buffer STR _ Buff is emptied. The first character "[" is searched for in the message Data.
If the data is found, the current message possibly contains other effective instructions, and invalid data in front of the first character is deleted; if not, it is proved that there is no other effective instruction in the message, and all the information in the message is deleted.
The invalid instruction is deleted and the completion status bit Fin is set to a value of 1.
If none of the above conditions are met. This case indicates that the Data in the current message is invalid, all Data is deleted, and the completion status bit Fin is set to 1.
An embodiment of the present invention further provides a message processing apparatus, where the apparatus is configured to intercept an instruction character string from a message, where the instruction character string is configured with a head and tail identifier, as shown in fig. 4, and the apparatus 400 includes: instruction intercept module 401.
The instruction intercepting module 401 is configured to repeatedly execute the following intercepting steps on the message until there is no character in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with a current message header character exists in the message according to the instruction header identifier and/or the instruction tail identifier;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to an instruction front-end character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction back-end character string in the message;
when the message does not have an instruction character string starting from the current message header character, an instruction front-segment character string or an instruction rear-segment character string, searching an instruction header identifier backwards from the current message header character, deleting the character before the found instruction header identifier, and deleting all characters in the message when the instruction header identifier is not found.
In the invention, the instruction character string is also configured with instruction length information, and the instruction intercepting module is further used for determining whether the instruction length is less than or equal to the character length of the current message or not if the current message header character is the instruction header identifier and the instruction length information can be read, and searching the instruction tail character corresponding to the instruction header identifier according to the instruction length if the instruction length is less than or equal to the character length of the current message.
And judging whether the instruction tail character is an instruction tail identification, and if so, determining that the current message header character, the instruction tail character and the character between the current message header character and the instruction tail character are instruction character strings.
In the invention, the instruction character string is also configured with instruction length information, and the instruction intercepting module is further used for determining whether the instruction length is greater than the character length of the current message or not if the current message header character is an instruction head identifier and the instruction length information can be read, and if so, determining that all characters in the current message are the character string of the instruction front section.
Or if the current message header character is the instruction head identifier and the instruction length character segment cannot be read, determining all characters in the current message as the instruction front segment character string.
In the invention, the instruction interception module further maintains an instruction interception state for the message, updates the instruction interception state to be completed after intercepting the instruction character string, updates the instruction interception state to be unfinished after saving the character string at the front section of the instruction, and updates the instruction interception state to be completed after deleting the character before finding the instruction header mark and deleting all characters in the message.
The instruction intercepting module is further used for searching an instruction tail identifier backwards from the current message head character if the current message head character is not the instruction head identifier and the current instruction intercepting state is incomplete.
And when the instruction tail identification is found, determining that the instruction tail identification and the character in the message before the instruction tail identification are the character string of the instruction rear section.
And determining whether the spliced character string is an instruction character string or not according to the length of the spliced character string.
The message processing method and the device provided by the invention have the advantages that the message adopts an indefinite-length instruction structure, so that the phenomenon that excessive placeholders occupy a data receiving cache region is avoided. Therefore, the defects of the prior art are avoided, and when a plurality of instructions exist in the message, all the instructions in the message can be completely acquired.
Fig. 5 shows an exemplary system architecture 500 to which the message processing method or the message processing apparatus according to the embodiments of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 501, 502, 503.
The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server that provides various services, such as a background management server that intercepts instructions from messages.
It should be noted that the message processing method provided in the embodiment of the present invention is generally executed by the server 505, and accordingly, the message processing apparatus is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 are merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU) 601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present invention, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an instruction intercept module. Wherein the names of the modules do not in some way constitute a limitation on the modules themselves.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not assembled into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
repeating the following intercepting steps on the message until no character exists in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with a current message header character exists in the message according to the instruction header identifier and/or the instruction tail identifier;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to an instruction front-end character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction back-end character string in the message;
when the message does not have an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with the current message header character, searching an instruction header identifier backwards from the current message header character, deleting the character before the found instruction header identifier, and deleting all characters in the message when the instruction header identifier is not found.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A message processing method is characterized in that the method is used for intercepting an instruction character string from a message, the instruction character string is configured with head and tail identification, and the method comprises the following steps: repeating the following intercepting steps on the message until no character exists in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts from a current message head character exists in the message or not according to the instruction head identification and/or the instruction tail identification;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from a current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to an instruction front-end character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction back-end character string in the message;
when the message does not have an instruction character string starting from the current message header character, an instruction front-segment character string or an instruction rear-segment character string, searching an instruction header identifier backwards from the current message header character, deleting the character before the instruction header identifier is found, and deleting all characters in the message when the instruction header identifier is not found.
2. The method of claim 1, wherein the instruction string is further configured with instruction length information, and wherein determining whether an instruction string beginning with a current header character exists in the message comprises:
if the current message header character is an instruction header identifier and the instruction length information can be read, determining whether the instruction length is less than or equal to the current message character length, and if so, searching an instruction tail character corresponding to the instruction header identifier according to the instruction length;
and judging whether the command tail character is a command tail identification, if so, determining that the current message header character, the command tail character and the character between the current message header character and the command tail character are command character strings.
3. The method of claim 1, wherein the command string is further configured with command length information, and wherein determining whether a command preceding segment string beginning with a current header character exists in the message comprises:
if the current message header character is an instruction header identifier and the instruction length information can be read, determining whether the instruction length is larger than the current message character length, and if so, determining all characters in the current message as an instruction front-segment character string; or
And if the current message header character is an instruction header identifier and the instruction length character segment cannot be read, determining all characters in the current message as the character string of the instruction front segment.
4. The method of claim 1, wherein an instruction intercept state is maintained for the message, the instruction intercept state is updated to be completed after the instruction string is intercepted, the instruction intercept state is updated to be incomplete after the instruction string preceding stage is saved, the instruction intercept state is updated to be completed after the character before the instruction header identifier is found by the deletion and when all characters in the message are deleted;
determining whether an instruction post-field character string beginning with a current message header character exists in the message comprises:
if the current message head character is not the instruction head identification and the current instruction interception state is incomplete, searching an instruction tail identification backwards from the current message head character;
when the instruction tail identification is found, determining the instruction tail identification and the character in the message before the instruction tail identification as the character string of the instruction rear segment;
and determining whether the spliced character string is an instruction character string or not according to the length of the spliced character string.
5. A message processing apparatus, wherein the apparatus is configured to intercept an instruction string from a message, where the instruction string is configured with a head-to-tail identifier, and the apparatus includes:
the instruction intercepting module is used for repeatedly executing the following intercepting steps on the message until no character exists in the message:
determining whether an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with a current message header character exists in the message according to the instruction header identifier and/or the instruction tail identifier;
when an instruction character string starting from the head character of the current message exists, intercepting the instruction character string and deleting the instruction character string in the message;
when a command front-segment character string starting from the current message head character exists, storing the command front-segment character string and deleting the command front-segment character string in the message;
when an instruction back-end character string starting from the current message head character exists, splicing the instruction back-end character string to an instruction front-end character string to form a spliced character string, and after determining that the spliced character string is an instruction character string, intercepting the instruction character string and deleting the instruction back-end character string in the message;
when the message does not have an instruction character string, an instruction front-segment character string or an instruction rear-segment character string which starts with the current message header character, searching an instruction header identifier backwards from the current message header character, deleting the character before the instruction header identifier is found, and deleting all characters in the message when the instruction header identifier is not found.
6. The apparatus according to claim 5, wherein the instruction string is further configured with instruction length information, and the instruction intercepting module is further configured to determine whether the instruction length is smaller than or equal to the current packet character length if the current header character is an instruction header identifier and the instruction length information can be read, and if so, search an instruction tail character corresponding to the instruction header identifier according to the instruction length;
and judging whether the command tail character is a command tail identification, if so, determining that the current message header character, the command tail character and the character between the current message header character and the command tail character are command character strings.
7. The device according to claim 5, wherein the command string is further configured with command length information, and the command intercepting module is further configured to determine whether the command length is greater than the current message character length if the current message header character is a command header identifier and the command length information can be read, and if so, determine that all characters in the current message are a command front-end character string; or
And if the current message header character is an instruction header identifier and the instruction length character segment cannot be read, determining all characters in the current message as the character string of the instruction front segment.
8. The apparatus according to claim 5, wherein the instruction intercepting module further maintains an instruction intercepting status for the message, updates the instruction intercepting status to be completed after intercepting the instruction string, updates the instruction intercepting status to be unfinished after saving the instruction front-end string, updates the instruction intercepting status to be completed after finding the character before the instruction header identification by the deleting, and when deleting all the characters in the message;
the instruction intercepting module is further used for searching an instruction tail identifier backwards from the current message head character if the current message head character is not the instruction head identifier and the current instruction intercepting state is incomplete;
when the instruction tail identification is found, determining the instruction tail identification and the character in the message before the instruction tail identification as the character string of the instruction rear segment;
and determining whether the spliced character string is an instruction character string or not according to the length of the spliced character string.
9. An electronic device for message processing, comprising:
one or more processors;
a storage device for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method recited in any of claims 1-4.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-4.
CN201811069058.6A 2018-09-13 2018-09-13 Message processing method and device Active CN110896391B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811069058.6A CN110896391B (en) 2018-09-13 2018-09-13 Message processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811069058.6A CN110896391B (en) 2018-09-13 2018-09-13 Message processing method and device

Publications (2)

Publication Number Publication Date
CN110896391A CN110896391A (en) 2020-03-20
CN110896391B true CN110896391B (en) 2023-01-31

Family

ID=69785613

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811069058.6A Active CN110896391B (en) 2018-09-13 2018-09-13 Message processing method and device

Country Status (1)

Country Link
CN (1) CN110896391B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113890904B (en) * 2021-09-27 2023-10-27 新华三信息安全技术有限公司 Method, device, computer equipment and storage medium for message analysis

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103366000A (en) * 2013-07-17 2013-10-23 飞天诚信科技股份有限公司 Resolution method for large-sized XML message
CN104423928A (en) * 2013-09-09 2015-03-18 腾讯科技(深圳)有限公司 Data processing method, data processing device and terminal equipment
CN104518969A (en) * 2014-12-12 2015-04-15 北京智谷睿拓技术服务有限公司 Data message processing method, device and switcher
CN104811429A (en) * 2014-01-27 2015-07-29 中兴通讯股份有限公司 OF (open flow) protocol instruction implementation method and controller
CN106559339A (en) * 2015-09-30 2017-04-05 华为技术有限公司 A kind of message processing method and device
CN107395381A (en) * 2016-05-16 2017-11-24 中兴通讯股份有限公司 A kind of message processing method, apparatus and system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008059279A (en) * 2006-08-31 2008-03-13 Internatl Business Mach Corp <Ibm> Technique for optimizing character string output processing

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103366000A (en) * 2013-07-17 2013-10-23 飞天诚信科技股份有限公司 Resolution method for large-sized XML message
CN104423928A (en) * 2013-09-09 2015-03-18 腾讯科技(深圳)有限公司 Data processing method, data processing device and terminal equipment
CN104811429A (en) * 2014-01-27 2015-07-29 中兴通讯股份有限公司 OF (open flow) protocol instruction implementation method and controller
CN104518969A (en) * 2014-12-12 2015-04-15 北京智谷睿拓技术服务有限公司 Data message processing method, device and switcher
CN106559339A (en) * 2015-09-30 2017-04-05 华为技术有限公司 A kind of message processing method and device
CN107395381A (en) * 2016-05-16 2017-11-24 中兴通讯股份有限公司 A kind of message processing method, apparatus and system

Also Published As

Publication number Publication date
CN110896391A (en) 2020-03-20

Similar Documents

Publication Publication Date Title
CN109951547B (en) Transaction request parallel processing method, device, equipment and medium
CN109032796B (en) Data processing method and device
CN111277639B (en) Method and device for maintaining data consistency
CN111111214B (en) Game archiving processing method, device and system
CN110019263B (en) Information storage method and device
CN110019873B (en) Face data processing method, device and equipment
US20190325043A1 (en) Method, device and computer program product for replicating data block
CN110896391B (en) Message processing method and device
CN112948138A (en) Method and device for processing message
CN114760369B (en) Protocol metadata extraction method, device, equipment and storage medium
CN113726885A (en) Method and device for adjusting flow quota
CN110990490B (en) Method, device, equipment and medium for checking in blockchain network
CN113742376A (en) Data synchronization method, first server and data synchronization system
CN114493875A (en) Transaction execution method, computer device, and storage medium
CN113900991A (en) Data interaction method, device, equipment and storage medium
CN109194566B (en) Method for retransmitting information, storage medium and terminal equipment
CN113541987A (en) Method and device for updating configuration data
CN109981554B (en) Information processing method and system and electronic equipment
CN112784596A (en) Method and device for identifying sensitive words
CN112241621A (en) Method and device for identifying client environment through user agent
CN113132480B (en) Data transmission method, device and system
CN111478949B (en) Data processing method and device
CN111179097B (en) Method, device, electronic equipment and storage medium for modifying warranty
CN113766437B (en) Short message sending method and device
CN112099963A (en) Method and device for analyzing binary log file

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant