Encapsulation method, analysis method and device for data in message transmission
By determining the encoding mode according to the attributes and transmission modes of the application data, the data is encoded, the problem of low data transmission efficiency in existing technologies has been solved, and the efficient utilization of resources and the improvement of application system performance have been achieved.
Patent Information
- Application Number
- CN202411513482.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-10-28
AI Technical Summary
In the prior art, it is difficult to efficiently transmit data blocks with uncertain data types and uncertain data lengths in data transmission, resulting in waste of resources and reduced transmission efficiency.
Determine the encoding mode according to the attributes and transmission mode of the application data, and encode the data to generate target messages. Different data types and transmission modes correspond to different encoding modes, rationally use resources, and improve transmission efficiency.
Realize the efficient coding of different data types and transmission modes, rationally use resources, improve transmission efficiency, and improve the performance of the application system.
Smart Images

Figure CN119383226A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic and computer data processing, and in particular to a data encapsulation method, a parsing method and a device in message transmission. Background Art
[0002] Computer network protocols, as the cornerstone of building a network communication system, are usually divided into seven levels. Among these seven levels, the transport layer plays a vital role. It mainly relies on TCP / IP or UDP protocols and is committed to solving the problem of network data packet transmission. At this level, the focus is not on specific data types, but on how to efficiently and accurately complete data transmission.
[0003] Generally speaking, when building business applications, most application layer systems are built on the basis of transport layer protocols. In the process of interaction at the application layer, in order to ensure accurate expression and efficient processing of data, a series of basic data types are usually defined, such as integer (int), double precision floating point type (double), single precision floating point type (float), string (string), and binary array. These data types provide basic specifications for data exchange at the application layer. These basic types are usually of variable length, so a field is generally required to identify their length during the transmission process.
[0004] However, when transmitting data, especially through narrow bandwidth transmission links, the transmission efficiency and quality of these basic data types often become an issue that needs to be considered. When defining common application protocols, there is often a challenge, that is, how to effectively transmit a data block of uncertain data type and data length in a message, which is particularly common in the application layer. Although the key-value pair method can meet basic transmission requirements, it is not the most ideal choice in today's pursuit of efficient transmission. For each message, a coding method is used to transmit various data types, and different data types have the same coding method, which causes a waste of resources, leads to a decrease in transmission efficiency, and even affects the performance of the entire application system. Summary of the invention
[0005] In order to solve the above problems existing in the prior art, the present invention provides a data encapsulation method, parsing method and device in message transmission. The technical problem to be solved by the present invention is achieved by the following technical solutions:
[0006] A first aspect of an embodiment of the present invention provides a method for encapsulating and parsing data in message transmission, comprising the following steps:
[0007] Determine the encoding mode according to the attributes and transmission mode of the application data;
[0008] Encoding the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message; wherein the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode;
[0009] The target message is transmitted to a message recipient.
[0010] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0011] When the field type of the application data is String and is an empty string, the encoding mode is the first string mode;
[0012] When the field type of the application data is String and the transmission mode is the first transmission mode NONE, the encoding mode is the second string mode;
[0013] When the field type of the application data is String, and the transmission mode is the second transmission mode FAST, and the maximum actual length of the string is less than 21 bits, the encoding mode is the third string mode;
[0014] When the field type of the application data is String, the transmission mode is the second transmission mode FAST, and the minimum actual length of the string is 21 bits, the encoding mode is the fourth string mode;
[0015] When the field type of the application data is String, and the transmission mode is the third transmission mode MAX, and the maximum actual length of the string is less than 21 bits, the encoding mode is the fifth string mode;
[0016] When the field type of the application data is String, the transmission mode is the third transmission mode MAX, and the minimum actual length of the string is 21 bits, the encoding mode is the sixth string mode;
[0017] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0018] When the encoding mode is the first string mode, the value of the field type in the target message is 0x83, and the length is 1 byte; wherein 0x83 is a custom encoding value, and 0x8 indicates that the field type is a string, and is an empty string;
[0019] When the encoding mode is the second string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0020] When the encoding mode is the third string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0021] When the encoding mode is the fourth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0022] When the encoding mode is the fifth string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string that does not carry null;
[0023] When the encoding mode is the sixth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string without null.
[0024] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0025] When the field type of the application data is Int8, the encoding mode is Int8 mode;
[0026] When the field type of the application data is Int16, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 7 bits, the encoding mode is the 16-bit integer first mode;
[0027] When the field type of the application data is Int16, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 7 bits, the encoding mode is the 16-bit integer second mode;
[0028] When the field type of the application data is Int32, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 21 bits, the encoding mode is the 32-bit integer first mode;
[0029] When the field type of the application data is Int32, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 21 bits, the encoding mode is the 32-bit integer second mode;
[0030] When the field type of the application data is Int64, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 49 bits, the encoding mode is the 64-bit integer first mode;
[0031] When the field type of the application data is Int64, the transmission mode is the fourth transmission mode notNONE, and the maximum length of the field value is less than 49 bits, the encoding mode is the 64-bit integer second mode;
[0032] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0033] When the encoding mode is Int8 mode, the length of the field type in the target message is 1 byte, the value is 0x07, the length of the field value is 1 byte, and the value is the actual value;
[0034] When the encoding mode is the 16-bit integer first mode, the value of the field type in the target message is 0x09, the length is 1 byte, the length of the field value is 2 bytes, and the value is the actual value;
[0035] When the encoding mode is the 16-bit integer second mode, the value of the field type in the target message is 0x49, the length is 1 byte, the length of the field value is 1 byte, and the value is the actual value;
[0036] When the encoding mode is the 32-bit integer first mode, the value of the field type in the target message is 0x0B, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value;
[0037] When the encoding mode is the 32-bit integer second mode, the value of the field type in the target message is 0x4B, the length is 1 byte, the maximum length of the field value is 3 bytes, and the value is the actual value;
[0038] When the encoding mode is the 64-bit integer first mode, the value of the field type in the target message is 0x0D, the length is 1 byte, the length of the field value is 8 bytes, and the value is the actual value;
[0039] When the encoding mode is the 64-bit integer second mode, the value of the field type in the target message is 0x4D, the length is 1 byte, the maximum length of the field value is 7 bytes, and the value is the actual value.
[0040] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0041] When the field type of the application data is a Boolean type and the transmission mode is the first transmission mode NONE, the encoding mode is a Boolean first mode;
[0042] When the field type of the application data is a Boolean type and the transmission mode is the fourth transmission mode not NONE, the encoding mode is the Boolean second mode;
[0043] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0044] When the encoding mode is the Boolean first mode, the value of the field type in the target message is 0x11, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value;
[0045] When the encoding mode is the Boolean second mode, the value of the field type in the target message is 0xD1 or 0x51, and the length is 1 byte; wherein 0xD1 and 0x51 are custom encoding values, 0xD1 indicates that the field type is Boolean and the value is true, and 0x51 indicates that the field type is Boolean and the value is false.
[0046] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0047] When the field type of the application data is an object, and the transmission mode is the first transmission mode NONE or the minimum length of the object is 21, the encoding mode is the object type first mode;
[0048] When the field type of the application data is object, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the object is less than 21 bits, the encoding mode is the object type second mode;
[0049] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0050] When the encoding mode is the object type first mode, the value of the field type in the target message is 0x16, 0x17 or 0x18, the length is 1 byte, the length of the field length is 4 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field;
[0051] When the encoding mode is the object type second mode, the value of the field type in the target message is 0x56, 0x57 or 0x58, the length is 1 byte, the maximum length of the field length is 3 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field;
[0052] Among them, 0x16 and 0x56 indicate that the field type is opaque, 0x17 and 0x57 indicate that the field type is java obj, and 0x18 and 0x58 indicate that the field type is dotnet obj.
[0053] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0054] When the field type of the application data is message and the message is empty, the encoding mode is the first message type mode;
[0055] When the field type of the application data is a message and the message is not empty, the encoding mode is the message type second mode;
[0056] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0057] When the encoding mode is the message type first mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, and the value is 0;
[0058] When the encoding mode is the message type second mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, the value is the value of the message length, the value of the message content is the serialized message content, and the length is the value of the message length.
[0059] A second aspect of an embodiment of the present invention provides a method for parsing data in message transmission, which is applied to a message receiver and includes the following steps:
[0060] Receive the target message sent by the message sender;
[0061] The target message is parsed.
[0062] A third aspect of an embodiment of the present invention provides a device for encapsulating data in message transmission, which is applied to a message sender, and includes:
[0063] A determination module, used to determine the encoding mode according to the attributes and transmission mode of the application data;
[0064] A generating module, configured to encode the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message; wherein the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode;
[0065] The sending module is used to transmit the target message to the message recipient.
[0066] A fourth aspect of an embodiment of the present invention provides a device for parsing data in message transmission, which is applied to a message receiver, including:
[0067] A receiving module, used for receiving a target message sent by a message sender;
[0068] The parsing module is used to parse the target message.
[0069] Beneficial effects of the present invention:
[0070] The present invention encodes application data by adopting different encoding modes according to the attributes and transmission modes of the application data, so that different data types of the application data can be encoded differently, and the same data type can further be encoded differently. After encoding, the largest data is represented by the smallest transmission byte, which reasonably utilizes resources, improves transmission efficiency, and enhances the performance of the application system.
[0071] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0072] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0074] Figure 1 A schematic diagram of a flow chart of a data encapsulation method and a parsing method in message transmission provided by an embodiment of the present invention;
[0075] Figure 2 A block diagram of a data encapsulation method and parsing device in message transmission provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0076] The present invention is further described in detail below with reference to specific embodiments, but the embodiments of the present invention are not limited thereto.
[0077] like Figure 1 As shown, a first aspect of an embodiment of the present invention provides a method for encapsulating data in message transmission, which is applied to a message sender and includes the following steps:
[0078] Step 11: Determine the encoding mode according to the attributes and transmission mode of the application data.
[0079] Step 12: Encode the application data according to the encoding mode, the variant data type, and the value of the custom encoding value to generate a target message.
[0080] Different attributes and transmission modes correspond to different encoding modes; the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode.
[0081] Step 13: Transmit the target message to the message recipient.
[0082] This embodiment encodes the application data by using different encoding modes according to the attributes and transmission modes of the application data, so that different data types of the application data are encoded using different encoding modes, and the same data type can be further encoded using different encoding modes. After encoding, the largest data is represented by the smallest transmission byte, avoiding the waste of resources caused by using the same encoding (for example, data of a smaller length is also encoded using a larger fixed length, which will cause a waste of resources), and making reasonable use of resources. At the same time, the same transmission mode can use different encoding methods according to actual needs, further making reasonable use of resources, improving transmission efficiency, and enhancing the performance of the application system.
[0083] A second aspect of an embodiment of the present invention provides a method for encapsulating data in message transmission, comprising the following steps:
[0084] Step 21: The message sender determines the encoding mode according to the attributes and transmission mode of the application data.
[0085] In this step, different attributes and transmission modes of the application data may correspond to different encoding modes. The message sender may determine which type each field or type of each type of field of the application data belongs to, determine the type of the transmission mode and which conditions other attributes meet, and thus automatically match the corresponding encoding mode. The transmission mode may be set as required, and the present invention represents a more specific field type of the application data based on the form of the variant data type.
[0086] Through a mapping table, fixed values are used to correspond to basic data types, as shown in Table 1:
[0087]
[0088]
[0089] Table 1
[0090] Step 22: The message sender encodes the application data according to the encoding mode, the variant data type, and the value of the custom encoding value to generate a target message.
[0091] Different attributes and transmission modes correspond to different encoding modes; the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode.
[0092] In this step, the application data is encoded after the encoding mode of each field is determined.
[0093] Specifically, the specific encoding method is described in detail below:
[0094] 1. When the field type of the application data is String:
[0095] 1. If it is an empty string, the encoding mode is the first string mode. At this time, there is no need to consider the transmission mode. When the encoding mode is the first string mode, the encoding method in the target message is: the value of the field type is 0x83, and the length of the field type is 1 byte. Here, the value of the field type is represented by 0x83, and 0x83 is a custom encoding value. 0x83 can indicate that the field type is a string and an empty string. 0x83 indicates both the field type and an attribute of the string.
[0096] 2. If it is a non-empty string and the transmission mode is the first transmission mode NONE, the encoding mode is the second string mode. When the encoding mode is the second string mode, the encoding method in the target message is: the length of the field type is 1 byte, the value of the field type is 0x03, the length of the string is 4 bytes, the value of the string length is the actual length of the string, the length of the string is the actual length of the string plus 1, and the value of the string is a string terminated by null.
[0097] Here, when encoding a string, it is necessary to encode the field type, the value of the field type, the string length, the value of the string length, the length of the string, and the value of the string. The length of the string is different from the length of the string. There is information in the encoding information that limits the length of the string. For example, it is required to limit the string length of a certain field in the application data to only 4 bytes (specifying the length of the content to be filled in).
[0098] For null-terminated strings, they can be parsed directly without copying them when parsing messages, which improves the parsing speed of the string.
[0099] 3. If the transmission mode is the second transmission mode FAST and the maximum actual length of the string is less than 21 bits, the encoding mode is the third string mode. Here, the attributes of the application data are further limited. When the transmission mode is the second transmission mode FAST and the maximum actual length of the string is less than 21 bits, the encoding mode is determined to be the third string mode.
[0100] When the encoding mode is the third string mode, the encoding method in the target message is: the length of the field type is 1 byte, the value of the field type is 0x43, the maximum length of the string length is 3 bytes, the value of the string length is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value of the string is a string terminated by null. Here, the length of the string length can be 1 to 3 bytes.
[0101] 4. If the transmission mode is the second transmission mode FAST and the minimum actual length of the character string is 21 bits, the encoding mode is the fourth character string mode.
[0102] When the encoding mode is the fourth string mode, the encoding method in the target message is: the length of the field type is 1 byte, the value of the field type is 0x03, the length of the string is 4 bytes, the value of the string length is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value of the string is a string terminated by null.
[0103] When the transmission mode is the second transmission mode, different encoding modes can be adaptively selected according to the length of the character string to efficiently perform encoding, thereby reasonably utilizing resources.
[0104] 5. If the transmission mode is the third transmission mode MAX and the maximum actual length of the character string is less than 21 bits, the encoding mode is determined to be the fifth character string mode.
[0105] When the encoding mode is the fifth string mode, the encoding method in the target message is: the length of the field type is 1 byte, the value of the field type is 0x43, the maximum length of the string length is 3 bytes, the value of the string length is the actual length of the string, the length of the string is the actual length of the string, and the value of the string is a string that does not carry null. Here, the length of the string length can be 1 to 3 bytes.
[0106] 6. If the transmission mode is the third transmission mode MAX and the minimum actual length of the character string is 21 bits, determine that the encoding mode is the sixth character string mode.
[0107] When the encoding mode is the sixth string mode, the encoding method in the target message is: the length of the field type is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value of the string length is the actual length of the string, the length of the string is the actual length of the string, and the value of the string is a string without null.
[0108] For example, the encoding method is shown in Table 2: compact is the transmission mode.
[0109]
[0110]
[0111] Table 2
[0112] In this embodiment, in the same transmission mode, encoding can be performed according to encoding methods adopted according to different lengths of character strings.
[0113] 2. When the field type of the application data is Int:
[0114] 1. When the field type of the application data is Int8, the encoding mode is Int8 mode.
[0115] When the encoding mode is Int8 mode, the encoding method in the target message is: the length of the field type is 1 byte, the value of the field type is 0x07, the length of the field value is 1 byte, and the value of the field is the actual value.
[0116] For example, the encoding method is shown in Table 3:
[0117] Field Name Size Value Type 1 0x07 Value 1 Value
[0118] Table 3
[0119] 2. When the field type of the application data is Int16, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 7 bits, the encoding mode is the 16-bit integer first mode.
[0120] When the encoding mode is 16-bit integer first mode, the encoding method in the target message is: the value of the field type is 0x09, the length of the field type is 1 byte, the length of the field value is 2 bytes, and the value of the field is the actual value.
[0121] 3. When the field type of the application data is Int16, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 7 bits, the encoding mode is the 16-bit integer second mode.
[0122] When the encoding mode is the 16-bit integer second mode, the encoding method in the target message is: the value of the field type is 0x49, the length of the field type is 1 byte, the length of the field value is 1 byte, and the value of the field is the actual value.
[0123] For example, the encoding method is shown in Table 4:
[0124]
[0125] Table 4
[0126] 4. When the field type of the application data is Int32, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 21 bits, the encoding mode is the 32-bit integer first mode.
[0127] When the encoding mode is the 32-bit integer first mode, the encoding method in the target message is that the value of the field type is 0x0B, the length of the field type is 1 byte, the length of the field value is 4 bytes, and the value of the field is the actual value.
[0128] 5. When the field type of the application data is Int32, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 21 bits, the encoding mode is the 32-bit integer second mode.
[0129] When the encoding mode is 32-bit integer second mode, the encoding mode in the target message is that the value of the field type is 0x4B, the length of the field type is 1 byte, the maximum length of the field value is 3 bytes, and the field value is the actual value. The length of the field value can be 1 to 3 bytes.
[0130] For example, the encoding method is shown in Table 5:
[0131]
[0132] Table 5
[0133] 6. When the field type of the application data is Int64, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 49 bits, the encoding mode is the 64-bit integer first mode.
[0134] When the encoding mode is the 64-bit integer first mode, the encoding method in the target message is that the value of the field type is 0x0D, the length is 1 byte, the length of the field value is 8 bytes, and the value is the actual value.
[0135] 7. When the field type of the application data is Int64, the transmission mode is the fourth transmission mode notNONE, and the maximum length of the field value is less than 49 bits, the encoding mode is the 64-bit integer second mode.
[0136] When the encoding mode is 64-bit integer second mode, the encoding method in the target message is: the value of the field type is 0x4D, the length is 1 byte, the maximum length of the field value is 7 bytes, and the field value is the actual value. The length of the field value can be 1 to 7 bytes.
[0137] For example, the encoding method is shown in Table 6:
[0138]
[0139]
[0140] Table 6
[0141] 3. When the field type of the application data is Boolean:
[0142] 1. When the transmission mode is the first transmission mode NONE, the encoding mode is the Boolean first mode.
[0143] When the encoding mode is Boolean first mode, the encoding method in the target message is: the value of the field type is 0x11, the length of the field type is 1 byte, the length of the field value is 4 bytes, and the value of the field is the actual value.
[0144] 2. When the transmission mode is the fourth transmission mode not NONE, the encoding mode is the Boolean second mode.
[0145] When the encoding mode is the Boolean second mode, the value of the field type in the target message is 0xD1 or 0x51, and the length of the field type is 1 byte.
[0146] Among them, 0xD1 and 0x51 are custom encoding values. 0xD1 can indicate that the type of the field is Boolean and the value is true, and 0x51 can indicate that the type of the field is Boolean and the value is false. Here, the custom encoding value can reduce the length and bytes of the encoded data and save space.
[0147] For example, the encoding method is shown in Table 7:
[0148]
[0149] Table 7
[0150] 4. When the field type of the application data is an object: The object here is a non-directly readable object. Like a string, the size of a non-directly readable object is variable. A non-directly readable object can be OPAQUE, JAVA_OBJ, or .NET_OBJ. A non-directly readable object first stores its size and then stores data.
[0151] 1. When the transmission mode is the first transmission mode NONE or the minimum length of the object is 21, the encoding mode is the object type first mode.
[0152] When the encoding mode is object-first mode, the encoding method in the target message is: the value of the field type is 0x16, 0x17 or 0x18, the length of the field type is 1 byte, the length of the field length is 4 bytes, the value of the field length is the length of the opaque, the value of the field is the actual value, and the length of the field is the actual length of the field.
[0153] 2. When the transmission mode is the fourth transmission mode not NONE and the maximum length of the object is less than 21 bits, the encoding mode is the object type second mode;
[0154] When the encoding mode is object-type second mode, the encoding method in the target message is: the value of the field type is 0x56, 0x57 or 0x58, the length of the field type is 1 byte, the maximum length of the field length is 3 bytes, the value of the field length is the length of the opaque, the value of the field is the actual value, and the length of the field is the actual length of the field.
[0155] Among them, 0x16 and 0x56 indicate that the field type is opaque, 0x17 and 0x57 indicate that the field type is java obj, and 0x18 and 0x58 indicate that the field type is dotnet obj.
[0156] For example, the encoding method is shown in Table 8:
[0157]
[0158]
[0159] Table 8
[0160] 5. When the field type of the application data is message, the variant data type also supports nesting of messages, that is, a message can be stored in another message. In this embodiment, the message is encoded:
[0161] 1. When the message is empty, the encoding mode is the message type first mode.
[0162] When the encoding mode is the message type first mode, the encoding method in the target message is: the value of the field type is 0x19, the length of the field type is 1 byte, the length of the message length is 4 bytes, and the value of the message length is 0.
[0163] 2. When the message is not empty, the encoding mode is the second message mode.
[0164] When the encoding mode is the message type second mode, the encoding method in the target message is: the value of the field type is 0x19, the length of the field type is 1 byte, the length of the message length is 4 bytes, the value of the message length is the actual value of the message length, the value of the message content is the serialized message content, and the length of the message content is the actual value of the message length.
[0165] For example, the encoding method is shown in Table 9:
[0166]
[0167]
[0168] Table 9
[0169] In this step, for uncertain input data types, they can be expressed in a unified variant manner, which expands the application scenarios; the smallest transmission byte can be used to represent the largest integer type data. (Transmission optimization) Use the smallest transmission byte during transmission, but use a larger integer type when used. For example, it is int64 when defined, but varint when actually transmitted. You can use null as a reserved placeholder, but it is not used to transmit data. It is used to split data and can parse data quickly. For data exceeding a certain value, you can adaptively select fixed length or variable length, and automatically optimize according to the size of the occupied space. The string can be added with or without a terminator. After adding the terminator, you do not need to copy it from the message and can parse it directly, which improves the string parsing speed.
[0170] Step 23: The message sender transmits the target message to the message receiver.
[0171] In this embodiment, when transmitting application data of the same size, the data type and encapsulation method used use fewer bytes during transmission than the transmission method in the prior art.
[0172] Step 24: The message receiver receives the target message sent by the message sender.
[0173] Step 25: The message receiver parses the target message.
[0174] After the message receiver obtains the target message, it parses the target message. If the custom encoding value is parsed, only the custom encoding value needs to be parsed to directly obtain the field type and its value. Only one encoding needs to be parsed, and there is no need to parse both the type and value encodings. If the string value is a null-terminated string, when parsing the message, it can be parsed directly without copying, which improves the string parsing speed.
[0175] like Figure 2 As shown, a third aspect of an embodiment of the present invention provides a data encapsulation device in message transmission, which is applied to a message sender, and includes:
[0176] A determination module 31, configured to determine a coding mode according to the attributes and transmission mode of the application data;
[0177] A generating module 32, configured to encode the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message; wherein the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode;
[0178] The sending module 33 is used to transmit the target message to the message recipient.
[0179] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0180] When the field type of the application data is String and is an empty string, the encoding mode is the first string mode;
[0181] When the field type of the application data is String and the transmission mode is the first transmission mode NONE, the encoding mode is the second string mode;
[0182] When the field type of the application data is String, and the transmission mode is the second transmission mode FAST, and the maximum actual length of the string is less than 21 bits, the encoding mode is the third string mode;
[0183] When the field type of the application data is String, the transmission mode is the second transmission mode FAST, and the minimum actual length of the string is 21 bits, the encoding mode is the fourth string mode;
[0184] When the field type of the application data is String, and the transmission mode is the third transmission mode MAX, and the maximum actual length of the string is less than 21 bits, the encoding mode is the fifth string mode;
[0185] When the field type of the application data is String, the transmission mode is the third transmission mode MAX, and the minimum actual length of the string is 21 bits, the encoding mode is the sixth string mode;
[0186] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0187] When the encoding mode is the first string mode, the value of the field type in the target message is 0x83 and the length is 1 byte;
[0188] When the encoding mode is the second string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0189] When the encoding mode is the third string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0190] When the encoding mode is the fourth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null;
[0191] When the encoding mode is the fifth string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string that does not carry null;
[0192] When the encoding mode is the sixth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string without null.
[0193] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0194] When the field type of the application data is Int8, the encoding mode is Int8 mode;
[0195] When the field type of the application data is Int16, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 7 bits, the encoding mode is the 16-bit integer first mode;
[0196] When the field type of the application data is Int16, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 7 bits, the encoding mode is the 16-bit integer second mode;
[0197] When the field type of the application data is Int32, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 21 bits, the encoding mode is the 32-bit integer first mode;
[0198] When the field type of the application data is Int32, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 21 bits, the encoding mode is the 32-bit integer second mode;
[0199] When the field type of the application data is Int64, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 49 bits, the encoding mode is the 64-bit integer first mode;
[0200] When the field type of the application data is Int64, the transmission mode is the fourth transmission mode notNONE, and the maximum length of the field value is less than 49 bits, the encoding mode is the 64-bit integer second mode;
[0201] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0202] When the encoding mode is Int8 mode, the length of the field type in the target message is 1 byte, the value is 0x07, the length of the field value is 1 byte, and the value is the actual value;
[0203] When the encoding mode is the 16-bit integer first mode, the value of the field type in the target message is 0x09, the length is 1 byte, the length of the field value is 2 bytes, and the value is the actual value;
[0204] When the encoding mode is the 16-bit integer second mode, the value of the field type in the target message is 0x49, the length is 1 byte, the length of the field value is 1 byte, and the value is the actual value;
[0205] When the encoding mode is the 32-bit integer first mode, the value of the field type in the target message is 0x0B, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value;
[0206] When the encoding mode is the 32-bit integer second mode, the value of the field type in the target message is 0x4B, the length is 1 byte, the maximum length of the field value is 3 bytes, and the value is the actual value;
[0207] When the encoding mode is the 64-bit integer first mode, the value of the field type in the target message is 0x0D, the length is 1 byte, the length of the field value is 8 bytes, and the value is the actual value;
[0208] When the encoding mode is the 64-bit integer second mode, the value of the field type in the target message is 0x4D, the length is 1 byte, the maximum length of the field value is 7 bytes, and the value is the actual value.
[0209] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0210] When the field type of the application data is a Boolean type and the transmission mode is the first transmission mode NONE, the encoding mode is a Boolean first mode;
[0211] When the field type of the application data is a Boolean type and the transmission mode is the fourth transmission mode not NONE, the encoding mode is the Boolean second mode;
[0212] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0213] When the encoding mode is the Boolean first mode, the value of the field type in the target message is 0x11, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value;
[0214] When the encoding mode is the Boolean second mode, the value of the field type in the target message is 0xD1 or 0x51, and the length is 1 byte.
[0215] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0216] When the field type of the application data is an object, and the transmission mode is the first transmission mode NONE or the minimum length of the object is 21, the encoding mode is the object type first mode;
[0217] When the field type of the application data is object, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the object is less than 21 bits, the encoding mode is the object type second mode;
[0218] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0219] When the encoding mode is the object type first mode, the value of the field type in the target message is 0x16, 0x17 or 0x18, the length is 1 byte, the length of the field length is 4 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field;
[0220] When the encoding mode is the object type second mode, the value of the field type in the target message is 0x56, 0x57 or 0x58, the length is 1 byte, the maximum length of the field length is 3 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field;
[0221] Among them, 0x16 and 0x56 indicate that the field type is opaque, 0x17 and 0x57 indicate that the field type is java obj, and 0x18 and 0x58 indicate that the field type is dotnet obj.
[0222] In one embodiment of the present invention, determining the encoding mode according to the attributes and transmission mode of the application data includes:
[0223] When the field type of the application data is message and the message is empty, the encoding mode is the first message type mode;
[0224] When the field type of the application data is a message and the message is not empty, the encoding mode is the message type second mode;
[0225] The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes:
[0226] When the encoding mode is the message type first mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, and the value is 0;
[0227] When the encoding mode is the message type second mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, the value is the value of the message length, the value of the message content is the serialized message content, and the length is the value of the message length.
[0228] A fourth aspect of an embodiment of the present invention provides a device for parsing data in message transmission, which is applied to a message receiver and includes:
[0229] A receiving module, used for receiving a target message sent by a message sender;
[0230] The parsing module is used to parse the target message.
[0231] A fifth aspect of an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, a method for encapsulating or parsing data in message transmission provided by the above-mentioned embodiment of the present invention is implemented.
[0232] The sixth aspect of an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of a data encapsulation method or a data parsing method in a message transmission provided by the above-mentioned embodiment of the present invention are implemented.
[0233] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0234] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware systems.
[0235] The method provided in the embodiment of the present invention can be applied to electronic devices. Specifically, the electronic device can be: a desktop computer, a portable computer, an intelligent mobile terminal, a server, etc. This is not limited here, and any electronic device that can implement the present invention belongs to the protection scope of the present invention.
[0236] As for the device / electronic device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0237] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (apparatus), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0238] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0239] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0240] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for encapsulating data in message transmission, characterized in that: Applied to the message sender, including the following steps: Determine the encoding mode according to the attributes and transmission mode of the application data; Encoding the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message; wherein the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode; The target message is transmitted to a message recipient.
2. The method according to claim 1, characterized in that The determining of the encoding mode according to the attributes and transmission mode of the application data includes: When the field type of the application data is String and is an empty string, the encoding mode is the first string mode; When the field type of the application data is String and the transmission mode is the first transmission mode NONE, the encoding mode is the second string mode; When the field type of the application data is String, and the transmission mode is the second transmission mode FAST, and the maximum actual length of the string is less than 21 bits, the encoding mode is the third string mode; When the field type of the application data is String, the transmission mode is the second transmission mode FAST, and the minimum actual length of the string is 21 bits, the encoding mode is the fourth string mode; When the field type of the application data is String, and the transmission mode is the third transmission mode MAX, and the maximum actual length of the string is less than 21 bits, the encoding mode is the fifth string mode; When the field type of the application data is String, the transmission mode is the third transmission mode MAX, and the minimum actual length of the string is 21 bits, the encoding mode is the sixth string mode; The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes: When the encoding mode is the first string mode, the value of the field type in the target message is 0x83, and the length is 1 byte; wherein 0x83 is a custom encoding value, and 0x8 indicates that the field type is a string, and is an empty string; When the encoding mode is the second string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null; When the encoding mode is the third string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null; When the encoding mode is the fourth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string length is 4 bytes, the value is the actual length of the string plus 1, the length of the string is the actual length of the string plus 1, and the value is a string terminated by null; When the encoding mode is the fifth string mode, the length of the field type in the target message is 1 byte, the value is 0x43, the maximum length of the string length is 3 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string that does not carry null; When the encoding mode is the sixth string mode, the length of the field type in the target message is 1 byte, the value is 0x03, the length of the string is 4 bytes, the value is the actual length of the string, the length of the string is the actual length of the string, and the value is a string without null.
3. The method according to claim 1, characterized in that The determining of the encoding mode according to the attributes and transmission mode of the application data includes: When the field type of the application data is Int8, the encoding mode is Int8 mode; When the field type of the application data is Int16, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 7 bits, the encoding mode is the 16-bit integer first mode; When the field type of the application data is Int16, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 7 bits, the encoding mode is the 16-bit integer second mode; When the field type of the application data is Int32, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 21 bits, the encoding mode is the 32-bit integer first mode; When the field type of the application data is Int32, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 21 bits, the encoding mode is the 32-bit integer second mode; When the field type of the application data is Int64, the transmission mode is the first transmission mode NONE, and the minimum length of the field value is 49 bits, the encoding mode is the 64-bit integer first mode; When the field type of the application data is Int64, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the field value is less than 49 bits, the encoding mode is the 64-bit integer second mode; The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes: When the encoding mode is Int8 mode, the length of the field type in the target message is 1 byte, the value is 0x07, the length of the field value is 1 byte, and the value is the actual value; When the encoding mode is the 16-bit integer first mode, the value of the field type in the target message is 0x09, the length is 1 byte, the length of the field value is 2 bytes, and the value is the actual value; When the encoding mode is the 16-bit integer second mode, the value of the field type in the target message is 0x49, the length is 1 byte, the length of the field value is 1 byte, and the value is the actual value; When the encoding mode is the 32-bit integer first mode, the value of the field type in the target message is 0x0B, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value; When the encoding mode is the 32-bit integer second mode, the value of the field type in the target message is 0x4B, the length is 1 byte, the maximum length of the field value is 3 bytes, and the value is the actual value; When the encoding mode is the 64-bit integer first mode, the value of the field type in the target message is 0x0D, the length is 1 byte, the length of the field value is 8 bytes, and the value is the actual value; When the encoding mode is the 64-bit integer second mode, the value of the field type in the target message is 0x4D, the length is 1 byte, the maximum length of the field value is 7 bytes, and the value is the actual value.
4. The method according to claim 3, characterized in that The determining of the encoding mode according to the attributes and transmission mode of the application data includes: When the field type of the application data is a Boolean type and the transmission mode is the first transmission mode NONE, the encoding mode is a Boolean first mode; When the field type of the application data is a Boolean type and the transmission mode is the fourth transmission mode not NONE, the encoding mode is the Boolean second mode; The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes: When the encoding mode is the Boolean first mode, the value of the field type in the target message is 0x11, the length is 1 byte, the length of the field value is 4 bytes, and the value is the actual value; When the encoding mode is the Boolean second mode, the value of the field type in the target message is 0xD1 or 0x51, and the length is 1 byte; wherein 0xD1 and 0x51 are custom encoding values, 0xD1 indicates that the field type is Boolean and the value is true, and 0x51 indicates that the field type is Boolean and the value is false.
5. The method according to claim 1, characterized in that The determining of the encoding mode according to the attributes and transmission mode of the application data includes: When the field type of the application data is an object, and the transmission mode is the first transmission mode NONE or the minimum length of the object is 21, the encoding mode is the object type first mode; When the field type of the application data is object, the transmission mode is the fourth transmission mode not NONE, and the maximum length of the object is less than 21 bits, the encoding mode is the object type second mode; The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes: When the encoding mode is the object type first mode, the value of the field type in the target message is 0x16, 0x17 or 0x18, the length is 1 byte, the length of the field length is 4 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field; When the encoding mode is the object type second mode, the value of the field type in the target message is 0x56, 0x57 or 0x58, the length is 1 byte, the maximum length of the field length is 3 bytes, the value is the length of the opaque, the value of the field is the actual value, and the length is the actual length of the field; Among them, 0x16 and 0x56 indicate that the field type is opaque, 0x17 and 0x57 indicate that the field type is java obj, and 0x18 and 0x58 indicate that the field type is dotnet obj.
6. The method according to claim 1, characterized in that The determining of the encoding mode according to the attributes and transmission mode of the application data includes: When the field type of the application data is message and the message is empty, the encoding mode is the first message type mode; When the field type of the application data is a message and the message is not empty, the encoding mode is the message type second mode; The encoding of the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message includes: When the encoding mode is the message type first mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, and the value is 0; When the encoding mode is the message type second mode, the value of the field type in the target message is 0x19, the length is 1 byte, the length of the message length is 4 bytes, the value is the value of the message length, the value of the message content is the serialized message content, and the length is the value of the message length.
7. A method for parsing data in message transmission, characterized in that: Applied to the message receiver, it includes the following steps: Receive the target message sent by the message sender; The target message is parsed.
8. A data encapsulation device in message transmission, characterized in that: Applicable to the message sender, including: A determination module, used to determine the encoding mode according to the attributes and transmission mode of the application data; A generating module, configured to encode the application data according to the encoding mode, the variant data type and the value of the custom encoding value to generate a target message; wherein the value of the custom encoding value indicates an empty string and its value or a non-empty value Boolean type and its value; and the target message includes the transmission mode; The sending module is used to transmit the target message to the message recipient.
9. A device for analyzing data in message transmission, characterized in that: Applicable to the message receiver, including: A receiving module, used for receiving a target message sent by a message sender; The parsing module is used to parse the target message.
Citation Information
Patent Citations
Data communication method and device
CN103297183A
Data serialization method for Internet of Things equipment communication
CN110830164A
Data transmission method, electronic equipment, system and medium
CN111082982A
Attribute communication encoding and decoding method, encoding device, decoding device and system
CN112260699A
Data transmission method, communication device and system
CN117083820A