Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). Where a convention analogous to "A, B or at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B or C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). It will be further understood by those within the art that virtually any disjunctive word and/or phrase presenting two or more alternative terms, whether in the description, claims, or drawings, should be understood to contemplate the possibilities of including one of the terms, either of the terms, or both terms. For example, the phrase "a or B" should be understood to include the possibility of "a" or "B", or "a and B".
Embodiments of the present disclosure provide an information processing method for identifying information in a byte stream according to a protocol, wherein each information includes a plurality of parts divided in a byte stream order. The method starts reading a part of the information from a previous part of the part when reading the part and temporarily does not save the part but saves the part when reading a next part. By using the method of the embodiment of the disclosure, the risk of information loss in the decoding process can be reduced.
Fig. 1A schematically illustrates an exemplary system architecture 100 to which the information processing methods, systems, and electronic devices may be applied, according to embodiments of the disclosure. It should be noted that fig. 1A is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
As shown in fig. 1A, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 101, 102, 103 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 105 may be a server providing various services, such as a background management server (for example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and perform other processing on the received data such as the user request, and feed back a processing result (e.g., a webpage, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the information processing method provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the information processing apparatus provided by the embodiment of the present disclosure may be generally provided in the server 105. The information processing method provided by the embodiment of the present disclosure may also be executed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the information processing apparatus provided in the embodiment of the present disclosure may also be provided in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. The information processing method provided by the embodiment of the present disclosure may also be executed by the terminal device 101, 102, or 103. Accordingly, the information processing apparatus provided by the embodiment of the present disclosure may be generally provided in the terminal device 101, 102, or 103. The information processing method provided by the embodiment of the present disclosure may also be executed by a terminal device different from the terminal devices 101, 102, 103 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the information processing apparatus provided in the embodiments of the present disclosure may also be provided in a terminal device different from the terminal devices 101, 102, 103 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks, and servers in FIG. 1A are merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Fig. 1B schematically shows an application scenario of the information processing method according to an embodiment of the present disclosure. Fig. 1B illustrates only an example of an application scenario in which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, but does not mean that the embodiments of the present disclosure may not be used in other environments or scenarios.
As shown in fig. 1B, the protocol 110 may include multiple portions 111, 112, 113. Of course, the number of the plurality of portions is only illustrative, and can be arbitrarily set according to actual needs. Each part may reserve an appropriate number of bits (bits) or bytes (bytes). For example, portion 111 of the disclosed embodiment occupies 35 bytes, portion 113 occupies 2 bytes, and the number of bytes occupied by portion 112 is defined by a field in portion 111. Each part may have different functions depending on the actual protocol definition. For example, the portion 111 of the embodiment of the present disclosure is a header (Head), in which the length of the portion 112, information of the sender and the receiver, and the like are defined. Part 112 is the Body of the message (Body) that records the data being sent. Portion 113 is a message tail (Foot) having two check bits, which may be used, for example, to check the integrity of the message. The embodiments of the present disclosure are not limited to the above, but rather, the methods provided by the embodiments of the present disclosure may be applied to various forms of protocols.
Fig. 2 schematically shows a flow chart of an information processing method according to an embodiment of the present disclosure.
As shown in fig. 2, the method includes operations S210 and S220.
In operation S210, a first portion of the information is read from the byte stream according to the protocol.
In operation S220, when reading the second portion of the information, the reading is started from the start byte of the first portion, and the information in the first portion is saved, wherein the second portion is adjacent to and behind the first portion in the order of the byte stream.
The method is for identifying information in a byte stream according to a protocol, wherein each information comprises a plurality of portions divided in a byte stream order.
Operations S210 and S220 are described below in conjunction with the embodiment illustrated in fig. 1B. As shown in fig. 1B, this information includes portions 111, 112, and 113. When reading and identifying a byte stream that conforms to the protocol, portions 111, 112, and 113 will be read sequentially in the byte stream order.
In operation S210, a first portion of the information is read from the byte stream according to the protocol. First, the portion 111 needs to be identified first in order, at which time the portion 111 serves as the first portion. According to the disclosed embodiment, the protocol specifying part 111 occupies 35 bytes, and therefore, according to the protocol, not less than 35 bytes are read. Here, because 35 bytes cannot necessarily be accurately obtained due to the randomness of the network, the read is set to be no less than 35 bytes here to ensure the integrity of the first portion. At this point, the content of the first portion is identified, but may choose not to be saved to memory for a while.
In operation S220, when reading the second portion of the information, the reading is started from the start byte of the first portion, and the information in the first portion is saved, wherein the second portion is adjacent to and behind the first portion in the order of the byte stream. According to the embodiment of the present disclosure, when reading a second portion adjacent to the first portion after the first portion, i.e., the portion 112, for example, the second portion occupies 10 bytes, reading will be started from the start byte of the first portion, i.e., from the start portion of the portion 111, until reading is not less than 45 bytes, which is the sum of the lengths of the first portion and the second portion. The contents of the second portion are identified and information of the first 35 bytes, i.e., the length of the first portion, is truncated and stored.
Similarly, when reading the portion 113, the operation S220 may be repeated with the portion 112 as a new first portion and the portion 113 as a new second portion. In particular, when the portion 113 is the last portion of the information, since reading ends up being on the last bit anyway, reading, recognition and saving can be performed directly without considering the problem of critical points.
When the decoding method reads two parts in the information according to the protocol, the content of the first part is stored, the integrity of the content of the first part can be ensured, and unknown risks are reduced.
Fig. 3 schematically shows a flow chart of an information processing method according to another embodiment of the present disclosure.
As shown in fig. 3, the method includes operations S210, S310, and S320. Operation S210 is similar to the previous embodiment, and is not described herein again.
In operation S310, the information of the first part is parsed according to the protocol.
In operation S320, the reading, when reading the second portion of the information, starting from the start byte of the first portion and saving the information in the first portion includes reading, based on the protocol and/or the parsed information, starting from the start byte of the first portion, reading at least the last byte beyond the second portion, and saving the information in the first portion. According to the embodiment of the present disclosure, the length of each part may be specified by the protocol or defined by fields in other preceding parts. Thus, the length of a certain portion may be determined based on the protocol and/or the parsed information.
Fig. 4 schematically shows a flow chart for reading a first part of the information from a byte stream according to an embodiment of the present disclosure.
As shown in fig. 4, the method includes operations S410, S420, S430, and S440.
In operation S410, in case that the first part is a beginning part of the information in the order of the byte stream, an array, a read index, and a write index are established, and the read index and the write index are initialized to 0, where the array is used to receive the byte stream. It should be noted that the array structure is only used as an embodiment, and those skilled in the art can make any suitable choice according to the existing data combination in the process of implementing the present invention.
In operation S420, a byte length of a first portion of the information is acquired. For example, the protocol specifying part 111 has a length of 35 bytes, which is the byte length of the first part from which the information is acquired.
In operation S430, a byte stream is received using the array, and the write index is updated according to the number of bytes received. For example, if 3 bytes are received on the first byte received, the write index is updated to 3, if 2 bytes are received on the second byte received, the write index is updated to 5, and so on, while the read index is always 0 in the process.
In operation S440, when the difference between the read index and the write index is not less than the byte length of the first portion, the reading of the first portion of the information is completed. For example, in the case that the byte length of the first portion is 35, when the write index is 34, the difference between the write index and the read index is smaller than the byte length 35 of the first portion, and the reading is continued, and if 3 bytes are read next time and the write index is updated to 37, it is determined that the difference between the write index and the read index is 37 and is not smaller than the byte length 35 of the first portion, and the reading of the first portion is completed.
Fig. 5 schematically shows a flowchart for reading from a start byte of the first portion and saving information in the first portion according to an embodiment of the disclosure.
As shown in fig. 5, the method includes operations S510, S520, and S530.
In operation S510, a tag index is established and assigned with a value of a read index. For example, in the case of the foregoing embodiment, the value of the read index is 0, and the tag index is assigned with 0, in which case the write index is 37, and both the read index and the tag index are 0.
In operation S520, a value of the read index is updated based on the byte length of the first portion. According to an embodiment of the present disclosure, the byte length of the first portion is 35, and thus the value of the read index may be updated to 35.
In operation S530, reading is started from the mark index until the difference between the write index and the read index is not less than the byte length of the second portion, the reading of the second portion is completed, and the information in the first portion is saved. According to the embodiment of the present disclosure, reading is started from the position 0 byte of the mark index, the value of the write index is reset to 0, and reading is performed in operation S430, and when the difference between the value of the write index and the read index is not less than the byte length of the second portion, that is, the difference between the write index and the read index (35) is not less than 10, that is, the write index is not less than 45, the reading of the second portion is completed.
FIG. 6 schematically shows a block diagram of an information handling system 600 according to an embodiment of the disclosure.
As shown in fig. 6, the information processing system 600 includes a first reading module 610 and a second reading module 620.
The first reading module 610, for example performing operation S210 described above with reference to fig. 2, is configured to read a first portion of the information from the byte stream according to the protocol.
The second reading module 620, for example, performs operation S22O described above with reference to fig. 2, and is configured to, when reading a second portion of the information, start reading from a start byte of the first portion, and save the information in the first portion, wherein the second portion is adjacent to and after the first portion in the byte stream order.
FIG. 7 schematically shows a block diagram of an information handling system 700 according to another embodiment of the present disclosure.
As shown in fig. 7, the information processing system 700 includes a first reading module 610, a second reading module 620, a parsing module 710, and a first reading sub-module 720.
The parsing module 710, for example, performs operation S310 described above with reference to fig. 3, for parsing the information of the first portion according to the protocol.
The first reading submodule 621, for example, performs the operation S320 described above with reference to fig. 3, and is configured to read from a start byte of the first portion, read at least a last byte of the second portion, and save information in the first portion based on the protocol and/or the parsed information.
Fig. 8 schematically illustrates a block diagram of a first read module 610 according to an embodiment of the present disclosure.
As shown in fig. 8, the first reading module 610 includes an initialization sub-module 611, an acquisition module 612, a second reading sub-module 613, and a suspension sub-module 614.
The initialization submodule 611, for example, performs operation S410 described above with reference to fig. 4, and is configured to, in a case where the first part is a start part of the information in the byte stream order, establish an array, a read index and a write index, and initialize the read index and the write index to 0, where the array is used for receiving the byte stream.
The obtaining submodule 612, for example, performs operation S420 described above with reference to fig. 4, for obtaining the byte length of the first part of the information.
The second read submodule 613, for example, performs operation S430 described above with reference to fig. 4, for receiving a byte stream using the array, and updating the write index according to the number of bytes received.
The abort submodule 614, for example performing operation S440 described above with reference to fig. 4, is configured to complete reading of the first part of the information when the difference between the read index and the write index is not smaller than the byte length of the first part.
Fig. 9 schematically illustrates a block diagram of a second read module 620 according to an embodiment of the present disclosure.
As shown in fig. 9, the second read module 620 includes a marking sub-module 611, an updating sub-module 612, and a third read sub-module 613.
The marking submodule 611, for example, performs operation S510 described above with reference to fig. 5, for establishing a marking index, and assigns a value to the marking index using a value of the read index.
The update submodule 612, for example, performs operation S520 described above with reference to fig. 5, for updating the value of the read index based on the byte length of the first portion.
The third reading sub-module 613, for example, performs operation S530 described above with reference to fig. 5, and is configured to start reading from the mark index, complete reading of the second portion until the difference between the write index and the read index is not less than the byte length of the second portion, and save the information in the first portion.
It is understood that the modules described above may be combined into one module, or any one of the modules may be split into a plurality of modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present invention, at least one of the above modules may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or in a suitable combination of three implementations of software, hardware, and firmware. Alternatively, at least one of the above modules may be implemented at least partly as a computer program module, which, when executed by a computer, may perform the functions of the respective module.
FIG. 10 schematically shows a block diagram of an electronic device according to an embodiment of the disclosure. The computer system illustrated in FIG. 10 is only one example and should not impose any limitations on the scope of use or functionality of embodiments of the disclosure.
As shown in fig. 10, a computer system 1000 according to an embodiment of the present disclosure includes a processor 1001 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)1002 or a program loaded from a storage section 1008 into a Random Access Memory (RAM) 1003. Processor 1001 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 1001 may also include onboard memory for caching purposes. Processor 1001 may include a single processing unit or multiple processing units for performing different actions of the method flows described with reference to fig. 2-5 in accordance with embodiments of the present disclosure.
In the RAM 1003, various programs and data necessary for the operation of the system 1000 are stored. The processor 1001, ROM1002, and RAM 1003 are connected to each other by a bus 1004. The processor 1001 performs various operations of the method according to the embodiment of the present disclosure described above with reference to fig. 2 to 5 by executing programs in the ROM1002 and/or the RAM 1003. Note that the programs may also be stored in one or more memories other than the ROM1002 and the RAM 1003. The processor 1001 may also perform various operations of the methods according to the embodiments of the present disclosure described above with reference to fig. 2-5 by executing programs stored in the one or more memories.
System 1000 may also include an input/output (I/O) interface 1005, the input/output (I/O) interface 1005 also being connected to bus 1004, according to an embodiment of the present disclosure. The system 1000 may also include one or more of the following components connected to the I/O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output section 1007 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 1008 including a hard disk and the like; and a communication section 1009 including a network interface card such as a LAN card, a modem, or the like. The communication section 1009 performs communication processing via a network such as the internet. The driver 1010 is also connected to the I/O interface 1005 as necessary. A removable medium 1011 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 1010 as necessary, so that a computer program read out therefrom is mounted into the storage section 1008 as necessary.
According to an embodiment of the present disclosure, the method described above with reference to the flow chart may be implemented as a computer software program. 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 part 1009 and/or installed from the removable medium 1011. The computer program performs the above-described functions defined in the system of the embodiment of the present disclosure when executed by the processor 1001. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
It should be noted that the computer readable media shown in the present disclosure may be computer readable signal media or computer readable storage media 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 disclosure, 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 disclosure, 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 many 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. According to embodiments of the present disclosure, a computer-readable medium may include one or more memories other than the ROM1002 and/or the RAM 1003 and/or the ROM1002 and the RAM 1003 described above.
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 disclosure. 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.
As another aspect, the present disclosure also provides a computer-readable medium, which may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to perform: … … are provided.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.