CN115334169A - Communication protocol coding method for saving network bandwidth - Google Patents
Communication protocol coding method for saving network bandwidth Download PDFInfo
- Publication number
- CN115334169A CN115334169A CN202210461679.9A CN202210461679A CN115334169A CN 115334169 A CN115334169 A CN 115334169A CN 202210461679 A CN202210461679 A CN 202210461679A CN 115334169 A CN115334169 A CN 115334169A
- Authority
- CN
- China
- Prior art keywords
- communication protocol
- data
- fields
- packet
- network bandwidth
- 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.)
- Granted
Links
Images
Classifications
-
- 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/06—Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]
-
- 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
Landscapes
- Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a communication protocol coding method for saving network bandwidth, which comprises a coding process and a decoding process, wherein the coding process comprises the steps of coding data content into a data packet; grouping fields to be encoded; preprocessing each field according to different data types; arranging the grouped field codes into a communication packet; carrying out conventional treatment; the decoding process comprises the steps of analyzing the data packet; analyzing the fields of the packet; conventional treatment is carried out. The invention comprises the following steps: (1) saving network traffic by about 35%. (2) The whole data range is flexibly processed, the change of a communication protocol caused by a small amount of data beyond the range is avoided, and the adaptability of the communication protocol and software is improved. (3) Compared with the compression coding, the coding method has no obvious consumption to the CPU and has stronger practicability.
Description
Technical Field
The invention relates to a communication protocol coding method for saving network bandwidth, belonging to the technical field of software design and development in the field of network communication.
Background
In network communication, before data is sent, the data needs to be encoded in a certain format and then sent to a network; after the opposite side receives the data, the data is decoded in a method opposite to the coding, so that the real data of the opposite side is obtained.
When data encoding is performed, each field needs to be arranged one by one, and common encoding methods for communication protocols include:
(1) Encoding in a fixed-length text mode;
(2) Variable length text mode encoding with separators;
(3) Binary coding;
(4) XML format, etc.;
(5) And transmitting after compression.
Different coding methods are generally selected for different occasions. Each method has respective advantages and disadvantages, for example, the binary system saves network bandwidth compared with the text mode, but the manual reading is difficult; lengthening saves bandwidth over fixing, but lengthening is more complex to process for computer programming. XML is highly human readable, but is almost the most expensive in terms of network bandwidth consumption, and typically must rely on third party libraries to translate entities.
In order to save network bandwidth, people compress data and then transmit the data, thereby saving bandwidth. Tests have shown that this approach is not feasible and can be invaluable for real-time communication due to the excessive consumption of CPU resources by the compressed data. Therefore, almost no one in real-time communication applications takes a compression approach, except in non-real-time communication.
Disclosure of Invention
The present invention is directed to a communication protocol encoding method for saving network bandwidth, so as to solve the problems in the background art mentioned above.
In order to achieve the purpose, the invention provides the following technical scheme: a communication protocol encoding method for saving network bandwidth comprises an encoding process and a decoding process, wherein the encoding process comprises steps 1 to 5, and the decoding process comprises steps 6 to 8:
step 1, data content is coded into a data packet;
step 2, grouping fields to be coded;
step 3, respectively carrying out the following preprocessing on each field according to different data types;
step 4, arranging the grouped field codes into a communication packet;
step 5, performing conventional treatment;
step 6, analyzing the data packet;
7, analyzing the grouped fields;
and 8, performing conventional treatment.
Preferably, the step 2 groups fields to be coded in groups of four fields, and groups fields with less than four fields at the end.
Preferably, the preprocessing manner of step 3 includes, but is not limited to, preprocessing with a conforming type, an unsigned type, a string type, and a floating point type.
Preferably, the conventional processing of step 5 includes, but is not limited to, adding a check field of a packet tail.
Preferably, the normal processing of step 8 includes, but is not limited to, parsing the check field.
Compared with the prior art, the invention has the beneficial effects that:
(1) Saving network traffic by about 35%.
Suppose that 70% of the memory in a packet is integer and the rest are floating points or strings. Since in most cases integer shapes are small numbers and character strings are short, especially in the financial industry, integer shapes can usually be represented by no more than 1 byte or 2 bytes, while in computers we often use 4 bytes or 8 bytes to represent, which results in more than half of the bytes being wasted. Assuming that the integer wastes 50% of the space (in the present invention, although one byte is supplemented before each group, this one byte is negligible for a large number of integers that are wasted more than half the length), the overall waste rate is 70% × 50% =35%. That is, with the present invention, it is possible to reduce the packet size by 35% in most cases, or to save 35% of the network traffic, or bandwidth consumption.
For example, in the market price, the declared quantity, etc. of the financial industry, after the decimal point is removed, the data size generally does not exceed 65535, but the possibility of exceeding 65535 cannot be completely eliminated. For example, 95% of stock prices do not exceed 655 yuan, but Guizhou Maotai exceeds 1000 yuan, if the stock prices are all represented by 4 bytes in network transmission, the waste is very high, and a large amount of bandwidth can be saved by adopting the coding method of the communication protocol.
(2) Compared with a field coding method with fixed length, the coding method has flexible processing on the integer data range, avoids the change of a communication protocol caused by a small amount of data beyond the range, and improves the adaptability of the communication protocol and software.
The traditional fixed-length field cannot expand the length of data, and in case of exceeding an expected data range in the future, the communication protocol becomes invalid, only the communication protocol can be redesigned, and software needs to be redeveloped by both communication parties, so that a large amount of cost is caused. The coding method is uniform for the integer data expressed by no matter a few bytes, and the problems of redesign of a communication protocol and recoding of software caused by expansion of a data range in use are solved.
(3) Compared with the compression coding, the coding method has no obvious consumption to the CPU and has stronger practicability. The compression coding method is basically not practical in real-time communication.
Drawings
Fig. 1 is a schematic diagram of packet information according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention are clearly and completely described below, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention provides a technical scheme that: the coding is performed in binary. The communication protocol header is not considered at all, is generally short and only needs to be adopted in a conventional mode. Only the coding of the individual fields is considered here.
1. The specific encoding process is as follows:
encoding means that data is packed before being sent to form a data stream, and finally the data stream is sent through a network.
Step 1: the data packet is encoded with contents such as a protocol header.
Step 2: the fields to be encoded are grouped in groups of four fields with less than four fields at the end.
And 3, step 3: and respectively preprocessing each field according to different data types as follows:
(1) Signed integer (whether 1, 2, 4 or 8 byte integer):
(1) if the integer range is [ -128,127], i.e. 1 byte can be represented, a signed integer of one byte is forced;
(2) if the integer range is not in the range and is in the range of-32768, 32767, that is, 2 bytes can be represented, the conversion is forced to be signed integer of two bytes;
(3) if the integer range is not in the above range, but in the range of [ -2147483648,2147483647], i.e. 4 bytes can be represented, then the conversion is forced to be a signed integer of four bytes;
(4) in other cases (referring to int64 not in the above range), no conversion is performed.
(2) Unsigned integer (whether 1, 2, 4, or 8 byte integer):
(1) if the integer range is [0,0xFF ], i.e. 1 byte can be represented, then the conversion is forced into unsigned integer of one byte;
(2) if the integer range is [0x100,0xFFFF ], i.e. 2 bytes can be represented, then the conversion is forced to be unsigned integer of two bytes;
(3) if the integer range is [0x10000,0xFFFFFFFF ], i.e. 4 bytes can be represented, then the conversion is forced to be unsigned integer of four bytes;
(4) otherwise (referring to agent 64 greater than 0 xFFFFFFFF), no conversion is performed.
(3) The type of character string: the type will be arranged in a way that length + string content is used. For the length therein, the same way as the above unsigned integer is used for storage.
(4) Floating point type (including float single precision and double precision): binary data is used directly without conversion.
And 4, step 4: encoding and arranging the mode of every four fields in one group into a communication packet, wherein the specific flow is as follows:
(1) First, a binary one-byte integer is written (for one-byte integer, the size-end endianness is the same, so conversion is not needed), which is called packet information. As shown in fig. 1. Since each byte has 8 bits, these 8 bits are equally divided into four parts, and each 2 bits represents the length of the value in the corresponding field of the subsequent group. That is to say:
bits 1 to 2, indicate the length of the value in the 1 st field in the subsequent group.
Bits 3 to 4, indicate the length of the value in the 2 nd field of the subsequent group.
Bits 5 to 6 indicate the length of the value in the 3 rd field in the subsequent group.
Bits 7 to 8, indicate the length of the value in the 4 th field of the subsequent group.
Wherein, every 2 bits can only represent four possible values of 0, 1, 2 and 3, and the meaning is:
0: indicating that the value length in the corresponding field that follows is 1 byte.
1: indicating that the value length in the corresponding field that follows is 2 bytes.
2: indicating that the value in the corresponding field that follows is 4 bytes in length.
3: indicating that the value length in the corresponding field that follows is 8 bytes.
For the last group, if there are less than 4 fields, the corresponding position may be filled with 0.
(2) The four fields of the group are written next in sequence, each field having the following format:
(1) if the character string is of a character string type, the length (big-endian representation) and the character string content which are preprocessed by the method are written in sequence.
(2) If the type is a floating point type (comprising float single precision and double precision), the binary content of the corresponding big endian is directly written.
(3) If it is an integer type, including signed and unsigned integer, then write the integer that the above method has preprocessed (big-endian method).
And 5, step 5: other conventional processing such as adding a check field at the end of the packet, etc. Because it belongs to the conventional processing and does not belong to the scope of the present invention, the detailed description is omitted.
The specific decoding process is as follows:
decoding refers to the process of unpacking the data received from the network to obtain the original information.
Step 1: the packet header and other contents are analyzed. Since they are not part of the present invention, they will not be described in detail herein.
Step 2: circularly analyzing each four-field packet, wherein the flow is as follows:
(1) Firstly, one byte of packet information is analyzed:
bits 1 to 2, indicate the length of the value in the 1 st field in the subsequent group.
Bits 3 to 4, indicate the length of the value in the 2 nd field of the subsequent group.
Bits 5 to 6 indicate the length of the value in the 3 rd field in the subsequent group.
Bits 7 to 8, indicate the length of the value in the 4 th field of the subsequent group.
Wherein, each 2 bits can only represent four possible values of 0, 1, 2 and 3, and the meaning is as follows:
0: indicating that the value length in the corresponding field that follows is 1 byte.
1: indicating that the value length in the corresponding field that follows is 2 bytes.
2: indicating that the value length in the corresponding field that follows is 4 bytes.
3: indicating that the value in the corresponding field that follows is 8 bytes in length.
For the last group, if there are less than 4 fields, the remainder can be ignored.
(2) The 1 st, 2 nd, 3 th and 4 th fields in the group are sequentially analyzed.
The data type of each field needs to be determined according to the agreement of both parties. Care should be taken to convert to native endianness. The storage length of the local integer can only be larger than or equal to the received length value, otherwise, an error is always existed.
If the last packet has less than four fields, the remainder is ignored.
And 3, step 3: other conventional processing such as parsing the check field of the trailer, etc.
The invention has practical value in real-time communication application, reduces network flow, saves about 35% of network bandwidth compared with a common binary coding method under the condition of no information loss, and simultaneously improves the adaptability of the protocol to various data ranges.
Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and alterations can be made in these embodiments without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.
Claims (5)
1. A communication protocol encoding method for saving network bandwidth is characterized in that the method comprises an encoding process and a decoding process, wherein the encoding process comprises steps 1 to 5, and the decoding process comprises steps 6 to 8:
step 1, data content is coded into a data packet;
step 2, grouping fields to be coded;
step 3, respectively carrying out the following pretreatment on each field according to different data types;
step 4, arranging the grouped field codes into a communication packet;
step 5, performing conventional treatment;
step 6, analyzing the data packet;
7, analyzing the grouped fields;
and 8, performing conventional treatment.
2. The network bandwidth saving communication protocol encoding method of claim 1, wherein: and the step 2 is to group every four fields to be coded, wherein the fields with less than four ends are grouped.
3. The network bandwidth saving communication protocol encoding method of claim 1, wherein: the preprocessing mode of the step 3 includes but is not limited to preprocessing a matched type, an unsigned type, a character string type and a floating point type.
4. The network bandwidth saving communication protocol encoding method of claim 1, wherein: the conventional processing of step 5 includes, but is not limited to, adding a check field of the packet tail.
5. The network bandwidth saving communication protocol encoding method of claim 1, wherein: the conventional processing of step 8 includes, but is not limited to, parsing the check field.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210461679.9A CN115334169B (en) | 2022-04-28 | 2022-04-28 | Communication protocol coding method capable of saving network bandwidth |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210461679.9A CN115334169B (en) | 2022-04-28 | 2022-04-28 | Communication protocol coding method capable of saving network bandwidth |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115334169A true CN115334169A (en) | 2022-11-11 |
CN115334169B CN115334169B (en) | 2023-06-06 |
Family
ID=83915877
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210461679.9A Active CN115334169B (en) | 2022-04-28 | 2022-04-28 | Communication protocol coding method capable of saving network bandwidth |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115334169B (en) |
Citations (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CA2065578A1 (en) * | 1991-04-22 | 1992-10-23 | David W. Carr | Packet-based data compression method |
US6591310B1 (en) * | 2000-05-11 | 2003-07-08 | Lsi Logic Corporation | Method of responding to I/O request and associated reply descriptor |
CN1459179A (en) * | 2000-07-25 | 2003-11-26 | 西门子公司 | Header compression method for network protocols |
CN1608255A (en) * | 2001-12-28 | 2005-04-20 | 英特尔公司 | Communicating transaction types between agents in a computer system using packet headers including an extended type/extended length field |
US20050193056A1 (en) * | 2002-12-26 | 2005-09-01 | Schaefer Diane E. | Message transfer using multiplexed connections in an open system interconnection transaction processing environment |
US20070226483A1 (en) * | 2006-03-24 | 2007-09-27 | Dennis Cox | System and method for storing and/or transmitting emulated network flows |
CN101312448A (en) * | 2007-05-23 | 2008-11-26 | 神乎科技股份有限公司 | Data process method |
US20100191777A1 (en) * | 2009-01-27 | 2010-07-29 | Tatu Ylonen Oy Ltd | Serialization of shared and cyclic data structures using compressed object encodings |
CN102984123A (en) * | 2001-12-28 | 2013-03-20 | 英特尔公司 | Communicating message request transaction types between agents in a computer system using multiple message groups |
CN106549673A (en) * | 2016-10-27 | 2017-03-29 | 深圳市金证科技股份有限公司 | A kind of data compression method and device |
CN106657441A (en) * | 2017-01-11 | 2017-05-10 | 深圳证券通信有限公司 | Algorithm for generating unique packet ID of financial data exchange message |
CN109525364A (en) * | 2018-10-30 | 2019-03-26 | 北京计算机技术及应用研究所 | A kind of telecommunication data protocol generalization based on XML describes method |
CN111309449A (en) * | 2020-03-17 | 2020-06-19 | 上海蓝载信息科技有限公司 | Programming language independent virtual machine oriented to meta-programming, interactive programming and blockchain interoperation |
CN112783974A (en) * | 2020-12-31 | 2021-05-11 | 杭州趣链科技有限公司 | Data conversion method, device, equipment and storage medium |
CN113114655A (en) * | 2021-04-07 | 2021-07-13 | 深圳市瑞驰信息技术有限公司 | Binary data interaction protocol design method based on TCP/IP |
-
2022
- 2022-04-28 CN CN202210461679.9A patent/CN115334169B/en active Active
Patent Citations (16)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5293379A (en) * | 1991-04-22 | 1994-03-08 | Gandalf Technologies, Inc. | Packet-based data compression method |
CA2065578A1 (en) * | 1991-04-22 | 1992-10-23 | David W. Carr | Packet-based data compression method |
US6591310B1 (en) * | 2000-05-11 | 2003-07-08 | Lsi Logic Corporation | Method of responding to I/O request and associated reply descriptor |
CN1459179A (en) * | 2000-07-25 | 2003-11-26 | 西门子公司 | Header compression method for network protocols |
CN102984123A (en) * | 2001-12-28 | 2013-03-20 | 英特尔公司 | Communicating message request transaction types between agents in a computer system using multiple message groups |
CN1608255A (en) * | 2001-12-28 | 2005-04-20 | 英特尔公司 | Communicating transaction types between agents in a computer system using packet headers including an extended type/extended length field |
US20050193056A1 (en) * | 2002-12-26 | 2005-09-01 | Schaefer Diane E. | Message transfer using multiplexed connections in an open system interconnection transaction processing environment |
US20070226483A1 (en) * | 2006-03-24 | 2007-09-27 | Dennis Cox | System and method for storing and/or transmitting emulated network flows |
CN101312448A (en) * | 2007-05-23 | 2008-11-26 | 神乎科技股份有限公司 | Data process method |
US20100191777A1 (en) * | 2009-01-27 | 2010-07-29 | Tatu Ylonen Oy Ltd | Serialization of shared and cyclic data structures using compressed object encodings |
CN106549673A (en) * | 2016-10-27 | 2017-03-29 | 深圳市金证科技股份有限公司 | A kind of data compression method and device |
CN106657441A (en) * | 2017-01-11 | 2017-05-10 | 深圳证券通信有限公司 | Algorithm for generating unique packet ID of financial data exchange message |
CN109525364A (en) * | 2018-10-30 | 2019-03-26 | 北京计算机技术及应用研究所 | A kind of telecommunication data protocol generalization based on XML describes method |
CN111309449A (en) * | 2020-03-17 | 2020-06-19 | 上海蓝载信息科技有限公司 | Programming language independent virtual machine oriented to meta-programming, interactive programming and blockchain interoperation |
CN112783974A (en) * | 2020-12-31 | 2021-05-11 | 杭州趣链科技有限公司 | Data conversion method, device, equipment and storage medium |
CN113114655A (en) * | 2021-04-07 | 2021-07-13 | 深圳市瑞驰信息技术有限公司 | Binary data interaction protocol design method based on TCP/IP |
Non-Patent Citations (4)
Title |
---|
LONGSHE HUO: "Grouped unequal loss protection for scalable media transmission", 《IEEE XPLORE》 * |
康松林: "简单网络管理协议分析仪的设计与实现", 《电脑与信息技术》, no. 2004 * |
盛庆博: "报文管理与编解码技术研究", 《CNKI中国知网》 * |
陈雪君: "基于动态编码的多属性感知多路径协同调度机制的研究与实现", 《CNKI中国知网》 * |
Also Published As
Publication number | Publication date |
---|---|
CN115334169B (en) | 2023-06-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8775927B2 (en) | Method for compressing XML documents into valid XML documents | |
US8060652B2 (en) | Extensible binary mark-up language for efficient XML-based data communications and related systems and methods | |
KR100614677B1 (en) | Method for compressing/decompressing a structured document | |
US7099884B2 (en) | System and method for data compression and decompression | |
US7924183B2 (en) | Method and system for reducing required storage during decompression of a compressed file | |
US20050086452A1 (en) | Enhanced boolean processor with parallel input | |
EP2858323A1 (en) | A method and a device for decoding data streams in reconfigurable platforms | |
US4574382A (en) | Variable length character code system | |
EP2219117A1 (en) | A processing module, a device, and a method for processing of XML data | |
US5701468A (en) | System for performing data compression based on a Liu-Zempel algorithm | |
US11955995B2 (en) | Apparatus and method for two-stage lossless data compression, and two-stage lossless data decompression | |
JP2004508647A (en) | Structured document compression / decompression method | |
CN111131403A (en) | Message coding and decoding method and device for Internet of things equipment | |
CN102096704B (en) | XML (extensible markup language) compression method and device | |
TWI273779B (en) | Method and apparatus for optimized lossless compression using a plurality of coders | |
CN114492316B (en) | Data exchange coding and decoding method and system | |
CN103605730A (en) | XML (extensible markup language) compressing method and device based on flexible-length identification codes | |
CN115334169B (en) | Communication protocol coding method capable of saving network bandwidth | |
CN112153054B (en) | Method and system for realizing splicing cache with any byte length | |
CN112017049B (en) | Security quotation forwarding system and method | |
US6611211B2 (en) | Data mask coding | |
CN117278053B (en) | GLTF-JSON format data compression method, system and device | |
Ridgewell et al. | Evaluating the Size of the SOAP for Integration in B2B | |
JPS62209948A (en) | Data compressing and transmitting method | |
Zhao et al. | A Configuration-Based Method For Conversion Between Binary Structure Data And JSON |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |