WO2018228238A1 - 一种进程之间的通信方法和装置 - Google Patents
一种进程之间的通信方法和装置 Download PDFInfo
- Publication number
- WO2018228238A1 WO2018228238A1 PCT/CN2018/089929 CN2018089929W WO2018228238A1 WO 2018228238 A1 WO2018228238 A1 WO 2018228238A1 CN 2018089929 W CN2018089929 W CN 2018089929W WO 2018228238 A1 WO2018228238 A1 WO 2018228238A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- message
- length
- bit
- header
- target
- 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.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/04—Protocols for data compression, e.g. ROHC
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/548—Queue
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W4/00—Services specially adapted for wireless communication networks; Facilities therefor
- H04W4/70—Services for machine-to-machine communication [M2M] or machine type communication [MTC]
Definitions
- the present application relates to the field of computer technology, and in particular, to a communication method between processes and a communication device between processes.
- IoT Internet of Things
- OS Operating System
- messages can be sent through a message queue between processes. For example, when the A process needs to send a message to the B process, the A process first creates a message queue for communicating with the B process. The A process adds the message that needs to be sent to the message queue, and the B process extracts the message from the message queue to complete the communication.
- Figure 1 shows a schematic diagram of a conventional message structure.
- Each of these messages consists of a message header and a message body.
- the message header is used to indicate the length of the message content in the message body, which is generally 4 bytes in length.
- the content in the message body is the length declared in the message header.
- the header used to store the length of the message is of a fixed length.
- the int type is generally used, and the length is 4 bytes.
- many message lengths are relatively short. For example, some message content is only a few tens of bytes in length. You can express this length with a one-byte message header. The rest of the bytes are not needed at all, which results in a message header. The waste of bytes.
- embodiments of the present application have been made in order to provide a communication method between processes and a communication device between processes that overcome the above problems or at least partially solve the above problems.
- the embodiment of the present application discloses a communication method between processes, including:
- the first process acquires an original message to be sent; the original message includes: a message header and a message body;
- the first process compresses the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the first process adds the compressed message to a message queue pre-created for a second process, and the second process is configured to obtain a compressed message from the message queue.
- the first process compresses the length of the message header according to the length of the message header and the length of the message body, and the step of obtaining the compressed message includes:
- the first process determines a target bit number, the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- the first process compresses the length of the message header to the target length.
- the step of the first process compressing the length of the message header to the target length comprises:
- the first process sets a length of the message header to the target length
- the first process sets a value of a specific bit in the message header according to the target length; and uses a remaining bit in the message header to remove the specific bit to indicate the length of the message body.
- the length of the message header is 4, and the step of determining, by the first process, the target length according to the target bit number includes:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- the first process sets a value of a specific bit in the message header according to the target length; and adopts a step of removing a remaining bit of the specific bit in the message header to indicate a length of the message body.
- the target length is 1, the first bit of the message header is set to 0; the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; 6 subsequent to the first byte is used.
- a value of a bit, and all bits of the second byte represent a length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication method between processes, including:
- the second process determines a length of a message header of the compressed message; the compressed message includes: a message header and a message body;
- the second process reads, according to the length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process for the second process;
- the second process reads the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the step of determining, by the second process, the length of the message header of the compressed message comprises:
- the second process reads the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the second process determines the length of the message header of the compressed message according to the value of each bit read.
- the step of the second process reading the message header of the compressed message from the message queue pre-created by the first process for the second process according to the length of the message header of the compressed message includes:
- the second process reads the value of the first digit of the bit from the message queue according to the length of the message header of the compressed message; the first digit is the number of bits corresponding to the length of the message header. Subtracting the number of bits read when the preset condition is met;
- the second process adds the value of the first bit to the value of the bit read when the preset condition is met as the message header of the compressed message.
- the step of determining, by the second process, the length of the message body according to the message header of the compressed message includes:
- the second process determines the length of the message body according to the value of a specific bit in the header of the compressed message.
- the step of determining, by the second process, the length of the message header of the compressed message according to the value of each bit read includes:
- the second process determines the length of the message header as 1;
- the second process determines the length of the message header as 2;
- the second process determines the length of the message header to be 3;
- the second process determines the length of the message header to be 4.
- the step of determining, by the second process, the length of the message body according to the value of the specific bit in the message header of the compressed message comprises:
- the second process determines the length of the message body by using the value of the last 7 bits of the message header;
- the second process determines the length of the message body by using the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte. ;
- the second process adopts the value of the last 5 bits of the first byte of the message header, and the values of all the bits of the second byte and the third byte. , determining the length of the message body;
- the second process adopts the value of the last 5 bits of the first byte of the message header, the second byte, the third byte, and the fourth word.
- the value of all bits in the section determines the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication method, including:
- the sender obtains an original message to be sent;
- the original message includes: a message header and a message body;
- the sending direction sends the compressed message to the receiver.
- the sender compresses the length of the message header according to the length of the message header and the length of the message body, and the step of obtaining the compressed message includes:
- the sender determines a target bit number, the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- the sender compresses the length of the message header to the target length.
- the step of the sender compressing the length of the message header to the target length comprises:
- the sender sets the length of the message header to the target length
- the sender sets a value of a specific bit in the message header according to the target length; and uses a remaining bit in the message header to remove the specific bit to indicate the length of the message body.
- the length of the message header is 4, and the step of determining, by the sender, the target length according to the target bit number includes:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- the sender sets a value of a specific bit in the message header according to the target length; and the step of using a message header to remove the remaining bits of the specific bit to indicate the length of the message body includes: :
- the target length is 1, the first bit of the message header is set to 0; the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; 6 subsequent to the first byte is used.
- a value of a bit, and all bits of the second byte represent a length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication method, including:
- the receiver determines the length of the message header of the compressed message; the compressed message includes: a message header and a message body;
- the receiving party reads a message header of the compressed message from a message queue pre-created by the sender for the receiver according to the length of the message header of the compressed message;
- the receiver reads the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the step of the receiver determining the length of the message header of the compressed message comprises:
- the receiving party reads the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the receiver determines the length of the message header of the compressed message according to the value of each bit read.
- the step of the receiver reading the message header of the compressed message from the message queue pre-created by the sender for the receiver according to the length of the message header of the compressed message includes:
- the receiving party reads the value of the first digit of the bit from the message queue according to the length of the message header of the compressed message; the first digit is the number of bits corresponding to the length of the message header, Subtracting the number of bits read when the preset condition is met;
- the receiver adds the value of the first bit to the value of the bit read when the preset condition is satisfied as the message header of the compressed message.
- the step of determining, by the receiver, the length of the message body according to the message header of the compressed message comprises:
- the receiver determines the length of the message body according to the value of a specific bit in the header of the compressed message.
- the step of determining, by the receiver, the length of the message header of the compressed message according to the value of each bit read includes:
- the receiver determines the length of the message header as 1;
- the receiver determines the length of the message header as 2;
- the receiver determines the length of the message header to be 3;
- the receiver determines the length of the message header to be 4.
- the step of determining, by the receiver, the length of the message body according to the value of the specific bit in the message header of the compressed message comprises:
- the receiver uses the value of the last 7 bits of the message header to determine the length of the message body;
- the receiver determines the length of the message body by using the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte;
- the receiver adopts the value of the last 5 bits of the first byte of the message header, the value of all the bits of the second byte and the third byte, Determine the length of the message body;
- the receiver adopts the value of the last 5 bits of the first byte of the message header, the second byte, the third byte, and the fourth byte. The value of all bits determines the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication method between processes, including:
- the first process acquires an original message to be sent; the original message includes: a message header and a message body;
- the first process compresses the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the first process adds the compressed message to a message queue pre-created for a second process, and the second process is configured to obtain a compressed message from the message queue.
- the first process compresses the length of the message header according to the length of the message header and the length of the message body, and the step of obtaining the compressed message includes:
- the first process determines a target bit number, the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- the first process compresses the length of the message header to the target length.
- the step of the first process compressing the length of the message header to the target length comprises:
- the first process sets a length of the message header to the target length
- the first process sets a value of a specific bit in the message header according to the target length; and uses a remaining bit in the message header to remove the specific bit to indicate the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a message compression method, including:
- the original message includes: a message header and a message body;
- the length of the message header is compressed according to the length of the message header and the length of the message body to obtain a compressed message.
- the step of compressing the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message includes:
- the target bit number being a bit number of a target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- the length of the message header is compressed to the target length.
- the step of compressing the length of the message header to the target length comprises:
- the length is a byte length.
- the embodiment of the present application further discloses a communication method between processes, including:
- the first process obtains the length of the content of the message to be sent
- the first process generates a corresponding message header according to the length of the message content
- the first process generates a message to be sent according to the message header and the message content
- the first process adds the to-be-sent message to a message queue pre-created for the second process, and the second process is used to obtain a message from the message queue.
- the step of the first process generating a corresponding message header according to the length of the message content includes:
- the first process generates a message header according to the length of the message header
- the first process sets a value of a specific bit in the message header according to the length of the message header; and uses a remaining bit of the message header to remove the specific bit to indicate the length of the message content.
- the step of determining, by the first process, the length of the message header according to the length of the message content includes:
- the first process determines a target bit number according to a length of the message content, where the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit indicating a length of the message content. sequence;
- the first process determines the target length according to the target bit number.
- the length is a byte length.
- the embodiment of the present application further discloses a message generating method, including:
- the step of generating a corresponding message header according to the length of the message content includes:
- the step of determining the length of the message header according to the length of the message content includes:
- Target bit number is a bit number of a target bit sequence
- target bit sequence is a shortest bit sequence indicating a length of the message content
- the target length is determined according to the target bit number.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device between processes, including: a first process module, and a second process module; the first process module includes:
- An original message obtaining submodule configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- a length determining submodule configured to determine a length of a message header of the original message to be sent, and a length of the message body
- a message compression submodule configured to compress a length of the message header according to a length of the message header and a length of the message body, to obtain a compressed message
- the second process module includes:
- the message compression submodule comprises:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit comprises:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length of the message header is 4, and the target length determining unit includes:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- bit setting subunit includes:
- a first bit setting component configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting component configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting component configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting component configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device between processes, including: a first process module, and a second process module;
- the second process module includes:
- a message header length determining submodule configured to determine a length of a message header of the compressed message;
- the compressed message includes: a message header and a message body;
- a message header reading submodule configured to read, according to a length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process module for the second process module;
- a message body length determining submodule configured to determine a length of the message body according to the message header of the compressed message
- the message body reading submodule is configured to read the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the message header length determining submodule includes:
- a first bit reading unit configured to read the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the message header length determining unit is configured to determine the length of the message header of the compressed message according to the value of each bit read when the value of the read bit satisfies the preset condition.
- the message header reading submodule comprises:
- a second bit reading unit configured to read a value of a bit of the first digit from the message queue according to a length of the message header of the compressed message; the first digit is a bit corresponding to a length of the message header The number of bits minus the number of bits read when the preset condition is met;
- a message header determining unit configured to add a value of the first bit to a message header of the compressed message by adding a value of the bit read when the preset condition is met.
- the message body length determining submodule comprises:
- a message body length determining unit configured to determine a length of the message body according to a value of a specific bit in the message header of the compressed message.
- the message header length determining unit includes:
- a first header length determining subunit configured to determine a length of the message header as 1 if the value of the first bit is 0;
- a second header length determining subunit configured to determine a length of the message header as 2 if the value of the first bit is 1 and the second bit is 0;
- a third message header length determining subunit configured to determine a length of the message header as 3 if the value of the first bit is 1, the second bit is 1, and the third bit is 0;
- the fourth header length determining subunit is configured to determine the length of the header as 4 if the value of the first bit is 1, the second bit is 1, and the third bit is 1.
- the message body length determining unit includes:
- a first message body length determining subunit configured to determine a length of the message body by using a value of a last 7 bits of the message header if the length of the message header is 1.
- a second message body length determining subunit configured to: if the length of the message header is 2, use the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte , determining the length of the message body;
- a third message body length determining subunit configured to: if the length of the message header is 3, use the value of the last 5 bits of the first byte of the message header, the second byte and the third word The value of all bits in the section, determining the length of the message body;
- a fourth message body length determining subunit configured to: if the length of the message header is 4, adopt the value of the last 5 bits of the first byte of the message header, the second byte, the third word The value of all bits in the section and the fourth byte determines the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device, including: a sender module, and a receiver module; the sender module includes:
- An original message obtaining submodule configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- a length determining submodule configured to determine a length of a message header of the original message to be sent, and a length of the message body
- a message compression submodule configured to compress a length of the message header according to a length of the message header and a length of the message body, to obtain a compressed message
- a compressed message sending submodule configured to send the compressed message to a receiver.
- the message compression submodule comprises:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit comprises:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length of the message header is 4, and the target length determining unit includes:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- bit setting subunit includes:
- a first bit setting component configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting component configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting component configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting component configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device, including: a sender module, and a receiver module; the receiver module includes:
- a message header length determining submodule configured to determine a length of a message header of the compressed message;
- the compressed message includes: a message header and a message body;
- a message header reading submodule configured to read, according to a length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process module for the second process module;
- a message body length determining submodule configured to determine a length of the message body according to the message header of the compressed message
- the message body reading submodule is configured to read the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the message header length determining submodule includes:
- a first bit reading unit configured to read the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the message header length determining unit is configured to determine the length of the message header of the compressed message according to the value of each bit read when the value of the read bit satisfies the preset condition.
- the message header reading submodule comprises:
- a second bit reading unit configured to read a value of a bit of the first digit from the message queue according to a length of the message header of the compressed message; the first digit is a bit corresponding to a length of the message header The number of bits minus the number of bits read when the preset condition is met;
- a message header determining unit configured to add a value of the first bit to a message header of the compressed message by adding a value of the bit read when the preset condition is met.
- the message body length determining submodule comprises:
- a message body length determining unit configured to determine a length of the message body according to a value of a specific bit in the message header of the compressed message.
- the message header length determining unit includes:
- a first header length determining subunit configured to determine a length of the message header as 1 if the value of the first bit is 0;
- a second header length determining subunit configured to determine a length of the message header as 2 if the value of the first bit is 1 and the second bit is 0;
- a third message header length determining subunit configured to determine a length of the message header as 3 if the value of the first bit is 1, the second bit is 1, and the third bit is 0;
- the fourth header length determining subunit is configured to determine the length of the header as 4 if the value of the first bit is 1, the second bit is 1, and the third bit is 1.
- the message body length determining unit includes:
- a first message body length determining subunit configured to determine a length of the message body by using a value of a last 7 bits of the message header if the length of the message header is 1.
- a second message body length determining subunit configured to: if the length of the message header is 2, use the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte , determining the length of the message body;
- a third message body length determining subunit configured to: if the length of the message header is 3, use the value of the last 5 bits of the first byte of the message header, the second byte and the third word The value of all bits in the section, determining the length of the message body;
- a fourth message body length determining subunit configured to: if the length of the message header is 4, adopt the value of the last 5 bits of the first byte of the message header, the second byte, the third word The value of all bits in the section and the fourth byte determines the length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device between processes, including: a first process module, and a second process module;
- the first process module includes:
- An original message obtaining submodule configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- a message compression submodule configured to compress a length of the message header according to a length of the message header and a length of the message body, to obtain a compressed message
- the second process module includes:
- the message compression submodule comprises:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit comprises:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a message compression apparatus, including:
- An original message obtaining module configured to acquire an original message; the original message includes: a message header and a message body;
- the message compression module is configured to compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the message compression module includes:
- a target bit number determining submodule configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining submodule configured to determine a target length according to the target bit number
- a message compression submodule configured to compress the length of the message header to the target length.
- the message compression submodule comprises:
- a length setting unit configured to set a length of the message header to the target length
- a bit setting unit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to represent a length of the message body.
- the length is a byte length.
- the embodiment of the present application further discloses a communication device between processes, including: a first process module, and a second process module;
- the first process module includes:
- a content length obtaining submodule configured to obtain a length of a message content to be sent
- a message header generating submodule configured to generate a corresponding message header according to the length of the message content
- a message generating submodule configured to generate a message to be sent according to the message header and the message content
- a message adding submodule configured to add the to-be-sent message to a message queue pre-created for the second process
- the second process module includes:
- a message acquisition submodule for obtaining a message from the message queue is provided.
- the message header generation submodule includes:
- a message header length determining unit configured to determine a length of the message header according to the length of the message content
- a message header generating unit configured to generate a message header according to the length of the message header
- a bit setting unit configured to set a value of a specific bit in the message header according to a length of the message header; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message content.
- the message header length determining unit includes:
- a bit number determining subunit configured to determine a target bit number according to a length of the message content, where the target bit number is a bit number of the target bit sequence, and the target bit sequence is a length indicating the content of the message The shortest bit sequence;
- the target length determining subunit is configured to determine the target length according to the target bit number.
- the length is a byte length.
- the embodiment of the present application further discloses a message generating apparatus, including:
- a message content length obtaining module configured to obtain a length of the message content
- a message header generating module configured to generate a corresponding message header according to the length of the message content
- a message generating module configured to generate a message according to the message header and the message content.
- the message header generating module includes:
- a message header length determining submodule configured to determine a length of the message header according to the length of the message content
- a message header generation submodule configured to generate a message header according to the length of the message header
- bit setting sub-module configured to set a value of a specific bit in the message header according to a length of the message header; and use a remaining bit of the message header to remove the specific bit to indicate a length of the message content .
- the message header length determining submodule includes:
- a target bit number determining unit configured to determine a target bit number according to a length of the message content, where the target bit number is a bit number of the target bit sequence, and the target bit sequence is a length indicating the content of the message The shortest bit sequence;
- the target length determining unit is configured to determine the target length according to the target bit number.
- the length is a byte length.
- the embodiment of the present application also discloses an apparatus, including:
- One or more processors are One or more processors.
- One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the apparatus to perform one or more of the methods described above.
- Embodiments of the present application also disclose one or more machine-readable media having stored thereon instructions that, when executed by one or more processors, cause the apparatus to perform one or more of the methods described above.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Therefore, the length of the message stored in the message queue is reduced, and the occupation of the memory resource is reduced, and is applicable to a device with limited hardware resources or relatively tight resources in the IoT field.
- Figure 1 is a schematic diagram of a conventional message structure
- Embodiment 1 of a communication method between processes in the present application
- Embodiment 3 is a flow chart showing the steps of Embodiment 2 of a communication method between processes in the present application;
- Embodiment 4 is a flow chart showing the steps of Embodiment 3 of a communication method between processes in the present application;
- Embodiment 4 is a flow chart showing the steps of Embodiment 4 of a communication method between processes in the present application;
- FIG. 6 is a schematic diagram of a process for reading a message from a message queue in an embodiment of the present application
- FIG. 7 is a flow chart showing the steps of Embodiment 1 of a communication method of the present application.
- Embodiment 8 is a flow chart showing the steps of Embodiment 2 of a communication method of the present application.
- Embodiment 9 is a flow chart showing the steps of Embodiment 5 of a communication method between processes in the present application.
- FIG. 10 is a flow chart showing the steps of an embodiment of a message compression method according to the present application.
- FIG. 11 is a flow chart showing the steps of Embodiment 6 of a communication method between processes in the present application.
- FIG. 12 is a flow chart showing the steps of an embodiment of a message generating method of the present application.
- Embodiment 13 is a structural block diagram of Embodiment 1 of a communication device between processes of the present application;
- Embodiment 14 is a structural block diagram of Embodiment 2 of a communication device between processes of the present application;
- Embodiment 15 is a structural block diagram of Embodiment 1 of a communication apparatus according to the present application.
- Embodiment 16 is a structural block diagram of Embodiment 2 of a communication apparatus according to the present application.
- FIG. 17 is a structural block diagram of Embodiment 3 of a communication device between processes of the present application.
- FIG. 18 is a structural block diagram of an embodiment of a message compression apparatus of the present application.
- Embodiment 19 is a structural block diagram of Embodiment 3 of a communication device between processes of the present application;
- FIG. 20 is a structural block diagram of an embodiment of a message generating apparatus of the present application.
- FIG. 21 is a structural block diagram of an embodiment of a smart terminal according to the present application.
- One of the core concepts of the embodiment of the present application is that in the process of sending and receiving messages through the message queue of any two processes, the sender process compresses the message header according to the length of the message body of the message to be sent and the length of the message header. Processing, deleting the bytes in the message header does not need to represent the length of the message body, reducing the length of the compression header.
- Embodiment 1 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 101 The first process acquires an original message to be sent, where the original message includes: a message header and a message body;
- the message is composed of two parts: a message header of the former part and a message body of the latter part.
- the message header may include one or more bytes, one byte includes 8 bits, and the value of each bit of each byte of the message header may indicate the length of the message body.
- the value of the 4-byte header can be 0000 0000 0000 0000 0000 0111, and its corresponding decimal number is 7, indicating that the length of the message body is 7 bytes.
- the length of the message header is greater than the length required to indicate the length of the corresponding message body.
- a message body of 7 bytes in length can actually be represented by only 1 byte 0000 0111.
- the message header uses 4 bytes, of which 3 bytes are equivalent to being wasted.
- transmitting a meaningless byte is equivalent to increasing the amount of data to be sent by the process, wasting memory resource usage.
- Step 102 The first process determines a length of a message header of the original message to be sent, and a length of the message body.
- the length is a byte length.
- the length of the header of the original message is the length before the header is uncompressed, and the sequence of the values of the bits of each byte in the header can represent the length of the message body.
- Step 103 The first process compresses the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the first process can determine the minimum number of bytes needed to represent the length based on the length of the message body. The first process then compresses the length of the message header based on the minimum number of bytes required.
- the length of the message body is 31 bytes, the corresponding binary number is 0001 1111. This length is only 1 byte. If the original length of the header is 4 bytes, the header is compressed to 1 byte, thereby obtaining a compressed message.
- Step 104 The first process adds the compressed message to a message queue pre-created for a second process, and the second process is used to obtain a compressed message from the message queue.
- the first process needs to establish a message queue in advance before sending the message to the second process. After the message queue is created, the compressed message is added to the message queue. The second process reads the compressed message from the message queue, thereby completing the process of sending and receiving the message.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Therefore, the length of the message stored in the message queue is reduced, and the occupation of the memory resource is reduced, and is applicable to an operating system with limited hardware resources or relatively tight resources in the IoT field.
- Embodiment 2 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 201 The first process acquires an original message to be sent, where the original message includes: a message header and a message body;
- the message is composed of two parts: a message header of the former part and a message body of the latter part.
- Step 202 The first process determines a length of a message header of the original message to be sent, and a length of the message body.
- the length is a byte length.
- the length of the header of the original message is the length before the header is uncompressed, and the sequence of the values of the bits of each byte in the header can represent the length of the message body.
- Step 203 The first process determines a target bit number, where the target bit number is a bit number of a target bit sequence indicating a length of the message body, and the target bit sequence is a length indicating the message body.
- the shortest bit sequence
- the target bit sequence is the shortest bit sequence representing the length of the message body. For example, if the length of the message body is 127 bytes, the corresponding shortest bit sequence is 1111111, and the bit sequence has 7 bits.
- Step 204 The first process determines a target length according to the target bit number.
- the number of bits corresponding to the target length is greater than the target number of bits.
- the determination of the target length can be divided stepwise according to the size of the target bit number.
- a range of a plurality of bit digits may be preset, and each range interval corresponds to one target length.
- the number of bits in a certain range corresponds to the same target length.
- the length of the message header is 4, and the step 204 may specifically include the following sub-steps:
- Sub-step S11 if the target bit number is less than or equal to 7, the target length is set to 1;
- the target bit number is less than or equal to 7, indicating that the length of the message body ranges from 0 bytes to 127 bytes (1111111).
- the corresponding target length can be set to 1 byte length.
- Sub-step S12 if the target bit number is greater than 7, and less than or equal to 15, the target length is set to 2;
- the target bit number is greater than 7, and less than or equal to 14, indicating that the message body has a length ranging between 128 bytes (1000 0000) and 16383 bytes (11 1111 1111 1111).
- the corresponding target length can be set to 2 bytes in length.
- Sub-step S13 if the target bit number is greater than 14, and less than or equal to 21, the target length is set to 3;
- the target bit number is greater than 14, and less than or equal to 21, indicating that the length of the message body ranges from 16384 bytes (100 0000 0000 0000) to 2097151 bytes (1 1111 1111 1111 1111 1111).
- the corresponding target length can be set to 3 bytes in length.
- Sub-step S14 if the target bit number is greater than 21 and less than or equal to 29, the target length is set to 4.
- the target bit number is greater than 21 and less than or equal to 29, indicating that the message body has a byte length ranging between 2097152 bytes (10 0000 0000 0000 0000) - 536870 911 bytes (1 1111 1111 1111 1111 1111 1111).
- the corresponding target byte length can be set to 4 bytes in length.
- target bit number is greater than 21 and less than or equal to 29, it indicates that the length of the message header is still 4 bytes, and no compression is required.
- the length of the message header may also be 6 bytes, 8 bytes, or the like.
- the header of the message can be compressed by the method of the present application. For example, when the length of the header is 6 bytes and the target length is 4 bytes, the header is compressed from 6 bytes to 4 bytes.
- Step 205 The first process compresses the length of the message header to the target length.
- the step 205 may include the following sub-steps:
- Sub-step S21 the first process sets the length of the message header to the target length
- the length of the message header may be 4 bytes.
- the first process sets the length of the message header from 4 bytes to 3 bytes. If the target length is 4 bytes, the first process still keeps the length of the message header to 4 bytes.
- Sub-step S22 the first process sets a value of a specific bit in the message header according to the target length, and uses a remaining bit of the message header to remove the specific bit to indicate the length of the message body.
- the target bit sequence is the shortest bit sequence representing the length of the message body.
- the value of the specific bit and the target length can be preset in correspondence.
- the sub-step S22 may specifically include:
- the target length is 1 byte, that is, the message header consists of only one byte.
- the first process sets the first bit of the byte to zero.
- the corresponding decimal value is 15.
- the next 7 bits in the header are used to indicate the length of the message body.
- the first process sets the 7 bits following the header to 000 1111, and the complete header is 0000 1111.
- the header indicates that the corresponding message body has a length of 15 bytes.
- Sub-step S222 if the target length is 2, the first bit of the first byte of the message header is set to 1, and the second bit is set to 0, and the first byte is used.
- the value of the next 6 bits, and all bits of the second byte represent the length of the message body;
- the message header consists of two bytes.
- the first process sets the first bit of the byte to 1 and the second bit to 0.
- the corresponding decimal value is 1024.
- the 6 bits following the first byte and the second byte are used to indicate the length of the message body.
- the first process sets the 6 bits following the first byte of the message header to 00 0100 and the second byte to 0000 0000.
- the complete message header is 1000 0100 0000 0000.
- the header indicates that the corresponding message body has a length of 1024 bytes.
- the first process sets the first bit of the first byte of the message header to 1, the second bit is set to 1, and the third bit is set to 0. .
- the target bit sequence is 1100 0000 0000 0000, the corresponding decimal value is 49152.
- the last 5 bytes, the second byte, and the third byte are used to indicate the length of the message body.
- the first process sets the 5 bits after the first byte of the message header to 0 0000, the second byte to 1100 0000, and the third byte to 0000 0000.
- the complete header is 1100 0000 1100 0000 0000.
- the header indicates that the corresponding header is 49152 bytes long.
- Sub-step S224 if the target length is 4, the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1. The value of the 5 bits following the first byte is used, and all bits of the second byte, the third byte, and the fourth byte represent the length of the message body.
- the first process sets the first bit of the first byte of the message header to 1, the second bit is set to 1, and the third bit is set to 1.
- the decimal value corresponding to the message header is 6291456.
- the value of the 5 bits following the first byte in the header, and all bits of the second byte, the third byte, and the fourth byte are used to indicate the length of the message body.
- the first process sets the 5 bits after the first byte of the message header to 0 0000, the second byte to 0110 0000, the third byte to 0000 0000, and the fourth byte to 0000 0000.
- the complete header is 1110 0000 0110 0000 0000 0000 0000.
- the header indicates that the length of the corresponding message body is 6291456 bytes.
- the value of the specific bit in the first byte may be used to represent the target length, and the specific bit is removed from the message header. The remaining bits represent the length of the message body.
- Step 206 The first process adds the compressed message to a message queue pre-created for a second process, where the second process is used to obtain a compressed message from the message queue.
- the first process needs to establish a message queue in advance before sending the message to the second process. After the message queue is created, the compressed message is added to the message queue. The second process reads the compressed message from the message queue, thereby completing the process of sending and receiving the message.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Thereby reducing the length of messages stored in the message queue and reducing the occupation of memory resources.
- Embodiment 3 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 301 The second process determines a length of a message header of the compressed message, where the compressed message includes: a message header and a message body;
- the length is a byte length.
- the first process when the first process sends a message through the message queue and the second process.
- the first process compresses the original message to be sent to generate a compressed message, and the message is composed of two parts: a message header of the previous part and a message body of the latter part.
- the message header may include one or more bytes, and one byte further includes 8 bits.
- the value of each bit of each byte of the message header may indicate the length of the message body.
- Step 302 The second process reads, according to the length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process for the second process.
- the first process needs to establish a message queue in advance before sending the message to the second process. After the message queue is created, the compressed message is added to the message queue. The second process reads the compressed message from the message queue, thereby completing the process of sending and receiving the message.
- the second process reads the compressed message, and according to the length of the message header, reads the content corresponding to the length from the message queue as the message header of the compressed message.
- Step 303 The second process determines the length of the message body according to the message header of the compressed message.
- the content of the message header of the compressed message may represent the length of the message body.
- Step 304 The second process reads the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the second process reads the content of the corresponding length from the message queue as a message body according to the length of the message body, thereby completing the reading of the message.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Thereby reducing the length of messages stored in the message queue and reducing the occupation of memory resources.
- the receiver process When the receiver process reads a message from the message queue, it reads the message header from the message queue based on the length of the message header. Then, according to the content of the message header, the message body is read from the message queue, thereby completing the reception of the message.
- Embodiment 4 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 401 The second process reads the value of the bit one by one from the message queue pre-created by the first process until the value of the read bit satisfies a preset condition;
- the first process when the first process sends a message through the message queue and the second process.
- the first process compresses the original message to be sent to generate a compressed message, and the message is composed of two parts: a message header of the previous part and a message body of the latter part.
- the contents of the message queue are arranged in a first-in-first-out order.
- the second process reads a new message from the message queue, the second process reads the value of the bit one by one from the head of the message queue until the The value of the read bit satisfies the preset condition.
- the second process starts from the first bit read and determines whether the value of the read bit satisfies the preset condition.
- the preset condition may include multiple, and one preset condition only corresponds to the value of the read bit of one case.
- the preset condition may be a value of a bit read by the second process, and satisfies a preset value.
- Step 402 When the value of the read bit satisfies the preset condition, the second process determines the length of the message header of the compressed message according to the value of each bit read; the compressed message includes: Header and message body;
- the length is a byte length.
- the value of each bit read when the preset condition is met corresponds to the case of the length of a message header.
- the second process can determine the length of the header of the compressed message based on the value of the bit read when the preset condition is met.
- the step 402 described in the embodiment of the present application may include the following sub-steps:
- Sub-step S31 if the value of the first bit is 0, the second process determines the length of the message header as 1;
- the preset condition may include: the value of the first bit is 0. If the value of the first bit is 0, the second process determines the length of the header as 1 byte.
- Sub-step S32 if the value of the first bit is 1 and the second bit is 0, the second process determines the length of the message header to be 2;
- the preset condition may further include: the value of the first bit is 1 and the second bit is 0. If the value of the first bit is 1 and the second bit is 0, the second process determines the length of the header as 2 bytes.
- Sub-step S33 if the value of the first bit is 1, the second bit is 1, and the third bit is 0, the second process determines the length of the message header to be 3;
- the preset condition may further include: the value of the first bit is 1, the second bit is 1, and the third bit is 0. If the value of the first bit is 1, the second bit is 1, and the third bit is 0, the second process determines the length of the message header to be 3 bytes.
- Sub-step S34 if the value of the first bit is 1, the second bit is 1, and the third bit is 1, the second process determines the length of the message header to be 4.
- the preset condition may further include: the value of the first bit is 1, the second bit is 1, and the third bit is 1. If the value of the first bit is 1, the second bit is 1, and the third bit is 1, the second process determines the length of the message header to be 4 bytes.
- Step 403 the second process reads the value of the first digit of the bit from the message queue according to the length of the message header of the compressed message; the first digit is the bit corresponding to the length of the message header. Number, minus the number of bits read when the preset condition is met;
- one byte includes 8 bits.
- the first digit is the number of bits corresponding to the length of the header, minus the number of bits read when the predetermined condition is met.
- the number of corresponding bits is 16.
- Step 404 The second process adds the value of the first bit to the value of the bit read when the preset condition is met as the message header of the compressed message.
- the second process may add the value of the bit bit that is read when the preset condition is satisfied to the value of the first bit in the order of the reading order, as the message header of the compressed message.
- Step 405 The second process determines the length of the message body according to the message header of the compressed message.
- the value of the bit in the header of the compressed message can be used to represent the length of the message body.
- the step 405 may include:
- the second process determines the length of the message body according to the value of a specific bit in the header of the compressed message. Specifically, it may include:
- the second process determines the length of the message body by using the value of the last 7 bits of the message header;
- the second process determines the length of the message body by using the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte. ;
- the second process adopts the value of the last 5 bits of the first byte of the message header, and the values of all the bits of the second byte and the third byte. , determining the length of the message body;
- the second process adopts the value of the last 5 bits of the first byte of the message header, the second byte, the third byte, and the fourth word.
- the value of all bits in the section determines the length of the message body.
- Step 406 The second process reads the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the second process reads the value of the bit of the corresponding length from the message queue according to the length of the message body as a message body, thereby completing the reading of the message.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Thereby reducing the length of messages stored in the message queue and reducing the occupation of memory resources.
- the receiver process When the receiver process reads a message from the message queue, it reads the message header from the message queue based on the length of the message header. Then, according to the content of the message header, the message body is read from the message queue, thereby completing the reception of the message.
- the sender process In the process of sending and receiving messages through the message queue of any two processes, the sender process first compresses the message header according to the byte length of the message body of the message to be sent and the original byte length of the message header, and deletes the message header. There is no need to represent the byte length of the message body, reducing the byte length of the compression header.
- the process of the message sender process compressing the message may include:
- the header of the original message has a byte length of 4.
- the byte length of the message body is in the range of 0-127
- only the 1-byte header is used to represent the byte length of the message body, and 4 bytes are compressed into 1 byte.
- the value of the first bit is 0, indicating that the header has only 1 byte.
- the next 7 bits can be used to indicate that the message body has a byte length in the range of 0-127.
- a 2-byte header can be used to represent the byte length of the message body, and 4 bytes are compressed into 2 bytes.
- the value of the first bit of the first byte is 1, and the value of the second bit of the first byte is 0, indicating that the header has 2 bytes.
- the first byte is followed by 6 bits, and the second byte can be used to indicate that the message body has a byte length in the range of 128-16383.
- the 3-byte header can be used to represent the byte length of the message body, and the 4 bytes are compressed into 3 bytes.
- the value of the first bit of the first byte is 1
- the value of the second bit of the first byte is 1
- the third bit of the first byte is 1
- a value of 0 indicates that the header has 3 bytes.
- the 5 bytes after the first byte, the second byte and the third byte can be used to indicate that the message body has a byte length ranging from 16384 to 2097151.
- the 4-byte header can be used to represent the byte length of the message body.
- the value of the first bit of the first byte is 1
- the value of the second bit of the first byte is 1
- the value of the third bit of the first byte is 1, indicating that this message header has 4 bytes.
- the 5th bit after the first byte, the second byte, the third byte, and the fourth byte can be used to indicate that the message body has a byte length range of 209715-536870911.
- FIG. 6 is a schematic diagram of a process for reading a message from a message queue in the embodiment of the present application.
- the process by which the receiver process reads messages from the message queue can include:
- the receiver process reads the first bit in the message queue. If the value of the first bit is 0, it means that the header is 1 byte. The receiver process reads the remaining 7 bits in the first byte to determine the byte length of the message body.
- the receiver process reads the remaining 6 bits in the first byte and the 2nd byte to determine the byte length of the message body.
- the receiver process reads the remaining 5 bits in the first byte, the 2nd byte and the 3rd byte to determine the byte length of the message body.
- the receiver process reads the remaining 5 bits in the first byte, the 2nd byte, the 3rd byte, and the 4th byte to determine the byte length of the message body.
- the receiver process reads the value of the bit length of the corresponding byte as the message body.
- Embodiment 1 of a communication method of the present application may specifically include the following steps:
- Step 501 The sender obtains an original message to be sent, where the original message includes: a message header and a message body;
- the sender may be a process in the operating system, or may be a variety of electronic devices (such as a mobile phone, a computer, or a tablet), and may be various programs and applications.
- the application is not limited herein.
- Step 502 The sender determines a length of a message header of the original message to be sent, and a length of the message body.
- the length is a byte length.
- Step 503 The sender compresses the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- Step 504 The sending direction sends the compressed message to a receiver.
- the step 503 may include the following sub-steps:
- Sub-step S41 the sender determines a target bit number, the target bit number is a bit number of the target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- Sub-step S42 the sender determines the target length according to the target bit number
- the length of the message header is 4, and the sub-step S42 may include:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- Sub-step S43 the sender compresses the length of the message header to the target length.
- the sub-step S43 may further include:
- Sub-step S431 the sender sets the length of the message header to the target length
- Sub-step S432 the sender sets a value of a specific bit in the message header according to the target length; and uses a remaining bit in the message header to remove the specific bit to indicate the length of the message body.
- the sub-step S432 may include:
- the target length is 1, the first bit of the message header is set to 0; the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; 6 subsequent to the first byte is used.
- a value of a bit, and all bits of the second byte represent a length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- Embodiment 2 of the communication method of the present application is shown, which may specifically include the following steps:
- Step 601 The receiver determines a length of a message header of the compressed message, where the compressed message includes: a message header and a message body;
- the length is a byte length.
- the step 601 may include the following sub-steps:
- Sub-step S51 the receiving party reads the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- Sub-step S52 when the value of the read bit satisfies the preset condition, the receiver determines the length of the message header of the compressed message according to the value of each bit read.
- the sub-step S52 may include:
- the receiver determines the length of the message header as 1;
- the receiver determines the length of the message header as 2;
- the receiver determines the length of the message header to be 3;
- the receiver determines the length of the message header to be 4.
- Step 602 The receiver reads, according to the length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the sender for the receiver.
- the step 602 may include the following sub-steps:
- Sub-step S61 the receiver reads the value of the first-digit bit from the message queue according to the length of the message header of the compressed message; the first digit is the bit corresponding to the length of the message header. The number of bits minus the number of bits read when the preset condition is met;
- Sub-step S62 the receiver adds the value of the first bit to the value of the bit read when the preset condition is satisfied as the message header of the compressed message.
- Step 603 The receiver determines the length of the message body according to the message header of the compressed message.
- the step 603 may include:
- the receiver determines the length of the message body according to the value of a specific bit in the header of the compressed message.
- the step of determining, by the receiver, the length of the message body according to the value of the specific bit in the message header of the compressed message includes:
- the receiver uses the value of the last 7 bits of the message header to determine the length of the message body;
- the receiver determines the length of the message body by using the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte;
- the receiver adopts the value of the last 5 bits of the first byte of the message header, the value of all the bits of the second byte and the third byte, Determine the length of the message body;
- the receiver adopts the value of the last 5 bits of the first byte of the message header, the second byte, the third byte, and the fourth byte. The value of all bits determines the length of the message body.
- Step 604 The receiver reads the content of the corresponding length from the message queue as a message body according to the length of the message body.
- Embodiment 5 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 701 The first process acquires an original message to be sent, where the original message includes: a message header and a message body;
- Step 702 The first process compresses the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the length is a byte length.
- the step 702 may include the following sub-steps:
- Sub-step S71 the first process determines a target bit number, the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- Sub-step S72 the first process determines the target length according to the target bit number
- the sub-step S72 may include:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- Sub-step S73 the first process compresses the length of the message header to the target length.
- the sub-step S73 may include:
- the first process sets a length of the message header to the target length
- the first process sets a value of a specific bit in the message header according to the target length; and uses a remaining bit in the message header to remove the specific bit to indicate the length of the message body.
- the first process sets a value of a specific bit in the message header according to the target length, and uses a message header to remove the remaining bits of the specific bit to represent the message body. length.
- the target length is 1, the first bit of the message header is set to 0; the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; 6 subsequent to the first byte is used.
- a value of a bit, and all bits of the second byte represent a length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- Step 703 The first process adds the compressed message to a message queue pre-created for the second process, where the second process is used to obtain a compressed message from the message queue.
- FIG. 10 a flow chart of steps of an embodiment of a message compression method of the present application is shown, which may specifically include the following steps:
- Step 801 Acquire an original message, where the original message includes: a message header and a message body;
- Step 802 Compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the length is a byte length.
- the step 802 may include the following sub-steps:
- Sub-step S81 determining a target bit number, the target bit number is a bit number of the target bit sequence, and the target bit sequence is a shortest bit sequence indicating a length of the message body;
- Sub-step S82 determining a target length according to the target bit number
- the length of the message header is 4, and the sub-step S82 may include:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- Sub-step S83 compressing the length of the message header to the target length.
- the sub-step S83 may include:
- the value of the specific bit in the message header is set according to the target length; and the remaining bits in the message header to remove the specific bit indicate that the length of the message body can be include:
- the target length is 1, the first bit of the message header is set to 0; the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; 6 subsequent to the first byte is used.
- a value of a bit, and all bits of the second byte represent a length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- Embodiment 6 of the communication method between processes of the present application is shown, which may specifically include the following steps:
- Step 901 The first process acquires a length of the content of the message to be sent.
- the length is a byte length.
- Step 902 The first process generates a corresponding message header according to the length of the message content.
- the step 902 may include the following sub-steps:
- Sub-step S91 the first process determines the length of the message header according to the length of the message content
- the sub-step S91 may include:
- the first process determines a target bit number according to a length of the message content, where the target bit number is a bit number of a target bit sequence, and the target bit sequence is a shortest bit indicating a length of the message content. sequence;
- the first process determines the target length according to the target bit number.
- the length of the message header is 4, and the step of determining the target length according to the target bit number may include:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- Sub-step S92 the first process generates a message header according to the length of the message header
- Sub-step S93 the first process sets a value of a specific bit in the message header according to a length of the message header; and uses a message header to remove the remaining bits of the specific bit to indicate the content of the message. length.
- the sub-step S93 may include:
- the length of the message header is 1, the first bit of the message header is set to 0; and the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; after the first byte is used a value of 6 bits, and all bits of the second byte represent the length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- Step 903 The first process generates a message to be sent according to the message header and the message content.
- Step 904 the first process adds the to-be-sent message to a message queue pre-created for the second process, and the second process is used to obtain a message from the message queue.
- the method may include the following steps:
- Step 1001 Obtain a length of the message content.
- the length is a byte length.
- Step 1002 Generate a corresponding message header according to the length of the message content.
- the step 1002 may include the following sub-steps:
- Sub-step S1001 determining the length of the message header according to the length of the message content
- Sub-step S1002 generating a message header according to the length of the message header
- Sub-step S1003 setting a value of a specific bit in the message header according to a length of the message header; and using a remaining bit of the message header to remove the specific bit to indicate a length of the message content.
- the sub-step S1003 may include:
- the length of the message header is 1, the first bit of the message header is set to 0; and the length of the message body is represented by 7 bits following the message header;
- the first bit of the first byte of the message header is set to 1, and the second bit is set to 0; after the first byte is used a value of 6 bits, and all bits of the second byte represent the length of the message body;
- the first bit of the first byte of the message header is set to 1
- the second bit is set to 1
- the third bit is set to 0
- the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body
- the first bit of the first byte of the message header is set to 1, the second bit is set to 1, and the third bit is set to 1;
- the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte represent the length of the message body.
- the sub-step S1002 may include:
- Target bit number is a bit number of a target bit sequence
- target bit sequence is a shortest bit sequence indicating a length of the message content
- the target length is determined according to the target bit number.
- the length of the message header is 4, and the step of determining the target length according to the target bit number may include:
- the target length is set to 1
- the target length is set to 2;
- the target length is set to 3;
- the target length is set to 4.
- Step 1003 Generate a message according to the message header and the message content.
- FIG. 13 a block diagram of a first embodiment of a communication device between the processes of the present application is shown, which may include the following modules: a first process module 1101, and a second process module 1102;
- the first process module 1101 can include:
- the original message obtaining sub-module 11011 is configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- a length determining sub-module 11012 configured to determine a length of a message header of the original message to be sent, and a length of the message body;
- the length is a byte length.
- the message compression sub-module 11013 is configured to compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- a compressed message adding submodule 11014 configured to add the compressed message to a message queue pre-created for the second process module
- the second process module 1102 can include:
- the compressed message acquisition sub-module 11021 is configured to obtain a compressed message from the message queue.
- the message compression sub-module 11013 may include:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit may include:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length of the message header is 4, and the target length determining unit may include:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- bit setting subunit may include:
- a first bit setting component configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting component configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting component configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting component configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Therefore, the length of the message stored in the message queue is reduced, and the occupation of the memory resource is reduced, and is applicable to an operating system with limited hardware resources or relatively tight resources in the IoT field.
- FIG. 14 a structural block diagram of a second embodiment of a communication device between processes of the present application is shown, which may specifically include the following modules: a first process module 1201, and a second process module 1202;
- the second process module 1202 can include:
- a message header length determining sub-module 12021 configured to determine a length of a message header of the compressed message;
- the compressed message includes: a message header and a message body;
- the message header reading sub-module 12022 is configured to read, according to the length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process module for the second process module;
- the length is a byte length.
- a message body length determining sub-module 12023 configured to determine a length of the message body according to the message header of the compressed message
- the message body reading sub-module 12024 is configured to read a content of a corresponding length from the message queue as a message body according to the length of the message body.
- the message header length determining submodule 12021 may include:
- a first bit reading unit configured to read the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the message header length determining unit is configured to determine the length of the message header of the compressed message according to the value of each bit read when the value of the read bit satisfies the preset condition.
- the message header reading submodule 12022 may include:
- a second bit reading unit configured to read a value of a bit of the first digit from the message queue according to a length of the message header of the compressed message; the first digit is a bit corresponding to a length of the message header The number of bits minus the number of bits read when the preset condition is met;
- a message header determining unit configured to add a value of the first bit to a message header of the compressed message by adding a value of the bit read when the preset condition is met.
- the message body length determining submodule 12023 may include:
- a message body length determining unit configured to determine a length of the message body according to a value of a specific bit in the message header of the compressed message.
- the message header length determining unit may include:
- a first header length determining subunit configured to determine a length of the message header as 1 if the value of the first bit is 0;
- a second header length determining subunit configured to determine a length of the message header as 2 if the value of the first bit is 1 and the second bit is 0;
- a third message header length determining subunit configured to determine a length of the message header as 3 if the value of the first bit is 1, the second bit is 1, and the third bit is 0;
- the fourth header length determining subunit is configured to determine the length of the header as 4 if the value of the first bit is 1, the second bit is 1, and the third bit is 1.
- the message body length determining unit may include:
- a first message body length determining subunit configured to determine a length of the message body by using a value of a last 7 bits of the message header if the length of the message header is 1.
- a second message body length determining subunit configured to: if the length of the message header is 2, use the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte , determining the length of the message body;
- a third message body length determining subunit configured to: if the length of the message header is 3, use the value of the last 5 bits of the first byte of the message header, the second byte and the third word The value of all bits in the section, determining the length of the message body;
- a fourth message body length determining subunit configured to: if the length of the message header is 4, adopt the value of the last 5 bits of the first byte of the message header, the second byte, the third word The value of all bits in the section and the fourth byte determines the length of the message body.
- the sender process compresses the message header according to the length of the message body of the original message to be sent and the length of the message header.
- the bytes in the header of the delete message do not need to represent the length of the message body, reducing the length of the compression header. Therefore, the length of the message stored in the message queue is reduced, and the occupation of the memory resource is reduced, and is applicable to an operating system with limited hardware resources or relatively tight resources in the IoT field.
- a block diagram of a first embodiment of a communications apparatus of the present application is shown.
- the method may include the following modules: a sender module 1301, and a receiver module 1302.
- the sender module 1301 may include:
- the original message obtaining sub-module 13011 is configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- a length determining sub-module 13012 configured to determine a length of a message header of the original message to be sent, and a length of the message body;
- the length is a byte length.
- the message compression sub-module 13013 is configured to compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the compressed message sending sub-module 13014 is configured to send the compressed message to a receiver.
- the message compression submodule 13013 may include:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit may include:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length of the message header is 4, and the target length determining unit may include:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- bit setting subunit may include:
- a first bit setting component configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting component configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting component configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting component configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- a sender module 1401 may include the following modules: a sender module 1401 and a receiver module 1402.
- the receiver module 1402 may include:
- the message header length determining sub-module 14021 is configured to determine a length of a message header of the compressed message, where the compressed message includes: a message header and a message body;
- the message header reading sub-module 14022 is configured to read, according to the length of the message header of the compressed message, a message header of the compressed message from a message queue pre-created by the first process module for the second process module;
- the length is a byte length.
- a message body length determining sub-module 14023 configured to determine a length of the message body according to the message header of the compressed message
- the message body reading sub-module 14024 is configured to read the content of the corresponding length from the message queue as a message body according to the length of the message body.
- the message header length determining sub-module 14021 may include:
- a first bit reading unit configured to read the value of the bit one by one from the message queue until the value of the read bit satisfies a preset condition
- the message header length determining unit is configured to determine the length of the message header of the compressed message according to the value of each bit read when the value of the read bit satisfies the preset condition.
- the message header reading submodule 14022 may include:
- a second bit reading unit configured to read a value of a bit of the first digit from the message queue according to a length of the message header of the compressed message; the first digit is a bit corresponding to a length of the message header The number of bits minus the number of bits read when the preset condition is met;
- a message header determining unit configured to add a value of the first bit to a message header of the compressed message by adding a value of the bit read when the preset condition is met.
- the message body length determining sub-module 14023 may include:
- a message body length determining unit configured to determine a length of the message body according to a value of a specific bit in the message header of the compressed message.
- the message header length determining unit may include:
- a first header length determining subunit configured to determine a length of the message header as 1 if the value of the first bit is 0;
- a second header length determining subunit configured to determine a length of the message header as 2 if the value of the first bit is 1 and the second bit is 0;
- a third message header length determining subunit configured to determine a length of the message header as 3 if the value of the first bit is 1, the second bit is 1, and the third bit is 0;
- the fourth header length determining subunit is configured to determine the length of the header as 4 if the value of the first bit is 1, the second bit is 1, and the third bit is 1.
- the message body length determining unit may include:
- a first message body length determining subunit configured to determine a length of the message body by using a value of a last 7 bits of the message header if the length of the message header is 1.
- a second message body length determining subunit configured to: if the length of the message header is 2, use the value of the last 6 bits of the first byte of the message header and the value of all the bits of the second byte , determining the length of the message body;
- a third message body length determining subunit configured to: if the length of the message header is 3, use the value of the last 5 bits of the first byte of the message header, the second byte and the third word The value of all bits in the section, determining the length of the message body;
- a fourth message body length determining subunit configured to: if the length of the message header is 4, adopt the value of the last 5 bits of the first byte of the message header, the second byte, the third word The value of all bits in the section and the fourth byte determines the length of the message body.
- Embodiment 3 of a communication device between processes of the present application is shown, which may specifically include the following modules: a first process module 1501, and a second process module 1502;
- the first process module 1501 may include:
- the original message obtaining sub-module 15011 is configured to obtain an original message to be sent; the original message includes: a message header and a message body;
- the message compression sub-module 15012 is configured to compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the length is a byte length.
- a compressed message adding submodule 15013 configured to add the compressed message to a message queue pre-created for the second process
- the second process module 1502 can include:
- the compressed message acquisition sub-module 15021 is configured to obtain a compressed message from the message queue.
- the message compression submodule 15012 may include:
- a target bit number determining unit configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining unit configured to determine a target length according to the target bit number
- a message compression unit configured to compress the length of the message header to the target length.
- the message compression unit may include:
- a length setting subunit configured to set a length of the message header to the target length
- bit setting subunit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message body.
- the length of the message header is 4, and the target length determining unit may include:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- bit setting subunit may include:
- a first bit setting component configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting component configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting component configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting component configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- FIG. 18 a structural block diagram of an embodiment of a message compression apparatus of the present application is shown, which may specifically include the following modules:
- the original message obtaining module 1601 is configured to obtain an original message, where the original message includes: a message header and a message body;
- the message compression module 1602 is configured to compress the length of the message header according to the length of the message header and the length of the message body to obtain a compressed message.
- the message compression module 1602 may include:
- a target bit number determining submodule configured to determine a target bit number, the target bit number being a bit number of the target bit sequence, the target bit sequence being a shortest bit sequence indicating a length of the message body;
- a target length determining submodule configured to determine a target length according to the target bit number
- a message compression submodule configured to compress the length of the message header to the target length.
- the message compression submodule may include:
- a length setting unit configured to set a length of the message header to the target length
- a bit setting unit configured to set a value of a specific bit in the message header according to the target length; and use a remaining bit in the message header to remove the specific bit to represent a length of the message body.
- the length of the message header is 4, and the target length determining submodule may include:
- a first target length determining unit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining unit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining unit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining unit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- the bit setting unit may include:
- a first bit setting subunit configured to: if the target length is 1, set a first bit of the message header to 0; and use the 7 bits following the message header to represent the message body length;
- a second bit setting subunit configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; a value of 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting subunit configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bits are set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting subunit configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bits are set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all the bits of the fourth byte are used to represent The length of the message body.
- Embodiment 3 of a communication device between processes of the present application is shown, which may specifically include the following modules: a first process module 1701, and a second process module 1702;
- the first process module 1701 may include:
- a content length obtaining sub-module 17011 configured to acquire a length of the message content to be sent
- the length is a byte length.
- a message header generation sub-module 17012 configured to generate a corresponding message header according to the length of the message content
- a message generating sub-module 17013, configured to generate a message to be sent according to the message header and the message content;
- a message adding sub-module 17014 configured to add the to-be-sent message to a message queue pre-created for the second process
- the second process module 1702 can include:
- the message acquisition sub-module 17021 is configured to obtain a message from the message queue.
- the message header generation sub-module 17012 may include:
- a message header length determining unit configured to determine a length of the message header according to the length of the message content
- a message header generating unit configured to generate a message header according to the length of the message header
- a bit setting unit configured to set a value of a specific bit in the message header according to a length of the message header; and use a remaining bit in the message header to remove the specific bit to indicate a length of the message content.
- the bit setting unit may include:
- a first bit setting subunit configured to: if the target length is 1, set a first bit of the message header to 0; and use the 7 bits following the message header to represent the message body length;
- a second bit setting subunit configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; a value of 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting subunit configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bits are set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting subunit configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bits are set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all the bits of the fourth byte are used to represent The length of the message body.
- the message header length determining unit may include:
- a bit number determining subunit configured to determine a target bit number according to a length of the message content, where the target bit number is a bit number of the target bit sequence, and the target bit sequence is a length indicating the content of the message The shortest bit sequence;
- the target length determining subunit is configured to determine the target length according to the target bit number.
- the length of the message header is 4, and the target length determining submodule may include:
- a first target length determining unit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining unit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining unit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining unit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- FIG. 20 a structural block diagram of an embodiment of a message generating apparatus of the present application is shown, which may specifically include the following modules:
- a message content length obtaining module 1801, configured to acquire a length of the message content
- the length is a byte length.
- a message header generating module 1802 configured to generate a corresponding message header according to the length of the message content
- the message generating module 1803 is configured to generate a message according to the message header and the message content.
- the message header generating module 1802 may include:
- a message header length determining submodule configured to determine a length of the message header according to the length of the message content
- a message header generation submodule configured to generate a message header according to the length of the message header
- bit setting sub-module configured to set a value of a specific bit in the message header according to a length of the message header; and use a remaining bit of the message header to remove the specific bit to indicate a length of the message content .
- bit setting submodule may include:
- a first bit setting unit configured to: if the target length is 1, set a first bit of the message header to 0; use 7 bits following the message header to represent the message body length;
- a second bit setting unit configured to: if the target length is 2, set a first bit of the first byte of the message header to 1 and a second bit to 0; The value of the 6 bits following the first byte, and all bits of the second byte represent the length of the message body;
- a third bit setting unit configured to: if the target length is 3, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 0; the value of the 5 bits following the first byte, the second byte, and all bits of the third byte represent the length of the message body;
- a fourth bit setting unit configured to: if the target length is 4, set the first bit of the first byte of the message header to 1, the second bit to 1, and the third bit The bit is set to 1; the value of the 5 bits following the first byte, the second byte, the third byte, and all bits of the fourth byte are used to indicate The length of the message body.
- the message header length determining submodule may include:
- a target bit number determining unit configured to determine a target bit number according to a length of the message content, where the target bit number is a bit number of the target bit sequence, and the target bit sequence is a length indicating the content of the message The shortest bit sequence;
- the target length determining unit is configured to determine the target length according to the target bit number.
- the target length determining unit may include:
- the length of the message header is 4, and the target length determining unit may include:
- a first target length determining subunit configured to set a target length to 1 if the target bit number is less than or equal to 7;
- a second target length determining subunit configured to set the target length to 2 if the target bit number is greater than 7, and less than or equal to 14,
- a third target length determining subunit configured to set the target length to 3 if the target bit number is greater than 14, and less than or equal to 21;
- the fourth target length determining subunit is configured to set the target length to 4 if the target bit number is greater than 21 and less than or equal to 29.
- the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
- Embodiments of the present disclosure can be implemented as a system for performing a desired configuration using any suitable hardware, firmware, software, or any combination thereof.
- FIG. 21 schematically illustrates an exemplary system (or apparatus) 2100 that can be used to implement various embodiments described in this disclosure.
- FIG. 21 illustrates an exemplary system 2100 having one or more processors 2102, a system control module (chipset) coupled to at least one of the processor(s) 2102. 2104, a system memory 2106 coupled to the system control module 2104, a non-volatile memory (NVM)/storage device 2108 coupled to the system control module 2104, and one or more inputs/outputs coupled to the system control module 2104 Device 2110, and a network interface 2112 that is coupled to system control module 2106.
- processors 2102 having one or more processors 2102, a system control module (chipset) coupled to at least one of the processor(s) 2102. 2104, a system memory 2106 coupled to the system control module 2104, a non-volatile memory (NVM)/storage device 2108 coupled to the system control module 2104, and one or more inputs/outputs coupled to the system control module 2104 Device 2110, and a network interface 2112 that is coupled to system control module 2106.
- NVM non-volatile
- Processor 2102 can include one or more single or multiple core processors, and processor 2102 can comprise any combination of general purpose or special purpose processors (eg, graphics processors, application processors, baseband processors, etc.).
- system 2100 can function as a browser as described in embodiments of the present application.
- system 2100 can include one or more computer readable media having instructions (eg, system memory 2106 or NVM/storage device 2108) and in combination with the one or more computer readable media configured to One or more processors 2102 that execute the instructions to implement the modules to perform the actions described in this disclosure.
- processors 2102 that execute the instructions to implement the modules to perform the actions described in this disclosure.
- system control module 2104 can include any suitable interface controller to provide to at least one of processor(s) 2102 and/or any suitable device or component in communication with system control module 2104. Any suitable interface.
- System control module 2104 can include a memory controller module to provide an interface to system memory 2106.
- the memory controller module can be a hardware module, a software module, and/or a firmware module.
- System memory 2106 can be used, for example, to load and store data and/or instructions for system 2100.
- system memory 2106 can include any suitable volatile memory, such as a suitable DRAM.
- system memory 2106 can include double data rate type quad synchronous dynamic random access memory (DDR4 SDRAM).
- system control module 2104 can include one or more input/output controllers to provide an interface to NVM/storage device 2108 and input/output device(s) 2110.
- NVM/storage device 2108 can be used to store data and/or instructions.
- NVM/storage device 2108 may comprise any suitable non-volatile memory (eg, flash memory) and/or may include any suitable non-volatile storage device(s) (eg, one or more hard disk drives (HDD), one or more compact disc (CD) drives and/or one or more digital versatile disc (DVD) drives).
- HDD hard disk drives
- CD compact disc
- DVD digital versatile disc
- the NVM/storage device 2108 can include storage resources that are physically part of the device on which the system 2100 is installed, or that can be accessed by the device without having to be part of the device.
- the NVM/storage device 2108 can be accessed via the network via the input/output device(s) 2110.
- the input/output device(s) 2110 can provide an interface to the system 2100 to communicate with any other suitable device, and the input/output device 2110 can include a communication component, an audio component, a sensor component, and the like.
- Network interface 2112 can provide an interface for system 2100 to communicate over one or more networks, and system 2100 can interact with one or more of the wireless networks in accordance with any one or more of the wireless network standards and/or protocols.
- the components communicate wirelessly, such as by accessing a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof for wireless communication.
- At least one of the processor(s) 2102 can be packaged with logic of one or more controllers (eg, memory controller modules) of the system control module 2104.
- at least one of the processor(s) 2102 can be packaged with the logic of one or more controllers of the system control module 2104 to form a system in package (SiP).
- at least one of the processor(s) 2102 can be integrated on the same mold as the logic of one or more controllers of the system control module 2104.
- at least one of the processor(s) 2102 can be integrated with the logic of one or more controllers of the system control module 2104 on the same mold to form a system on a chip (SoC).
- SoC system on a chip
- system 2100 can be, but is not limited to, a browser, a workstation, a desktop computing device, or a mobile computing device (eg, a laptop computing device, a handheld computing device, a tablet, a netbook, etc.).
- system 2100 can have more or fewer components and/or different architectures.
- system 2100 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, an application specific integrated circuit ( ASIC) and speakers.
- LCD liquid crystal display
- ASIC application specific integrated circuit
- the display screen can be implemented as a touch screen display to receive an input signal from the user.
- the touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel.
- the touch sensor may sense not only the boundary of the touch or sliding action, but also the duration and pressure associated with the touch or slide operation.
- the embodiment of the present application further provides a non-volatile readable storage medium, where the storage medium stores one or more programs, and when the one or more modules are applied to the terminal device, the terminal may be The device executes the instructions of the method steps in the embodiment of the present application.
- An apparatus in one example, comprising: one or more processors; and one or more machine-readable media having instructions stored thereon, when executed by the one or more processors, The apparatus is caused to perform the method as in the embodiment of the present application.
- Also provided in one example is one or more machine readable medium having stored thereon instructions that, when executed by one or more processors, cause the apparatus to perform the method as in the embodiments of the present application.
- embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
- computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
- Embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG.
- These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal device to produce a machine such that instructions are executed by a processor of a computer or other programmable data processing terminal device
- Means are provided for implementing the functions specified in one or more of the flow or in one or more blocks of the flow chart.
- the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
- the instruction device implements the functions specified in one or more blocks of the flowchart or in a flow or block of the flowchart.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Compression, Expansion, Code Conversion, And Decoders (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本申请实施例提供了一种进程之间的通信方法和装置,所述方法包括:第一进程获取待发送的原始消息;原始消息包括:消息头和消息体;第一进程确定待发送的原始消息的消息头的长度,以及消息体的长度;第一进程依据消息头的长度以及消息体的长度,压缩消息头的长度,得到压缩消息;第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,第二进程用于从消息队列中获取压缩消息。在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。
Description
本申请要求2017年06月14日递交的申请号为201710449251.1、发明名称为“一种进程之间的通信方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及计算机技术领域,特别是涉及一种进程之间的通信方法和一种进程之间的通信装置。
在工业领域中,为了减少设备的成本的投入,会对设备的硬件资源设有较大的限制。
例如,在物联网IoT(Internet of Things)领域中,物联网设备的硬件资源非常有限。如何在较小的硬件资源条件下,满足操作系统OS(Operating System,)的开销已经成为亟待解决的技术问题。
在常见的操作系统中,进程之间可以通过消息队列进行消息的发送。例如,当A进程需要向B进程发送消息时,A进程首先创建用于与B进程通信的消息队列。A进程将需要发送的消息添加到消息队列中,由B进程从消息队列中取出消息,完成通信。
如图1所示为传统的消息结构的示意图。其中每一条消息由消息头和消息体两部分组成。消息头,用于表示消息体中的消息内容的长度,一般为4个字节的长度。消息体中的内容为消息头中所声明的长度。当需要从消息队列中读取消息时,首先读取消息头获取消息内容的长度,然后根据长度读取相应的消息内容。
传统的消息结构中,用来保存消息长度的消息头是固定长度的,为了能表示0~n的消息,一般采用int类型,长度为4个字节。但是很多消息长度本身比较短,比如有的消息内容长度只有几十个字节左右,用一个字节的消息头就可以表达这个长度,其余的字节根本无需用到,这就造成了消息头字节的浪费。
发明内容
鉴于上述问题,提出了本申请实施例以便提供一种克服上述问题或者至少部分地解决上述问题的一种进程之间的通信方法和一种进程之间的通信装置。
为了解决上述问题,本申请实施例公开了一种进程之间的通信方法,包括:
第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;
所述第一进程确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
优选的,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:
所述第一进程确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
所述第一进程依据所述目标比特位数,确定目标长度;
所述第一进程将所述消息头的长度压缩为所述目标长度。
优选的,所述第一进程将所述消息头的长度压缩为所述目标长度的步骤包括:
所述第一进程将所述消息头的长度设置为所述目标长度;
所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述消息头的长度为4,所述第一进程依据所述目标比特位数,确定目标长度的步骤包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
优选的,所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度的步骤包括:
若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信方法,包括:
第二进程确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
所述第二进程依据所述压缩消息的消息头的长度,从第一进程针对所述第二进程预先创建的消息队列中读取压缩消息的消息头;
所述第二进程依据所述压缩消息的消息头,确定消息体的长度;
所述第二进程依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
优选的,所述第二进程确定压缩消息的消息头的长度的步骤包括:
所述第二进程从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
在所读取的比特位的值满足所述预设条件时,所述第二进程依据读取的各个比特位的值,确定压缩消息的消息头的长度。
优选的,所述第二进程依据所述压缩消息的消息头的长度,从第一进程针对所述第二进程预先创建的消息队列中读取压缩消息的消息头的步骤包括:
所述第二进程根据压缩消息的消息头的长度,从所述消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
所述第二进程将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
优选的,所述第二进程依据所述压缩消息的消息头,确定消息体的长度的步骤包括:
所述第二进程依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
优选的,所述在所读取的比特位的值满足所述预设条件时,所述第二进程依据读取 的各个比特位的值,确定压缩消息的消息头的长度的步骤包括:
若第一个比特位的值为0,则所述第二进程将消息头的长度确定为1;
若第一个比特位的值为1,第二个比特位为0,则所述第二进程将消息头的长度确定为2;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述第二进程将消息头的长度确定为3;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述第二进程将消息头的长度确定为4。
优选的,所述第二进程依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度的步骤包括:
若消息头的长度为1,则所述第二进程采用所述消息头的后7个比特位的值,确定消息体的长度;
若消息头的长度为2,则所述第二进程采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
若消息头的长度为3,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
若消息头的长度为4,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种通信方法,包括:
发送方获取待发送的原始消息;所述原始消息包括:消息头和消息体;
所述发送方确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
所述发送方依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
所述发送方向接收方发送所述压缩消息。
优选的,所述发送方依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:
所述发送方确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
所述发送方依据所述目标比特位数,确定目标长度;
所述发送方将所述消息头的长度压缩为所述目标长度。
优选的,所述发送方将所述消息头的长度压缩为所述目标长度的步骤包括:
所述发送方将所述消息头的长度设置为所述目标长度;
所述发送方依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述消息头的长度为4,所述发送方依据所述目标比特位数,确定目标长度的步骤包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
优选的,所述发送方依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度的步骤包括:
若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种通信方法,包括:
接收方确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
所述接收方依据所述压缩消息的消息头的长度,从发送方针对所述接收方预先创建 的消息队列中读取压缩消息的消息头;
所述接收方依据所述压缩消息的消息头,确定消息体的长度;
所述接收方依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
优选的,所述接收方确定压缩消息的消息头的长度的步骤包括:
所述接收方从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
在所读取的比特位的值满足所述预设条件时,所述接收方依据读取的各个比特位的值,确定压缩消息的消息头的长度。
优选的,所述接收方依据所述压缩消息的消息头的长度,从发送方针对所述接收方预先创建的消息队列中读取压缩消息的消息头的步骤包括:
所述接收方根据压缩消息的消息头的长度,从所述消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
所述接收方将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
优选的,所述接收方依据所述压缩消息的消息头,确定消息体的长度的步骤包括:
所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
优选的,所述在所读取的比特位的值满足所述预设条件时,所述接收方依据读取的各个比特位的值,确定压缩消息的消息头的长度的步骤包括:
若第一个比特位的值为0,则所述接收方将消息头的长度确定为1;
若第一个比特位的值为1,第二个比特位为0,则所述接收方将消息头的长度确定为2;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述接收方将消息头的长度确定为3;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述接收方将消息头的长度确定为4。
优选的,所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度的步骤包括:
若消息头的长度为1,则所述接收方采用所述消息头的后7个比特位的值,确定消 息体的长度;
若消息头的长度为2,则所述接收方采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
若消息头的长度为3,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
若消息头的长度为4,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信方法,包括:
第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;
所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
优选的,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:
所述第一进程确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
所述第一进程依据所述目标比特位数,确定目标长度;
所述第一进程将所述消息头的长度压缩为所述目标长度。
优选的,所述第一进程将所述消息头的长度压缩为所述目标长度的步骤包括:
所述第一进程将所述消息头的长度设置为所述目标长度;
所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种消息压缩方法,包括:
获取原始消息;所述原始消息包括:消息头和消息体;
根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩 消息。
优选的,所述根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:
确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
依据所述目标比特位数,确定目标长度;
将所述消息头的长度压缩为所述目标长度。
优选的,所述将所述消息头的长度压缩为所述目标长度的步骤包括:
将所述消息头的长度设置为所述目标长度;
依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信方法,包括:
第一进程获取待发送的消息内容的长度;
所述第一进程依据所述消息内容的长度生成对应的消息头;
所述第一进程依据所述消息头和所述消息内容生成待发送的消息;
所述第一进程将所述待发送消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取消息。
优选的,所述第一进程依据所述消息内容的长度生成对应的消息头的步骤包括:
所述第一进程依据所述消息内容的长度,确定消息头的长度;
所述第一进程依据消息头的长度,生成消息头;
所述第一进程依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
优选的,所述第一进程依据所述消息内容的长度,确定消息头的长度的步骤包括:
所述第一进程依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
所述第一进程依据所述目标比特位数,确定目标长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种消息生成方法,包括:
获取消息内容的长度;
依据所述消息内容的长度生成对应的消息头;
依据所述消息头和所述消息内容生成消息。
优选的,所述依据所述消息内容的长度生成对应的消息头的步骤包括:
依据所述消息内容的长度,确定消息头的长度;
依据所述消息头的长度,生成消息头;
依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
优选的,所述依据所述消息内容的长度,确定消息头的长度的步骤包括:
依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
依据所述目标比特位数,确定目标长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信装置,包括:第一进程模块,以及第二进程模块;所述第一进程模块包括:
原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
长度确定子模块,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
压缩消息添加子模块,用于将所述压缩消息添加到针对第二进程模块预先创建的消息队列中;
所述第二进程模块包括:
压缩消息获取子模块,用于从所述消息队列中获取压缩消息。
优选的,所述消息压缩子模块包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
优选的,所述消息压缩单元包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述消息头的长度为4,所述目标长度确定单元包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
优选的,所述比特位设置子单元包括:
第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信装置,包括:第一进程模块,以及第二进程模块;
所述第二进程模块包括:
消息头长度确定子模块,用于确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
消息头读取子模块,用于依据所述压缩消息的消息头的长度,从第一进程模块针对所述第二进程模块预先创建的消息队列中读取压缩消息的消息头;
消息体长度确定子模块,用于依据所述压缩消息的消息头,确定消息体的长度;
消息体读取子模块,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
优选的,所述消息头长度确定子模块包括:
第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
优选的,所述消息头读取子模块包括:
第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
优选的,所述消息体长度确定子模块包括:
消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
优选的,所述消息头长度确定单元包括:
第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;
第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;
第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;
第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则将消息头的长度确定为4。
优选的,所述消息体长度确定单元包括:
第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7个比特位的值,确定消息体的长度;
第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种通信装置,包括:发送方模块,以及接收方模块;所述发送方模块包括:
原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
长度确定子模块,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
压缩消息发送子模块,用于向接收方发送所述压缩消息。
优选的,所述消息压缩子模块包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
优选的,所述消息压缩单元包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述消息头的长度为4,所述目标长度确定单元包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
优选的,所述比特位设置子单元包括:
第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种通信装置,包括:发送方模块,以及接收方模块;所述接收方模块包括:
消息头长度确定子模块,用于确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
消息头读取子模块,用于依据所述压缩消息的消息头的长度,从第一进程模块针对所述第二进程模块预先创建的消息队列中读取压缩消息的消息头;
消息体长度确定子模块,用于依据所述压缩消息的消息头,确定消息体的长度;
消息体读取子模块,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
优选的,所述消息头长度确定子模块包括:
第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
优选的,所述消息头读取子模块包括:
第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
优选的,所述消息体长度确定子模块包括:
消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
优选的,所述消息头长度确定单元包括:
第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;
第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;
第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;
第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则将消息头的长度确定为4。
优选的,所述消息体长度确定单元包括:
第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7个比特位的值,确定消息体的长度;
第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信装置,包括:第一进程模块,以及第二进程模块;
所述第一进程模块包括:
原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
压缩消息添加子模块,用于将所述压缩消息添加到针对第二进程预先创建的消息队列中;
所述第二进程模块包括:
压缩消息获取子模块,用于从所述消息队列中获取压缩消息。
优选的,所述消息压缩子模块包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
优选的,所述消息压缩单元包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种消息压缩装置,包括:
原始消息获取模块,用于获取原始消息;所述原始消息包括:消息头和消息体;
消息压缩模块,用于根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息。
优选的,所述消息压缩模块包括:
目标比特位数确定子模块,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定子模块,用于依据所述目标比特位数,确定目标长度;
消息压缩子模块,用于将所述消息头的长度压缩为所述目标长度。
优选的,所述消息压缩子模块包括:
长度设置单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种进程之间的通信装置,包括:第一进程模块,以及第二进程模块;
所述第一进程模块包括:
内容长度获取子模块,用于获取待发送的消息内容的长度;
消息头生成子模块,用于依据所述消息内容的长度生成对应的消息头;
消息生成子模块,用于依据所述消息头和所述消息内容生成待发送的消息;
消息添加子模块,用于将所述待发送消息添加到针对第二进程预先创建的消息队列中;
所述第二进程模块包括:
消息获取子模块,用于从所述消息队列中获取消息。
优选的,所述消息头生成子模块包括:
消息头长度确定单元,用于依据所述消息内容的长度,确定消息头的长度;
消息头生成单元,用于依据所述消息头的长度,生成消息头;
比特位设置单元,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
优选的,所述消息头长度确定单元包括:
比特位数确定子单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
目标长度确定子单元,用于依据所述目标比特位数,确定目标长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种消息生成装置,包括:
消息内容长度获取模块,用于获取消息内容的长度;
消息头生成模块,用于依据所述消息内容的长度生成对应的消息头;
消息生成模块,用于依据所述消息头和所述消息内容生成消息。
优选的,所述消息头生成模块包括:
消息头长度确定子模块,用于依据所述消息内容的长度,确定消息头的长度;
消息头生成子模块,用于依据消息头的长度,生成消息头;
比特位设置子模块,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
优选的,所述消息头长度确定子模块包括:
目标比特位数确定单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度。
优选的,所述长度为字节长度。
本申请实施例还公开了一种装置,包括:
一个或多个处理器;和
其上存储有指令的一个或多个机器可读介质,当由所述一个或多个处理器执行时,使得所述装置执行如上所述的一个或多个的方法。
本申请实施例还公开了一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得装置执行如上所述的一个或多个的方法。
本申请实施例包括以下优点:
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用,适用于IoT领域中硬件资源有限或其他资源相对紧张的设备。
图1是传统的消息结构的示意图;
图2是本申请的一种进程之间的通信方法实施例1的步骤流程图;
图3是本申请的一种进程之间的通信方法实施例2的步骤流程图;
图4是本申请的一种进程之间的通信方法实施例3的步骤流程图;
图5是本申请的一种进程之间的通信方法实施例4的步骤流程图;
图6是本申请实施例中进程从消息队列中读取消息的示意图;
图7是本申请的一种通信方法实施例1的步骤流程图;
图8是本申请的一种通信方法实施例2的步骤流程图;
图9是本申请的一种进程之间的通信方法实施例5的步骤流程图;
图10是本申请的一种消息压缩方法实施例的步骤流程图;
图11是本申请的一种进程之间的通信方法实施例6的步骤流程图;
图12是本申请的一种消息生成方法实施例的步骤流程图;
图13是本申请的一种进程之间的通信装置实施例1的结构框图;
图14是本申请的一种进程之间的通信装置实施例2的结构框图;
图15是本申请的一种通信装置实施例1的结构框图;
图16是本申请的一种通信装置实施例2的结构框图;
图17是本申请的一种进程之间的通信装置实施例3的结构框图;
图18是本申请的一种消息压缩装置实施例的结构框图;
图19是本申请的一种进程之间的通信装置实施例3的结构框图;
图20是本申请的一种消息生成装置实施例的结构框图;
图21是本申请一种智能终端实施例的结构框图。
为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。
本申请实施例的核心构思之一在于,在任意两个进程的通过消息队列进行消息收发的过程中,发送方进程根据待发送消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。
参照图2,示出了本申请的一种进程之间的通信方法实施例1的步骤流程图,具体可以包括如下步骤:
步骤101,第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;
在本申请实施例中,消息由两部分组成:前一部分的消息头和后一部分的消息体。
消息头可以包括一个或多个字节,一个字节包括了8比特位(bit),消息头各个字节的各个比特位的取值,可以表示消息体的长度。
例如,4个字节的消息头的取值可以为0000 0000 0000 0000 0000 0000 0000 0111,其对应的十进制数为7,表示消息体的长度为7个字节。
在本申请实施例中,对于待发送的原始消息,其消息头所包括的长度大于用于表示对应消息体长度所需的长度。
例如,7字节长度的消息体实际上只需要用1个字节0000 0111就能够表示。而消息头却用了4个字节,其中3个字节相当于被浪费了。
对于内存资源较小的设备,传输没有意义的字节,相当于增加了进程所要发送的数据量,浪费了内存资源的占用。
步骤102,所述第一进程确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
在本申请实施例中,所述长度为字节长度。
原始消息的消息头的长度是消息头未经压缩前的长度,消息头中各字节的各比特位的值组合起来的序列,可以表示消息体的长度。
步骤103,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
第一进程可以依据消息体的长度,确定用于表示该长度所需的最小字节数。然后第一进程根据所需的最小字节数压缩消息头的长度。
例如,若消息体的长度为31字节,对应的二进制数为0001 1111。该长度只需1个字节表示。若消息头原始的长度为4个字节,则将消息头压缩为1个字节,从而得到压缩消息。
步骤104,所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
第一进程在向第二进程发送消息之前,需要预先建立一个消息队列。消息队列创建完成后,再将压缩消息添加到消息队列中。第二进程从消息队列中读取压缩消息,从而完成消息的收发过程。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用,适用于IoT领域中硬件资源有限或其他资源相对紧张的操作系统。
参照图3,示出了本申请的一种进程之间的通信方法实施例2的步骤流程图,具体可以包括如下步骤:
步骤201,第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;
在本申请实施例中,消息由两部分组成:前一部分的消息头和后一部分的消息体。
步骤202,所述第一进程确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
在本申请实施例中,所述长度为字节长度。原始消息的消息头的长度是消息头未经 压缩前的长度,消息头中各字节的各比特位的值组合起来的序列,可以表示消息体的长度。
步骤203,所述第一进程确定目标比特位数,所述目标比特位数为表示所述消息体的长度的目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标比特序列为表示消息体的长度的最短的比特序列。例如,若消息体的长度为127字节,对应的最短的比特序列为1111111,该比特序列的位数为7位。
步骤204,所述第一进程依据所述目标比特位数,确定目标长度;
目标长度所对应的比特位数大于目标比特位数。
目标长度的确定,可以按目标比特位数的大小阶段性的划分。
在本申请实施例中,可以预先设定多个比特位数的范围区间,每一个范围区间对应一个目标长度。处于某一个范围区间内的比特位数,对应同一个目标长度。
具体的,在本申请实施例中消息头的长度为4,所述步骤204具体可以包括如下子步骤:
子步骤S11,若所述目标比特位数小于或等于7,则将目标长度设置为1;
目标比特位数小于或等于7,表示消息体的长度范围在0字节-127字节(1111111)之间。对应的目标长度可设置为1个字节长度。
子步骤S12,若所述目标比特位数大于7,以及小于或等于15,则将目标长度设置为2;
目标比特位数大于7,以及小于或等于14,表示消息体的长度范围在128字节(1000 0000)-16383字节(11 1111 1111 1111)之间。对应的目标长度可设置为2个字节长度。
子步骤S13,若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
目标比特位数大于14,以及小于或等于21,表示消息体的长度范围在16384字节(100 0000 0000 0000)-2097151字节(1 1111 1111 1111 1111 1111)之间。对应的目标长度可设置为3个字节长度。
子步骤S14,若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
目标比特位数大于21,以及小于或等于29,表示消息体的字节长度范围在2097152字节(10 0000 0000 0000 0000 0000)-536870911字节(1 1111 1111 1111 1111 1111 1111 1111)之间。对应的目标字节长度可设置为4个字节长度。
若所述目标比特位数大于21,以及小于或等于29,表示消息头的长度仍然为4个字节,不需要压缩。
在本申请实施例的优选示例中,消息头的长度还可以为6字节、8字节等等。只要当消息头中部分字节不用于表示消息体的长度,都可以采用本申请的方法对消息头进行压缩处理。例如,当消息头的长度为6字节时,目标长度为4字节,则将消息头从6字节压缩为4字节。
步骤205,所述第一进程将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述步骤205可以包括如下子步骤:
子步骤S21,所述第一进程将所述消息头的长度设置为所述目标长度;
在本申请实施例中,消息头的长度可以为4字节。
若目标长度为3字节,则第一进程将消息头的长度从4字节设置为3字节。若目标长度为4字节,则第一进程仍然将消息头的长度保持为4字节。
子步骤S22,所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值,采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
目标比特序列为表示所述消息体的长度的最短的比特序列。
特定比特位的取值和目标长度可以预先设定好对应关系。
在本申请实施例中,所述子步骤S22具体可以包括:
子步骤S221,若所述目标长度为1,则将所述消息头的第一个比特位设置为0,采用所述消息头后面的7个比特位表示所述消息体的长度;
例如,若目标长度为1字节,也就是说消息头只由一个字节组成。第一进程将该字节的第一个比特位设置为0。
若目标比特序列为1111,对应的十进制的值为15。消息头中后面的7个比特位用于表示消息体的长度。
第一进程将该消息头后面的7个比特位设置为000 1111,完整的消息头为0000 1111,该消息头表示了对应的消息体的长度为15字节。
子步骤S222,若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0,采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
例如,若目标长度为2字节,也就是说消息头由两个字节组成。第一进程将该字节 的第一个比特位设置为1,第二个比特位设置为0。
若目标比特序列为100 0000 0000,对应的十进制的值为1024。
消息头中,第一个字节后面的6个比特位以及第二个字节用于表示消息体的长度。
第一进程将该消息头第一个字节后面的6个比特位设置为00 0100,第二个字节设置为0000 0000。完整的消息头为1000 0100 0000 0000,该消息头表示了对应的消息体的长度为1024字节。
子步骤S223,若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0,采用所述第一个字节后面的5个比特位的值,以及所述第二个字节、第三个字节的所有比特位表示所述消息体的长度;
例如,若目标长度为3字节,第一进程将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0。
若目标比特序列为1100 0000 0000 0000,对应的十进制的值为49152。
消息头中,第一个字节后面5个比特位、第二个字节以及第三个字节用于表示消息体的长度。
第一进程将消息头第一个字节后面5个比特位的设置为0 0000,将第二个字节设置为1100 0000,将第三个字节设置为0000 0000。完整的消息头为1100 0000 1100 0000 0000 0000,该消息头表示了对应的消息头的长度为49152字节。
子步骤S224,若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1,采用所述第一个字节后面的5个比特位的值,以及所述第二个字节、第三个字节、第四个字节的所有比特位表示所述消息体的长度。
例如,若目标长度为4字节,第一进程将消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1。
若目标比特序列为110 0000 0000 0000 0000 0000,消息头对应的十进制值为6291456。
消息头中第一个字节后面的5个比特位的值,以及第二个字节、第三个字节、第四个字节的所有比特位用于表示消息体的长度。
第一进程将该消息头第一个字节后面的5个比特位设置为0 0000,第二个字节设置为0110 0000,第三个字节设置为0000 0000,第四个字节设置为0000 0000。完整的消息头为1110 0000 0110 0000 0000 0000 0000 0000。该消息头表示了对应的消息体的长度为 6291456字节。
在本申请实施例的优选示例中,当目标长度为不同数值时,可以采用第一个字节中不同的特定比特位的取值来表示目标长度,并采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
步骤206,所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
第一进程在向第二进程发送消息之前,需要预先建立一个消息队列。消息队列创建完成后,再将压缩消息添加到消息队列中。第二进程从消息队列中读取压缩消息,从而完成消息的收发过程。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用。
参照图4,示出了本申请的一种进程之间的通信方法实施例3的步骤流程图,具体可以包括如下步骤:
步骤301,第二进程确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
在本申请实施例中,所述长度为字节长度。
在本申请实施例中,当第一进程通过消息队列与第二进程进行消息发送的过程中。第一进程采用待发送的原始消息压缩生成压缩消息,消息由两部分组成:前一部分的消息头和后一部分的消息体。
压缩消息的生成过程具体可以参见上述的实施例1和实施例2,在此不作赘述。
消息头可以包括一个或多个字节,一个字节又包括了8比特位(bit),消息头各个字节的各个比特位的取值,可以表示消息体的长度。
步骤302,所述第二进程依据所述压缩消息的消息头的长度,从第一进程针对所述第二进程预先创建的消息队列中读取压缩消息的消息头;
第一进程在向第二进程发送消息之前,需要预先建立一个消息队列。消息队列创建完成后,再将压缩消息添加到消息队列中。第二进程从消息队列中读取压缩消息,从而完成消息的收发过程。
第二进程读取压缩消息可以根据消息头的长度,从消息队列中读取长度相应的内容作为压缩消息的消息头。
步骤303,所述第二进程依据所述压缩消息的消息头,确定消息体的长度;
在本申请实施例中,压缩消息的消息头的内容可以表示消息体的长度。
步骤304,所述第二进程依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
第二进程依据消息体的长度从消息队列中读取相应长度的内容作为消息体,从而完成消息的读取。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用。
接收方进程在从消息队列中读取消息时,根据消息头的长度从消息队列中读取消息头。然后根据消息头的内容,从消息队列中读取消息体,从而完成消息的接收。
参照图5,示出了本申请的一种进程之间的通信方法实施例4的步骤流程图,具体可以包括如下步骤:
步骤401,所述第二进程从由第一进程预先创建的消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
在本申请实施例中,当第一进程通过消息队列与第二进程进行消息发送的过程中。第一进程采用待发送的原始消息压缩生成压缩消息,消息由两部分组成:前一部分的消息头和后一部分的消息体。
压缩消息的生成过程具体可以参见上述的实施例1和实施例2,在此不作赘述。
消息队列中的内容是按先进先出的顺序排列的,当第二进程从消息队列中读取新的消息时,第二进程从消息队列的头部开始逐个读取比特位的值,直至所读取的比特位的值满足预设条件。
第二进程从读取的第一个比特位开始,判断已读取比特位的值是否满足预设条件。在本申请实施例中,预设条件可以包括多个,一个预设条件只对应一种情况的读取的比特位的值。
预设条件可以为第二进程所读取的比特位的值,满足预先设定的值。
步骤402,在所读取的比特位的值满足所述预设条件时,所述第二进程依据读取的各个比特位的值,确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
在本申请实施例中,所述长度为字节长度。
每一种满足预设条件时读取的比特位的值,都对应有一种消息头的长度的情况。第二进程根据满足预设条件时读取的比特位的值,可以确定压缩消息的消息头的长度。具体的,在本申请实施例中所述步骤402可以包括如下子步骤:
子步骤S31,若第一个比特位的值为0,则所述第二进程将消息头的长度确定为1;
在本申请实施例中,预设条件可以包括:第一个比特位的值为0。若第一个比特位的值为0,第二进程将消息头的长度确定为1字节。
子步骤S32,若第一个比特位的值为1,第二个比特位为0,则所述第二进程将消息头的长度确定为2;
预设条件还可以包括:第一个比特位的值为1,第二个比特位为0。若第一个比特位的值为1,第二个比特位为0,则第二进程将消息头的长度确定为2字节。
子步骤S33,若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述第二进程将消息头的长度确定为3;
预设条件还可以包括:第一个比特位的值为1,第二个比特位为1,第三个比特位为0。若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则第二进程将消息头的长度确定为3字节。
子步骤S34,若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述第二进程将消息头的长度确定为4。
预设条件还可以包括:第一个比特位的值为1,第二个比特位为1,第三个比特位为1。若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则第二进程将消息头的长度确定为4字节。
步骤403,所述第二进程根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
在本申请实施例中,一个字节包括8比特位。第一位数为消息头的长度所对应的比特位的数目,减去在满足述预设条件时读取的比特位的数目。
例如,若消息头的长度为2字节,其对应的比特位数目为16。在满足预设条件时,已读取的比特位的数目为2,则第一位数为16-2=14。
步骤404,所述第二进程将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
所述第二进程可以按照读取顺序的先后,将满足所述预设条件时读取的比特位的值加上第一比特位的值,作为压缩消息的消息头。
步骤405,所述第二进程依据所述压缩消息的消息头,确定消息体的长度;
压缩消息的消息头中的比特位的值,可以用于表示消息体的长度。
在本申请实施例中,所述步骤405可以为包括:
所述第二进程依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。具体的,可以包括:
若消息头的长度为1,则所述第二进程采用所述消息头的后7个比特位的值,确定消息体的长度;
若消息头的长度为2,则所述第二进程采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
若消息头的长度为3,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
若消息头的长度为4,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
步骤406,所述第二进程依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
第二进程依据消息体的长度从消息队列中,读取相应长度的比特位的值作为消息体,从而完成消息的读取。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用。
接收方进程在从消息队列中读取消息时,根据消息头的长度从消息队列中读取消息头。然后根据消息头的内容,从消息队列中读取消息体,从而完成消息的接收。
为了使本领域技术人员能够更好地理解本申请实施例,下面通过一个例子对本申请实施例加以说明:
在任意两个进程的通过消息队列进行消息收发的过程中,发送方进程首先根据待发送消息的消息体的字节长度和消息头的原始字节长度,对消息头进行压缩处理,删除消息头中不需要表示消息体字节长度的字节,减少压缩头的字节长度。
消息发送方进程压缩消息的过程可以包括:
原始消息的消息头的字节长度为4。
当消息体的字节长度在0-127范围内时,只用1个字节的消息头来表示消息体的字节长度,把4个字节压缩为1个字节。压缩后的消息头中,第1个比特位的值为0,表示这个消息头只有1个字节。后面7个比特位可以用来表示消息体的字节长度范围为0-127。
当消息体的字节长度在128-16383范围内时,可以用2个字节的消息头来表示消息体的字节长度,把4个字节压缩为2个字节。压缩后的消息头中,第1个字节的第1个比特位的值为1,第1个字节的第2个比特位的值为0,表示这个消息头有2个字节。第一个字节后面6个比特位,以及第二个字节可以用来表示消息体的字节长度范围为128-16383。
当消息体的字节长度在16384-2097151范围内时,可以用3个字节的消息头来表示消息体的字节长度,把4个字节压缩为3个字节。压缩后的消息头中,第1个字节的第1个比特位的值为1,第1个字节的第2个比特位的值为1,第1个字节的第3个比特位的值为0,表示这个消息头有3个字节。第一个字节后面5个比特位,第二个字节以及第三个字节可以用来表示消息体的字节长度范围为16384-2097151。
当消息体的字节长度在2097152-536870911范围内时,可以用4个字节的消息头来表示消息体的字节长度。消息头中,第1个字节的第1个比特位的值为1,第1个字节的第2个比特位的值为1,第1个字节的第3个比特位的值为1,表示这个消息头有4个字节。第一个字节后面5个比特位,第二个字节,第三个字节以及第四个字节可以用来表示消息体的字节长度范围为2097152-536870911。
参照图6所示为本申请实施例中进程从消息队列中读取消息的示意图。接收方进程从消息队列中读取消息的过程可以包括:
接收方进程读取消息队列中第1个比特位。若第1个比特位的值为0,则表示消息头为1个字节。接收方进程读取第一个字节中剩余的7个比特位来确定消息体的字节长度。
若第1个比特位的值为1,则读取消息队列中第2个比特位。若第2个比特位的值 为0,则表示消息头为2个字节。接收方进程读取第一个字节中剩余的6个比特位,以及第2个字节来确定消息体的字节长度。
若第2个比特位的值为1,则读取消息队列中第3个比特位。若第3个比特位的值为0,则表示消息头为3个字节。接收方进程读取第一个字节中剩余的5个比特位,第2个字节以及第3个字节来确定消息体的字节长度。
若第3个比特位的值为1,则表示消息头为4个字节。接收方进程读取第一个字节中剩余的5个比特位,第2个字节、第3个字节以及第4个字节来确定消息体的字节长度。
接收方进程按照消息头所表示的消息体的字节长度,请消息队列中读取相应字节长度的比特位的值作为消息体。
参照图7,示出了本申请的一种通信方法实施例1的步骤流程图,具体可以包括如下步骤:
步骤501,发送方获取待发送的原始消息;所述原始消息包括:消息头和消息体;
本申请实施例中,发送方可以是操作系统中的进程,也可以是各种电子设备(如手机、电脑、平板电脑),还可以是各种程序、应用,本申请在此不作限定。
步骤502,所述发送方确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
本申请实施例中,在本申请实施例中,所述长度为字节长度。
步骤503,所述发送方依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
步骤504,所述发送方向接收方发送所述压缩消息。
在本申请实施例中,所述步骤503可以包括如下子步骤:
子步骤S41,所述发送方确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
子步骤S42,所述发送方依据所述目标比特位数,确定目标长度;
在本申请实施例中,所述消息头的长度为4,所述子步骤S42可以包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
子步骤S43,所述发送方将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述子步骤S43可以进一步包括:
子步骤S431,所述发送方将所述消息头的长度设置为所述目标长度;
子步骤S432,所述发送方依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,所述子步骤S432可以包括:
若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
参照图8,示出了本申请的一种通信方法实施例2的步骤流程图,具体可以包括如下步骤:
步骤601,接收方确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
在本申请实施例中,所述长度为字节长度。
在本申请实施例中,所述步骤601可以包括如下子步骤:
子步骤S51,所述接收方从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
子步骤S52,在所读取的比特位的值满足所述预设条件时,所述接收方依据读取的各个比特位的值,确定压缩消息的消息头的长度。
在本申请实施例中,所述子步骤S52可以包括:
若第一个比特位的值为0,则所述接收方将消息头的长度确定为1;
若第一个比特位的值为1,第二个比特位为0,则所述接收方将消息头的长度确定为2;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述接收方将消息头的长度确定为3;
若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述接收方将消息头的长度确定为4。
步骤602,所述接收方依据所述压缩消息的消息头的长度,从发送方针对所述接收方预先创建的消息队列中读取压缩消息的消息头;
在本申请实施例中,所述步骤602可以包括如下子步骤:
子步骤S61,所述接收方根据压缩消息的消息头的长度,从所述消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
子步骤S62,所述接收方将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
步骤603,所述接收方依据所述压缩消息的消息头,确定消息体的长度;
在本申请实施例中,所述步骤603可以包括:
所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
在本申请实施例中,所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度的步骤包括:
若消息头的长度为1,则所述接收方采用所述消息头的后7个比特位的值,确定消息体的长度;
若消息头的长度为2,则所述接收方采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
若消息头的长度为3,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
若消息头的长度为4,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
步骤604,所述接收方依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
参照图9,示出了本申请的一种进程之间的通信方法实施例5的步骤流程图,具体可以包括如下步骤:
步骤701,第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;
步骤702,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
在本申请实施例中,所述长度为字节长度。
在本申请实施例中,所述步骤702可以包括如下子步骤:
子步骤S71,所述第一进程确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
子步骤S72,所述第一进程依据所述目标比特位数,确定目标长度;
在本申请实施例中,所述子步骤S72可以包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
子步骤S73,所述第一进程将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述子步骤S73可以包括:
所述第一进程将所述消息头的长度设置为所述目标长度;
所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例,所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。可以包括:
若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个 比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
步骤703,所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
参照图10,示出了本申请的一种消息压缩方法实施例的步骤流程图,具体可以包括如下步骤:
步骤801,获取原始消息;所述原始消息包括:消息头和消息体;
步骤802,根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息。
在本申请实施例中,所述长度为字节长度。
在本申请实施例中,所述步骤802可以包括如下子步骤:
子步骤S81,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
子步骤S82,依据所述目标比特位数,确定目标长度;
在本申请实施例中,所述消息头的长度为4,所述子步骤S82可以包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
子步骤S83,将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述子步骤S83可以包括:
将所述消息头的长度设置为所述目标长度;
依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,所述依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度可以包括:
若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
参照图11,示出了本申请的一种进程之间的通信方法实施例6的步骤流程图,具体可以包括如下步骤:
步骤901,第一进程获取待发送的消息内容的长度;
在本申请实施例中,所述长度为字节长度。
步骤902,所述第一进程依据所述消息内容的长度生成对应的消息头;
在本申请实施例中,所述步骤902可以包括如下子步骤:
子步骤S91,所述第一进程依据所述消息内容的长度,确定消息头的长度;
在本申请实施例中,所述子步骤S91可以包括:
所述第一进程依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
所述第一进程依据所述目标比特位数,确定目标长度。
在本申请实施例中,所述消息头的长度为4,所述依据所述目标比特位数,确定目标长度的步骤可以包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
子步骤S92,所述第一进程依据消息头的长度,生成消息头;
子步骤S93,所述第一进程依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
在本申请实施例中,所述子步骤S93可以包括:
若所述消息头的长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述消息头的长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述消息头的长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述消息头的长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
步骤903,所述第一进程依据所述消息头和所述消息内容生成待发送的消息;
步骤904,所述第一进程将所述待发送消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取消息。
参照图12,示出了本申请的一种消息生成方法实施例的步骤流程图,具体可以包括如下步骤:
步骤1001,获取消息内容的长度;
在本申请实施例中,所述长度为字节长度。
步骤1002,依据所述消息内容的长度生成对应的消息头;
在本申请实施例中,所述步骤1002可以包括如下子步骤:
子步骤S1001,依据所述消息内容的长度,确定消息头的长度;
子步骤S1002,依据所述消息头的长度,生成消息头;
子步骤S1003,依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
在本申请实施例中,所述子步骤S1003可以包括:
若所述消息头的长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
若所述消息头的长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
若所述消息头的长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
若所述消息头的长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
在本申请实施例中,所述子步骤S1002可以包括:
依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
依据所述目标比特位数,确定目标长度。
在本申请实施例中,所述消息头的长度为4,所述依据所述目标比特位数,确定目标长度的步骤可以包括:
若所述目标比特位数小于或等于7,则将目标长度设置为1;
若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
步骤1003,依据所述消息头和所述消息内容生成消息。
需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请实施例并不受所描述的动作顺序的限制,因为依据本申请实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是本申请实施例所必须的。
参照图13,示出了本申请的一种进程之间的通信装置实施例1的结构框图,具体可以包括如下模块:第一进程模块1101,以及第二进程模块1102;
所述第一进程模块1101可以包括:
原始消息获取子模块11011,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
长度确定子模块11012,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
在本申请实施例中,所述长度为字节长度。
消息压缩子模块11013,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
压缩消息添加子模块11014,用于将所述压缩消息添加到针对第二进程模块预先创建的消息队列中;
所述第二进程模块1102可以包括:
压缩消息获取子模块11021,用于从所述消息队列中获取压缩消息。
在本申请实施例中,所述消息压缩子模块11013可以包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述消息压缩单元可以包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,所述消息头的长度为4,所述目标长度确定单元可以包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
在本申请实施例中,所述比特位设置子单元可以包括:
第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用,适用于IoT领域中硬件资源有限或其他资源相对紧张的操作系统。
参照图14,示出了本申请的一种进程之间的通信装置实施例2的结构框图,具体可以包括如下模块:第一进程模块1201,以及第二进程模块1202;
所述第二进程模块1202可以包括:
消息头长度确定子模块12021,用于确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;
消息头读取子模块12022,用于依据所述压缩消息的消息头的长度,从第一进程模块针对所述第二进程模块预先创建的消息队列中读取压缩消息的消息头;
在本申请实施例中,所述长度为字节长度。
消息体长度确定子模块12023,用于依据所述压缩消息的消息头,确定消息体的长度;
消息体读取子模块12024,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
在本申请实施例中,所述消息头长度确定子模块12021可以包括:
第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
在本申请实施例中,所述消息头读取子模块12022可以包括:
第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
在本申请实施例中,所述消息体长度确定子模块12023可以包括:
消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
在本申请实施例中,所述消息头长度确定单元可以包括:
第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;
第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;
第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;
第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则将消息头的长度确定为4。
在本申请实施例中,所述消息体长度确定单元可以包括:
第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7个比特位的值,确定消息体的长度;
第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
在本申请实施例中,任意两个进程的在通过消息队列进行消息收发的过程中,发送方进程根据待发送的原始消息的消息体的长度和消息头的长度,对消息头进行压缩处理,删除消息头中不需要表示消息体长度的字节,减少压缩头的长度。从而减少消息队列中存储的消息的长度,减少了对内存资源的占用,适用于IoT领域中硬件资源有限或其他资源相对紧张的操作系统。
参照图15,示出了本申请的一种通信装置实施例1的结构框图,具体可以包括如下模块:发送方模块1301,以及接收方模块1302;所述发送方模块1301可以包括:
原始消息获取子模块13011,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
长度确定子模块13012,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;
在本申请实施例中,所述长度为字节长度。
消息压缩子模块13013,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
压缩消息发送子模块13014,用于向接收方发送所述压缩消息。
在本申请实施例中,所述消息压缩子模块13013可以包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述消息压缩单元可以包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,所述消息头的长度为4,所述目标长度确定单元可以包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
在本申请实施例中,所述比特位设置子单元可以包括:
第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
参照图16,示出了本申请的一种通信装置实施例2的结构框图,具体可以包括如下模块:发送方模块1401,以及接收方模块1402;所述接收方模块1402可以包括:
消息头长度确定子模块14021,用于确定压缩消息的消息头的长度;所述压缩消息 包括:消息头和消息体;
消息头读取子模块14022,用于依据所述压缩消息的消息头的长度,从第一进程模块针对所述第二进程模块预先创建的消息队列中读取压缩消息的消息头;
在本申请实施例中,所述长度为字节长度。
消息体长度确定子模块14023,用于依据所述压缩消息的消息头,确定消息体的长度;
消息体读取子模块14024,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
在本申请实施例中,所述消息头长度确定子模块14021可以包括:
第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;
消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
在本申请实施例中,所述消息头读取子模块14022可以包括:
第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;
消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
在本申请实施例中,所述消息体长度确定子模块14023可以包括:
消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
在本申请实施例中,所述消息头长度确定单元可以包括:
第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;
第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;
第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;
第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第 三个比特位为1,则将消息头的长度确定为4。
在本申请实施例中,所述消息体长度确定单元可以包括:
第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7个比特位的值,确定消息体的长度;
第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;
第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;
第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
参照图17,示出了本申请的一种进程之间的通信装置实施例3的结构框图,具体可以包括如下模块:第一进程模块1501,以及第二进程模块1502;
所述第一进程模块1501可以包括:
原始消息获取子模块15011,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;
消息压缩子模块15012,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;
在本申请实施例中,所述长度为字节长度。
压缩消息添加子模块15013,用于将所述压缩消息添加到针对第二进程预先创建的消息队列中;
所述第二进程模块1502可以包括:
压缩消息获取子模块15021,用于从所述消息队列中获取压缩消息。
在本申请实施例中,消息压缩子模块15012可以包括:
目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度;
消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述消息压缩单元可以包括:
长度设置子单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,在本申请实施例中,所述消息头的长度为4,所述目标长度确定单元可以包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
在本申请实施例中,所述比特位设置子单元可以包括:
第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
参照图18,示出了本申请的一种消息压缩装置实施例的结构框图,具体可以包括如 下模块:
原始消息获取模块1601,用于获取原始消息;所述原始消息包括:消息头和消息体;
消息压缩模块1602,用于根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息。
在本申请实施例中,所述消息压缩模块1602可以包括:
目标比特位数确定子模块,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;
目标长度确定子模块,用于依据所述目标比特位数,确定目标长度;
消息压缩子模块,用于将所述消息头的长度压缩为所述目标长度。
在本申请实施例中,所述消息压缩子模块可以包括:
长度设置单元,用于将所述消息头的长度设置为所述目标长度;
比特位设置单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
在本申请实施例中,所述消息头的长度为4,所述目标长度确定子模块可以包括:
第一目标长度确定单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
在本申请实施例中,所述比特位设置单元可以包括:
第一比特位设置子单元,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置子单元,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置子单元,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一 个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置子单元,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
参照图19,示出了本申请的一种进程之间的通信装置实施例3的结构框图,具体可以包括如下模块:第一进程模块1701,以及第二进程模块1702;
所述第一进程模块1701可以包括:
内容长度获取子模块17011,用于获取待发送的消息内容的长度;
在本申请实施例中,所述长度为字节长度。
消息头生成子模块17012,用于依据所述消息内容的长度生成对应的消息头;
消息生成子模块17013,用于依据所述消息头和所述消息内容生成待发送的消息;
消息添加子模块17014,用于将所述待发送消息添加到针对第二进程预先创建的消息队列中;
所述第二进程模块1702可以包括:
消息获取子模块17021,用于从所述消息队列中获取消息。
在本申请实施例中,所述消息头生成子模块17012可以包括:
消息头长度确定单元,用于依据所述消息内容的长度,确定消息头的长度;
消息头生成单元,用于依据所述消息头的长度,生成消息头;
比特位设置单元,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
在本申请实施例中,所述比特位设置单元可以包括:
第一比特位设置子单元,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置子单元,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置子单元,用于若所述目标长度为3,则将所述消息头第一个字节的 第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置子单元,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
在本申请实施例中,所述消息头长度确定单元可以包括:
比特位数确定子单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
目标长度确定子单元,用于依据所述目标比特位数,确定目标长度。
在本申请实施例中,所述消息头的长度为4,所述目标长度确定子模块可以包括:
第一目标长度确定单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
参照图20,示出了本申请的一种消息生成装置实施例的结构框图,具体可以包括如下模块:
消息内容长度获取模块1801,用于获取消息内容的长度;
在本申请实施例中,所述长度为字节长度。
消息头生成模块1802,用于依据所述消息内容的长度生成对应的消息头;
消息生成模块1803,用于依据所述消息头和所述消息内容生成消息。
在本申请实施例中,所述消息头生成模块1802可以包括:
消息头长度确定子模块,用于依据所述消息内容的长度,确定消息头的长度;
消息头生成子模块,用于依据消息头的长度,生成消息头;
比特位设置子模块,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
在本申请实施例中,所述比特位设置子模块可以包括:
第一比特位设置单元,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;
第二比特位设置单元,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;
第三比特位设置单元,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;
第四比特位设置单元,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
在本申请实施例中,所述消息头长度确定子模块可以包括:
目标比特位数确定单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;
目标长度确定单元,用于依据所述目标比特位数,确定目标长度。
在本申请实施例中,所述目标长度确定单元可以包括:
在本申请实施例中,所述消息头的长度为4,所述目标长度确定单元可以包括:
第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;
第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;
第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;
第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
本公开的实施例可被实现为使用任意适当的硬件,固件,软件,或及其任意组合进行想要的配置的系统。图21示意性地示出了可被用于实现本公开中所述的各个实施例的示例性系统(或装置)2100。
对于一个实施例,图21示出了示例性系统2100,该系统具有一个或多个处理器2102、被耦合到(一个或多个)处理器2102中的至少一个的系统控制模块(芯片组)2104、被耦合到系统控制模块2104的系统存储器2106、被耦合到系统控制模块2104的非易失性存储器(NVM)/存储设备2108、被耦合到系统控制模块2104的一个或多个输入/输出设备2110,以及被耦合到系统控制模块2106的网络接口2112。
处理器2102可包括一个或多个单核或多核处理器,处理器2102可包括通用处理器或专用处理器(例如图形处理器、应用处理器、基频处理器等)的任意组合。在一些实施例中,系统2100能够作为本申请实施例中所述的浏览器。
在一些实施例中,系统2100可包括具有指令的一个或多个计算机可读介质(例如,系统存储器2106或NVM/存储设备2108)以及与该一个或多个计算机可读介质相合并被配置为执行指令以实现模块从而执行本公开中所述的动作的一个或多个处理器2102。
对于一个实施例,系统控制模块2104可包括任意适当的接口控制器,以向(一个或多个)处理器2102中的至少一个和/或与系统控制模块2104通信的任意适当的设备或组件提供任意适当的接口。
系统控制模块2104可包括存储器控制器模块,以向系统存储器2106提供接口。存储器控制器模块可以是硬件模块、软件模块和/或固件模块。
系统存储器2106可被用于例如为系统2100加载和存储数据和/或指令。对于一个实施例,系统存储器2106可包括任意适当的易失性存储器,例如,适当的DRAM。在一些实施例中,系统存储器2106可包括双倍数据速率类型四同步动态随机存取存储器(DDR4SDRAM)。
对于一个实施例,系统控制模块2104可包括一个或多个输入/输出控制器,以向 NVM/存储设备2108及(一个或多个)输入/输出设备2110提供接口。
例如,NVM/存储设备2108可被用于存储数据和/或指令。NVM/存储设备2108可包括任意适当的非易失性存储器(例如,闪存)和/或可包括任意适当的(一个或多个)非易失性存储设备(例如,一个或多个硬盘驱动器(HDD)、一个或多个光盘(CD)驱动器和/或一个或多个数字通用光盘(DVD)驱动器)。
NVM/存储设备2108可包括在物理上作为系统2100被安装在其上的设备的一部分的存储资源,或者其可被该设备访问而不必作为该设备的一部分。例如,NVM/存储设备2108可通过网络经由(一个或多个)输入/输出设备2110进行访问。
(一个或多个)输入/输出设备2110可为系统2100提供接口以与任意其他适当的设备通信,输入/输出设备2110可以包括通信组件、音频组件、传感器组件等。网络接口2112可为系统2100提供接口以通过一个或多个网络通信,系统2100可根据一个或多个无线网络标准和/或协议中的任意标准和/或协议来与无线网络的一个或多个组件进行无线通信,例如接入基于通信标准的无线网络,如WiFi,2G或3G,或它们的组合进行无线通信。
对于一个实施例,(一个或多个)处理器2102中的至少一个可与系统控制模块2104的一个或多个控制器(例如,存储器控制器模块)的逻辑封装在一起。对于一个实施例,(一个或多个)处理器2102中的至少一个可与系统控制模块2104的一个或多个控制器的逻辑封装在一起以形成系统级封装(SiP)。对于一个实施例,(一个或多个)处理器2102中的至少一个可与系统控制模块2104的一个或多个控制器的逻辑集成在同一模具上。对于一个实施例,(一个或多个)处理器2102中的至少一个可与系统控制模块2104的一个或多个控制器的逻辑集成在同一模具上以形成片上系统(SoC)。
在各个实施例中,系统2100可以但不限于是:浏览器、工作站、台式计算设备或移动计算设备(例如,膝上型计算设备、手持计算设备、平板电脑、上网本等)。在各个实施例中,系统2100可具有更多或更少的组件和/或不同的架构。例如,在一些实施例中,系统2100包括一个或多个摄像机、键盘、液晶显示器(LCD)屏幕(包括触屏显示器)、非易失性存储器端口、多个天线、图形芯片、专用集成电路(ASIC)和扬声器。
其中,如果显示器包括触摸面板,显示屏可以被实现为触屏显示器,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。
本申请实施例还提供了一种非易失性可读存储介质,该存储介质中存储有一个或多个模块(programs),该一个或多个模块被应用在终端设备时,可以使得该终端设备执行本申请实施例中各方法步骤的指令(instructions)。
在一个示例中提供了一种装置,包括:一个或多个处理器;和,其上存储的有指令的一个或多个机器可读介质,当由所述一个或多个处理器执行时,使得所述装置执行如本申请实施例中的方法。
在一个示例中还提供了一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得装置执行如本申请实施例中的方法。
本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。
本领域内的技术人员应明白,本申请实施例的实施例可提供为方法、装置、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本申请实施例是参照根据本申请实施例的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程 和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。
以上对本申请所提供的一种进程之间的通信方法和一种进程之间的通信装置,进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。
Claims (86)
- 一种进程之间的通信方法,其特征在于,包括:第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;所述第一进程确定所述待发送的原始消息的消息头的长度,以及消息体的长度;所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
- 根据权利要求1所述的方法,其特征在于,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:所述第一进程确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;所述第一进程依据所述目标比特位数,确定目标长度;所述第一进程将所述消息头的长度压缩为所述目标长度。
- 根据权利要求2所述的方法,其特征在于,所述第一进程将所述消息头的长度压缩为所述目标长度的步骤包括:所述第一进程将所述消息头的长度设置为所述目标长度;所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求3所述的方法,其特征在于,所述消息头的长度为4,所述第一进程依据所述目标比特位数,确定目标长度的步骤包括:若所述目标比特位数小于或等于7,则将目标长度设置为1;若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
- 根据权利要求4所述的方法,其特征在于,所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度的步骤包括:若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
- 根据权利要求1-5任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种进程之间的通信方法,其特征在于,包括:第二进程确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;所述第二进程依据所述压缩消息的消息头的长度,从第一进程针对所述第二进程预先创建的消息队列中读取压缩消息的消息头;所述第二进程依据所述压缩消息的消息头,确定消息体的长度;所述第二进程依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
- 根据权利要求7所述的方法,其特征在于,所述第二进程确定压缩消息的消息头的长度的步骤包括:所述第二进程从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;在所读取的比特位的值满足所述预设条件时,所述第二进程依据读取的各个比特位的值,确定压缩消息的消息头的长度。
- 根据权利要求8所述的方法,其特征在于,所述第二进程依据所述压缩消息的消息头的长度,从第一进程针对所述第二进程预先创建的消息队列中读取压缩消息的消息头的步骤包括:所述第二进程根据压缩消息的消息头的长度,从所述消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设 条件时读取的比特位的数目;所述第二进程将所述第一位数的比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
- 根据权利要求8或9所述的方法,其特征在于,所述第二进程依据所述压缩消息的消息头,确定消息体的长度的步骤包括:所述第二进程依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
- 根据权利要求10所述的方法,其特征在于,所述在所读取的比特位的值满足所述预设条件时,所述第二进程依据读取的各个比特位的值,确定压缩消息的消息头的长度的步骤包括:若第一个比特位的值为0,则所述第二进程将消息头的长度确定为1;若第一个比特位的值为1,第二个比特位为0,则所述第二进程将消息头的长度确定为2;若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述第二进程将消息头的长度确定为3;若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述第二进程将消息头的长度确定为4。
- 根据权利要求11所述的方法,其特征在于,所述第二进程依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度的步骤包括:若消息头的长度为1,则所述第二进程采用所述消息头的后7个比特位的值,确定消息体的长度;若消息头的长度为2,则所述第二进程采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;若消息头的长度为3,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;若消息头的长度为4,则所述第二进程采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
- 根据权利要求7-12任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种通信方法,其特征在于,包括:发送方获取待发送的原始消息;所述原始消息包括:消息头和消息体;所述发送方确定所述待发送的原始消息的消息头的长度,以及消息体的长度;所述发送方依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;所述发送方向接收方发送所述压缩消息。
- 根据权利要求14所述的方法,其特征在于,所述发送方依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:所述发送方确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;所述发送方依据所述目标比特位数,确定目标长度;所述发送方将所述消息头的长度压缩为所述目标长度。
- 根据权利要求15所述的方法,其特征在于,所述发送方将所述消息头的长度压缩为所述目标长度的步骤包括:所述发送方将所述消息头的长度设置为所述目标长度;所述发送方依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求16所述的方法,其特征在于,所述消息头的长度为4,所述发送方依据所述目标比特位数,确定目标长度的步骤包括:若所述目标比特位数小于或等于7,则将目标长度设置为1;若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
- 根据权利要求17所述的方法,其特征在于,所述发送方依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度的步骤包括:若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二 个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
- 根据权利要求14-18任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种通信方法,其特征在于,包括:接收方确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;所述接收方依据所述压缩消息的消息头的长度,从发送方针对所述接收方预先创建的消息队列中读取压缩消息的消息头;所述接收方依据所述压缩消息的消息头,确定消息体的长度;所述接收方依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
- 根据权利要求20所述的方法,其特征在于,所述接收方确定压缩消息的消息头的长度的步骤包括:所述接收方从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;在所读取的比特位的值满足所述预设条件时,所述接收方依据读取的各个比特位的值,确定压缩消息的消息头的长度。
- 根据权利要求21所述的方法,其特征在于,所述接收方依据所述压缩消息的消息头的长度,从发送方针对所述接收方预先创建的消息队列中读取压缩消息的消息头的步骤包括:所述接收方根据压缩消息的消息头的长度,从所述消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;所述接收方将所述第一位数的比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
- 根据权利要求21或22所述的方法,其特征在于,所述接收方依据所述压缩消息 的消息头,确定消息体的长度的步骤包括:所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
- 根据权利要求23所述的方法,其特征在于,所述在所读取的比特位的值满足所述预设条件时,所述接收方依据读取的各个比特位的值,确定压缩消息的消息头的长度的步骤包括:若第一个比特位的值为0,则所述接收方将消息头的长度确定为1;若第一个比特位的值为1,第二个比特位为0,则所述接收方将消息头的长度确定为2;若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则所述接收方将消息头的长度确定为3;若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则所述接收方将消息头的长度确定为4。
- 根据权利要求24所述的方法,其特征在于,所述接收方依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度的步骤包括:若消息头的长度为1,则所述接收方采用所述消息头的后7个比特位的值,确定消息体的长度;若消息头的长度为2,则所述接收方采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;若消息头的长度为3,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;若消息头的长度为4,则所述接收方采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
- 根据权利要求20-25任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种进程之间的通信方法,其特征在于,包括:第一进程获取待发送的原始消息;所述原始消息包括:消息头和消息体;所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;所述第一进程将所述压缩消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取压缩消息。
- 根据权利要求27所述的方法,其特征在于,所述第一进程依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:所述第一进程确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;所述第一进程依据所述目标比特位数,确定目标长度;所述第一进程将所述消息头的长度压缩为所述目标长度。
- 根据权利要求28所述的方法,其特征在于,所述第一进程将所述消息头的长度压缩为所述目标长度的步骤包括:所述第一进程将所述消息头的长度设置为所述目标长度;所述第一进程依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求27-29任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种消息压缩方法,其特征在于,包括:获取原始消息;所述原始消息包括:消息头和消息体;根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息。
- 根据权利要求31所述的方法,其特征在于,所述根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息的步骤包括:确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;依据所述目标比特位数,确定目标长度;将所述消息头的长度压缩为所述目标长度。
- 根据权利要求32所述的方法,其特征在于,所述将所述消息头的长度压缩为所述目标长度的步骤包括:将所述消息头的长度设置为所述目标长度;依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求31-33任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种进程之间的通信方法,其特征在于,包括:第一进程获取待发送的消息内容的长度;所述第一进程依据所述消息内容的长度生成对应的消息头;所述第一进程依据所述消息头和所述消息内容生成待发送的消息;所述第一进程将所述待发送消息添加到针对第二进程预先创建的消息队列中,所述第二进程用于从所述消息队列中获取消息。
- 根据权利要求35所述的方法,其特征在于,所述第一进程依据所述消息内容的长度生成对应的消息头的步骤包括:所述第一进程依据所述消息内容的长度,确定消息头的长度;所述第一进程依据消息头的长度,生成消息头;所述第一进程依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
- 根据权利要求36所述的方法,其特征在于,所述第一进程依据所述消息内容的长度,确定消息头的长度的步骤包括:所述第一进程依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;所述第一进程依据所述目标比特位数,确定目标长度。
- 根据权利要求35-37任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种消息生成方法,其特征在于,包括:获取消息内容的长度;依据所述消息内容的长度生成对应的消息头;依据所述消息头和所述消息内容生成消息。
- 根据权利要求39所述的方法,其特征在于,所述依据所述消息内容的长度生成对应的消息头的步骤包括:依据所述消息内容的长度,确定消息头的长度;依据所述消息头的长度,生成消息头;依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
- 根据权利要求40所述的方法,其特征在于,所述依据所述消息内容的长度,确定消息头的长度的步骤包括:依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;依据所述目标比特位数,确定目标长度。
- 根据权利要求39-41任意一项所述的方法,其特征在于,所述长度为字节长度。
- 一种进程之间的通信装置,其特征在于,包括:第一进程模块,以及第二进程模块;所述第一进程模块包括:原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;长度确定子模块,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;压缩消息添加子模块,用于将所述压缩消息添加到针对第二进程模块预先创建的消息队列中;所述第二进程模块包括:压缩消息获取子模块,用于从所述消息队列中获取压缩消息。
- 根据权利要求43所述的装置,其特征在于,所述消息压缩子模块包括:目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;目标长度确定单元,用于依据所述目标比特位数,确定目标长度;消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
- 根据权利要求44所述的装置,其特征在于,所述消息压缩单元包括:长度设置子单元,用于将所述消息头的长度设置为所述目标长度;比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求45所述的装置,其特征在于,所述消息头的长度为4,所述目标长度确定单元包括:第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
- 根据权利要求46所述的装置,其特征在于,所述比特位设置子单元包括:第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
- 根据权利要求43-47任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种进程之间的通信装置,其特征在于,包括:第一进程模块,以及第二进程模块;所述第二进程模块包括:消息头长度确定子模块,用于确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;消息头读取子模块,用于依据所述压缩消息的消息头的长度,从第一进程模块针对 所述第二进程模块预先创建的消息队列中读取压缩消息的消息头;消息体长度确定子模块,用于依据所述压缩消息的消息头,确定消息体的长度;消息体读取子模块,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
- 根据权利要求49所述的装置,其特征在于,所述消息头长度确定子模块包括:第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
- 根据权利要求50所述的装置,其特征在于,所述消息头读取子模块包括:第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
- 根据权利要求50或51所述的装置,其特征在于,所述消息体长度确定子模块包括:消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
- 根据权利要求52所述的装置,其特征在于,所述消息头长度确定单元包括:第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则将消息头的长度确定为4。
- 根据权利要求53所述的装置,其特征在于,所述消息体长度确定单元包括:第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7 个比特位的值,确定消息体的长度;第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
- 根据权利要求49-54任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种通信装置,其特征在于,包括:发送方模块,以及接收方模块;所述发送方模块包括:原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;长度确定子模块,用于确定所述待发送的原始消息的消息头的长度,以及消息体的长度;消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;压缩消息发送子模块,用于向接收方发送所述压缩消息。
- 根据权利要求56所述的装置,其特征在于,所述消息压缩子模块包括:目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;目标长度确定单元,用于依据所述目标比特位数,确定目标长度;消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
- 根据权利要求57所述的装置,其特征在于,所述消息压缩单元包括:长度设置子单元,用于将所述消息头的长度设置为所述目标长度;比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求58所述的装置,其特征在于,所述消息头的长度为4,所述目标 长度确定单元包括:第一目标长度确定子单元,用于若所述目标比特位数小于或等于7,则将目标长度设置为1;第二目标长度确定子单元,用于若所述目标比特位数大于7,以及小于或等于14,则将目标长度设置为2;第三目标长度确定子单元,用于若所述目标比特位数大于14,以及小于或等于21,则将目标长度设置为3;第四目标长度确定子单元,用于若所述目标比特位数大于21,以及小于或等于29,则将目标长度设置为4。
- 根据权利要求59所述的装置,其特征在于,所述比特位设置子单元包括:第一比特位设置组件,用于若所述目标长度为1,则将所述消息头的第一个比特位设置为0;采用所述消息头后面的7个比特位表示所述消息体的长度;第二比特位设置组件,用于若所述目标长度为2,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为0;采用所述第一个字节后面的6个比特位的值,以及所述第二个字节的所有比特位表示所述消息体的长度;第三比特位设置组件,用于若所述目标长度为3,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为0;采用所述第一个字节后面的5个比特位的值、所述第二个字节,以及第三个字节的所有比特位表示所述消息体的长度;第四比特位设置组件,用于若所述目标长度为4,则将所述消息头第一个字节的第一个比特位设置为1,第二个比特位设置为1,第三个比特位设置为1;采用所述第一个字节后面的5个比特位的值、所述第二个字节、第三个字节,以及第四个字节的所有比特位表示所述消息体的长度。
- 根据权利要求56-60任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种通信装置,其特征在于,包括:发送方模块,以及接收方模块;所述接收方模块包括:消息头长度确定子模块,用于确定压缩消息的消息头的长度;所述压缩消息包括:消息头和消息体;消息头读取子模块,用于依据所述压缩消息的消息头的长度,从第一进程模块针对 第二进程模块预先创建的消息队列中读取压缩消息的消息头;消息体长度确定子模块,用于依据所述压缩消息的消息头,确定消息体的长度;消息体读取子模块,用于依据所述消息体的长度从所述消息队列中读取相应长度的内容作为消息体。
- 根据权利要求62所述的装置,其特征在于,所述消息头长度确定子模块包括:第一比特位读取单元,用于从所述消息队列中,逐个读取比特位的值直至所读取的比特位的值满足预设条件;消息头长度确定单元,用于在所读取的比特位的值满足所述预设条件时,依据读取的各个比特位的值,确定压缩消息的消息头的长度。
- 根据权利要求63所述的装置,其特征在于,所述消息头读取子模块包括:第二比特位读取单元,用于根据压缩消息的消息头的长度,从消息队列中读取第一位数的比特位的值;所述第一位数为消息头的长度所对应的比特位的数目,减去在满足所述预设条件时读取的比特位的数目;消息头确定单元,用以将所述第一比特位的值,加上在满足所述预设条件时读取的比特位的值作为压缩消息的消息头。
- 根据权利要求63或64所述的装置,其特征在于,所述消息体长度确定子模块包括:消息体长度确定单元,用于依据所述压缩消息的消息头中特定比特位的值,确定消息体的长度。
- 根据权利要求65所述的装置,其特征在于,所述消息头长度确定单元包括:第一消息头长度确定子单元,用于若第一个比特位的值为0,则将消息头的长度确定为1;第二消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为0,则将消息头的长度确定为2;第三消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为0,则将消息头的长度确定为3;第四消息头长度确定子单元,用于若第一个比特位的值为1,第二个比特位为1,第三个比特位为1,则将消息头的长度确定为4。
- 根据权利要求66所述的装置,其特征在于,所述消息体长度确定单元包括:第一消息体长度确定子单元,用于若消息头的长度为1,则采用所述消息头的后7 个比特位的值,确定消息体的长度;第二消息体长度确定子单元,用于若消息头的长度为2,则采用所述消息头的第一个字节的后6个比特位的值以及第二个字节所有比特位的值,确定消息体的长度;第三消息体长度确定子单元,用于若消息头的长度为3,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节以及第三个字节所有比特位的值,确定消息体的长度;第四消息体长度确定子单元,用于若消息头的长度为4,则采用所述消息头的第一个字节的后5个比特位的值,第二个字节、第三个字节以及第四个字节所有比特位的值,确定消息体的长度。
- 根据权利要求62-67任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种进程之间的通信装置,其特征在于,包括:第一进程模块,以及第二进程模块;所述第一进程模块包括:原始消息获取子模块,用于获取待发送的原始消息;所述原始消息包括:消息头和消息体;消息压缩子模块,用于依据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息;压缩消息添加子模块,用于将所述压缩消息添加到针对第二进程预先创建的消息队列中;所述第二进程模块包括:压缩消息获取子模块,用于从所述消息队列中获取压缩消息。
- 根据权利要求69所述的装置,其特征在于,所述消息压缩子模块包括:目标比特位数确定单元,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;目标长度确定单元,用于依据所述目标比特位数,确定目标长度;消息压缩单元,用于将所述消息头的长度压缩为所述目标长度。
- 根据权利要求70所述的装置,其特征在于,所述消息压缩单元包括:长度设置子单元,用于将所述消息头的长度设置为所述目标长度;比特位设置子单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值; 采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求69-71任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种消息压缩装置,其特征在于,包括:原始消息获取模块,用于获取原始消息;所述原始消息包括:消息头和消息体;消息压缩模块,用于根据所述消息头的长度以及所述消息体的长度,压缩所述消息头的长度,得到压缩消息。
- 根据权利要求73所述的装置,其特征在于,所述消息压缩模块包括:目标比特位数确定子模块,用于确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息体的长度的最短的比特序列;目标长度确定子模块,用于依据所述目标比特位数,确定目标长度;消息压缩子模块,用于将所述消息头的长度压缩为所述目标长度。
- 根据权利要求74所述的装置,其特征在于,所述消息压缩子模块包括:长度设置单元,用于将所述消息头的长度设置为所述目标长度;比特位设置单元,用于依据所述目标长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息体的长度。
- 根据权利要求73-75任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种进程之间的通信装置,其特征在于,包括:第一进程模块,以及第二进程模块;所述第一进程模块包括:内容长度获取子模块,用于获取待发送的消息内容的长度;消息头生成子模块,用于依据所述消息内容的长度生成对应的消息头;消息生成子模块,用于依据所述消息头和所述消息内容生成待发送的消息;消息添加子模块,用于将所述待发送消息添加到针对第二进程预先创建的消息队列中;所述第二进程模块包括:消息获取子模块,用于从所述消息队列中获取消息。
- 根据权利要求77所述的装置,其特征在于,所述消息头生成子模块包括:消息头长度确定单元,用于依据所述消息内容的长度,确定消息头的长度;消息头生成单元,用于依据所述消息头的长度,生成消息头;比特位设置单元,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
- 根据权利要求78所述的装置,其特征在于,所述消息头长度确定单元包括:比特位数确定子单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;目标长度确定子单元,用于依据所述目标比特位数,确定目标长度。
- 根据权利要求77-79任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种消息生成装置,其特征在于,包括:消息内容长度获取模块,用于获取消息内容的长度;消息头生成模块,用于依据所述消息内容的长度生成对应的消息头;消息生成模块,用于依据所述消息头和所述消息内容生成消息。
- 根据权利要求81所述的装置,其特征在于,所述消息头生成模块包括:消息头长度确定子模块,用于依据所述消息内容的长度,确定消息头的长度;消息头生成子模块,用于依据消息头的长度,生成消息头;比特位设置子模块,用于依据所述消息头的长度,设置所述消息头中特定比特位的取值;采用消息头中除去所述特定比特位的其余比特位表示所述消息内容的长度。
- 根据权利要求82所述的装置,其特征在于,所述消息头长度确定子模块包括:目标比特位数确定单元,用于依据所述消息内容的长度,确定目标比特位数,所述目标比特位数为目标比特序列的位数,所述目标比特序列为表示所述消息内容的长度的最短的比特序列;目标长度确定单元,用于依据所述目标比特位数,确定目标长度。
- 根据权利要求81-83任意一项所述的装置,其特征在于,所述长度为字节长度。
- 一种通信装置,其特征在于,包括:一个或多个处理器;和其上存储有指令的一个或多个机器可读介质,当由所述一个或多个处理器执行时,使得所述装置执行如权利要求1-6和/或7-13和/或14-19和/或20-26和/或27-30和/或 31-34和/或35-38和/或39-42所述的一个或多个的方法。
- 一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得装置执行如权利要求1-6和/或7-13和/或14-19和/或20-26和/或27-30和/或31-34和/或35-38和/或39-42所述的一个或多个的方法。
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| US16/714,522 US11216320B2 (en) | 2017-06-14 | 2019-12-13 | Method and apparatus for communication between processes |
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710449251.1 | 2017-06-14 | ||
| CN201710449251.1A CN109086144B (zh) | 2017-06-14 | 2017-06-14 | 一种进程之间的通信方法和装置 |
Related Child Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| US16/714,522 Continuation US11216320B2 (en) | 2017-06-14 | 2019-12-13 | Method and apparatus for communication between processes |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2018228238A1 true WO2018228238A1 (zh) | 2018-12-20 |
Family
ID=64659910
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2018/089929 Ceased WO2018228238A1 (zh) | 2017-06-14 | 2018-06-05 | 一种进程之间的通信方法和装置 |
Country Status (3)
| Country | Link |
|---|---|
| US (1) | US11216320B2 (zh) |
| CN (1) | CN109086144B (zh) |
| WO (1) | WO2018228238A1 (zh) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US11252110B1 (en) | 2018-09-21 | 2022-02-15 | Marvell Asia Pte Ltd | Negotiation of alignment mode for out of order placement of data in network devices |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1592272A (zh) * | 2003-09-04 | 2005-03-09 | 国际商业机器公司 | 用于压缩消息头部的方法 |
| CN102023961A (zh) * | 2009-09-10 | 2011-04-20 | 中兴通讯股份有限公司 | 一种基于共享内存的通信方法及装置 |
| CN105634684A (zh) * | 2014-11-19 | 2016-06-01 | 中国移动通信集团广东有限公司 | 一种数据包的处理方法、装置及服务器 |
Family Cites Families (18)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5222217A (en) | 1989-01-18 | 1993-06-22 | International Business Machines Corporation | System and method for implementing operating system message queues with recoverable shared virtual storage |
| US5787300A (en) | 1993-11-10 | 1998-07-28 | Oracle Corporation | Method and apparatus for interprocess communications in a database environment |
| US7099949B1 (en) | 1995-10-23 | 2006-08-29 | Imec Vzw | Interprocess communication protocol system |
| US6829769B2 (en) | 2000-10-04 | 2004-12-07 | Microsoft Corporation | High performance interprocess communication |
| US7263701B2 (en) | 2001-09-04 | 2007-08-28 | Samsung Electronics Co., Ltd. | Interprocess communication method and apparatus |
| US20030115358A1 (en) | 2001-09-04 | 2003-06-19 | Yeong-Hyun Yun | Unified interprocess communication |
| US8136155B2 (en) | 2003-04-01 | 2012-03-13 | Check Point Software Technologies, Inc. | Security system with methodology for interprocess communication control |
| US7389512B2 (en) | 2003-05-09 | 2008-06-17 | Sun Microsystems, Inc. | Interprocess communication within operating system partitions |
| US7546613B2 (en) * | 2004-09-14 | 2009-06-09 | Oracle International Corporation | Methods and systems for efficient queue propagation using a single protocol-based remote procedure call to stream a batch of messages |
| US8214640B2 (en) * | 2005-12-05 | 2012-07-03 | Alcatel Lucent | Method of embedding information in implementation defined SIP header fields |
| US8286188B1 (en) | 2007-04-27 | 2012-10-09 | Marvell Israel (M.I.S.L.) Ltd. | Method and apparatus for advanced interprocess communication |
| EP2243271A1 (en) * | 2008-02-04 | 2010-10-27 | Telefonaktiebolaget L M Ericsson (publ) | Communication with compressed headers |
| CN102255972B (zh) * | 2011-08-10 | 2014-06-25 | 北京邮电大学 | 6LoWPAN网络中面向HTTP协议的TCP首部压缩方法 |
| CN104205114B (zh) | 2011-11-29 | 2018-08-07 | 索尼移动通信公司 | 用于提供安全的进程间通信的系统和方法 |
| CN103078921B (zh) * | 2012-12-28 | 2016-08-17 | Tcl集团股份有限公司 | 一种发送、接收消息的方法及装置 |
| CN106470212B (zh) * | 2016-10-13 | 2020-01-17 | 重庆金美通信有限责任公司 | 一种基于lzw压缩算法对eigrp协议报文进行压缩和加密的方法 |
| US10630654B2 (en) * | 2017-03-22 | 2020-04-21 | Microsoft Technology Licensing, Llc | Hardware-accelerated secure communication management |
| US20200104289A1 (en) * | 2018-09-27 | 2020-04-02 | Aptiv Technologies Limited | Sharing classified objects perceived by autonomous vehicles |
-
2017
- 2017-06-14 CN CN201710449251.1A patent/CN109086144B/zh active Active
-
2018
- 2018-06-05 WO PCT/CN2018/089929 patent/WO2018228238A1/zh not_active Ceased
-
2019
- 2019-12-13 US US16/714,522 patent/US11216320B2/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1592272A (zh) * | 2003-09-04 | 2005-03-09 | 国际商业机器公司 | 用于压缩消息头部的方法 |
| CN102023961A (zh) * | 2009-09-10 | 2011-04-20 | 中兴通讯股份有限公司 | 一种基于共享内存的通信方法及装置 |
| CN105634684A (zh) * | 2014-11-19 | 2016-06-01 | 中国移动通信集团广东有限公司 | 一种数据包的处理方法、装置及服务器 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109086144A (zh) | 2018-12-25 |
| US11216320B2 (en) | 2022-01-04 |
| US20200125430A1 (en) | 2020-04-23 |
| CN109086144B (zh) | 2022-04-05 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN105631035B (zh) | 数据存储方法和装置 | |
| TW201539187A (zh) | 快閃記憶體之壓縮、讀取方法及應用其方法的裝置 | |
| CN113873255B (zh) | 一种视频数据传输方法、视频数据解码方法及相关装置 | |
| CN109542361A (zh) | 一种分布式存储系统文件读取方法、系统及相关装置 | |
| CN110083221A (zh) | 电子装置及音频播放方法 | |
| CN110765395B (zh) | 一种用于提供小说信息的方法与设备 | |
| CN105007082A (zh) | 一种数据压缩方法、装置及终端 | |
| CN106502922A (zh) | 一种fifo数据缓存器的数据读写方法及数据缓存器 | |
| US10834435B2 (en) | Display apparatus and content display method thereof | |
| WO2023179742A1 (zh) | 数据访问方法及系统、硬件卸载设备、电子设备及介质 | |
| WO2021057665A1 (zh) | 数据存储方法、装置、移动终端及存储介质 | |
| CN105320669B (zh) | 数据存储、读取方法及数据存储、读取装置 | |
| TWI634421B (zh) | 用以存取資料之電子裝置及其資料存取方法 | |
| CN110928935A (zh) | 数据的访问命令处理方法、装置和系统 | |
| CN110688070B (zh) | 固态硬盘数据表的管理方法、装置、存储介质及电子设备 | |
| WO2018228238A1 (zh) | 一种进程之间的通信方法和装置 | |
| CN108495177A (zh) | 一种音频变速处理方法及装置 | |
| WO2020029527A1 (zh) | 显示界面切换方法、装置及电子设备 | |
| CN107832256A (zh) | 一种数据处理的方法及装置 | |
| HK40001273B (zh) | 一种进程之间的通信方法和装置 | |
| HK40001273A (zh) | 一种进程之间的通信方法和装置 | |
| TW201931353A (zh) | 音訊處理方法、裝置及非暫時性電腦可讀媒體 | |
| CN106507268B (zh) | 一种手机搬家中动态验证的方法及装置 | |
| WO2020107353A1 (zh) | 视频解码方法、装置、电子设备、计算机可读存储介质 | |
| CN115048347A (zh) | 一种文件动态压缩方法、系统、终端设备和存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18818099 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 18818099 Country of ref document: EP Kind code of ref document: A1 |