Message data serialization packaging and analysis method supporting interface protocol verification
By using a message data serialization encapsulation and parsing method that supports interface protocol verification, the problem of interface inconsistency during message sending and receiving is solved, ensuring data compliance and improving system stability and development efficiency.
Patent Information
- Application Number
- CN202511906947.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-17
- Publication Date
- 2026-03-17
AI Technical Summary
In existing technologies, errors in serialization encapsulation and decapsulation during message transmission and reception can lead to abnormal system functions or communication failures, increasing the workload of developers and system instability.
This paper provides a message data serialization encapsulation and parsing method that supports interface protocol verification. By obtaining the message data structure, it realizes digital conversion, performs interface protocol verification, and captures and records errors in real time during the encapsulation and unpacking process to ensure that the data conforms to the interface protocol specification.
Standardized processing of message data was achieved, ensuring compliance of interface protocols during data transmission and reception, reducing the workload of developers, and improving the reliability and efficiency of the system.
Smart Images

Figure CN121691508A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to message data parsing technology, and more particularly to a message data serialization encapsulation and parsing method that supports interface protocol verification. Background Technology
[0002] A message is a customized data structure used to enable information exchange and data transmission between different systems. In practical applications, the message sending and receiving process typically includes the following key steps: the message sending process and the message receiving process. The message sending process is as follows: 1) Data assignment: The user assigns values to each field according to the predefined message data structure. 2) Serialization and packet encapsulation: The assigned field data is serialized to generate a standard byte stream. 3) Message transmission: The packetized byte stream is sent to the network platform through communication mechanisms such as DDS and UDP.
[0003] The message receiving process is as follows: 1) Message reception: Using communication mechanisms such as DDS and UDP, the byte stream of the message is obtained from the network. 2) Deserialization and unpacking: The received byte stream is deserialized and unpacked into the original field data. 3) Business value retrieval: The user extracts the data according to the field definition to complete the subsequent business logic processing.
[0004] In the above message sending and receiving process, serialization and deserialization are the core steps in realizing message data transmission. However, in engineering development, problems often arise where message sending and receiving do not conform to the interface protocol specifications. For example, data structure errors or mismatched field types in the code can lead to the receipt of messages that are not in accordance with the protocol. These problems not only increase the workload of developers in troubleshooting, locating, and debugging interface connections, but may also cause system malfunctions or communication failures, seriously affecting development efficiency and system reliability.
[0005] To avoid the aforementioned problems caused by errors in packet encapsulation and decapsulation during development, a standardized packet processing solution needs to be provided to users. Summary of the Invention
[0006] The technical problem to be solved by the present invention is to provide a message data serialization encapsulation and parsing method that supports interface protocol verification, in order to address the deficiencies in the prior art.
[0007] The technical solution adopted by this invention to solve its technical problem is: a method for message data serialization encapsulation and parsing that supports interface protocol verification, comprising the following steps: 1) Obtain the message data structure and realize the digital conversion of the message protocol; Read the predefined message interface protocol and convert it into a standardized data structure; The standardized data structure includes message subject, variable length identifier, field information, and control word field partitioning; 2) Control the concatenation of character field segments; Call the encapsulation function to determine whether to perform protocol verification and then concatenate the bit fields. 3) Full message field serialization packetization; Call the encapsulation function to determine whether to perform protocol verification and perform serialization processing; 4) Byte stream deserialization and unpacking: Call the encapsulation function to determine whether to perform protocol verification and perform deserialization and parsing of the byte stream; Input serialized byte stream and protocol data structure. When verification is enabled, first verify the message subject, then truncate the byte stream according to the field length, and deserialize it into a container of field values. 5) Control the splitting and parsing of character fields into bit-field subfields; Call the encapsulation function to determine whether to perform protocol verification and split the control word bit field; During function encapsulation, error type feedback and logging are implemented: violation issues during the verification and processing process are captured in real time through error type feedback strings, and error type prompts and log recordings are achieved; the logs clearly indicate the error message subject, error type, and specific location.
[0008] According to the above scheme, in step 1), the field information is stored through the typeData structure, and the control word field partition information is stored through the FieldInfo structure.
[0009] According to the above scheme, in step 2), the encapsulated function is as follows: 2.1) Interface design of encapsulated functions: The input parameters of the encapsulation function are: message protocol data structure, bit field assignment container, message subject, control word field sequence number, check flag, and error type feedback; The return value of the encapsulated function is the numerical value of a single field. 2.2) Function implementation process; Verification mode determination: If verification is enabled, an error message will be triggered if the verification fails, and bit field concatenation will only be performed after the verification passes; if verification is disabled, the concatenation process will proceed directly. Bit field concatenation: Based on the start and end bits of each partition defined in the protocol, the sub-field values are mapped to the corresponding binary bits and concatenated into a complete control word field value.
[0010] According to the above scheme, in step 2.2), if verification is enabled, the following four verifications will be performed in sequence: message subject compliance, field sequence number compliance, assignment container size compliance, and assignment range compliance.
[0011] According to the above scheme, in step 3), the encapsulated function is as follows: 3.1) Interface design of encapsulated functions The input parameters of the encapsulation function are: message protocol data structure, container for assigning values to all message fields, message subject, checksum, and error type feedback; The return value of the encapsulation function is a sequenced byte stream. 3.2) Function implementation process: Message protocol structure verification: When verification is enabled, compliance checks are performed, and inputs that do not conform to the protocol are blocked; Serialization processing: According to the field types and lengths defined in the protocol, all fields are assigned values and converted into standard byte streams, and the serialization result is output.
[0012] According to the above scheme, in step 3.2), when the verification is enabled, the verification of message subject conformity, field quantity conformity, and field type conformity is completed.
[0013] According to the above scheme, in step 4), the encapsulated function is as follows: 4.1) Interface design for encapsulated functions; The encapsulation function has five parameters: the data structure of the message protocol, the sequenced byte stream, the message subject, the judgment of whether to check according to the protocol, and the error type feedback. The return value of the encapsulation function is a container for assigning values to all message fields; 4.2) Function Implementation Process Message protocol structure verification: When verification is enabled, the message subject is verified; Byte stream deserialization parsing: By reading the interface protocol data structure, the data type of each field is obtained, the byte stream is truncated according to the number of bytes occupied by each field, and finally deserialized into a numerical container of all message fields.
[0014] According to the above scheme, in step 5), the encapsulated function is as follows: 5.1) Interface design for encapsulated functions; The encapsulation function has six parameters: the data structure of the message protocol, the value of a single field of the control word class, the message subject, the field sequence number of the control word class, an indicator for whether to perform message protocol structure verification, and error type feedback. The return value of the encapsulation function is: a container for assigning values to bit-field subfields; 5.2) Function Implementation Process Message protocol structure verification: When verification is enabled, it completes the verification of message subject conformity and control word field sequence number conformity. Control word bit field splitting: For control word fields, input their complete numerical values and protocol data structures, verify the subject and field sequence number, perform shifting and value extraction according to the start and end bits of the bit field partition, and split out the original assignment of each sub-field.
[0015] The beneficial effects of this invention are: 1. This invention encapsulates data serialization (packetization) and deserialization (unpacking) into a standard function library, providing a standard method for message data processing; 2. By integrating interface protocol compliance verification into the message data packetization process, real-time checks on the compliance of user-assigned data can be achieved, ensuring that only data that fully complies with the interface protocol can successfully complete the serialization and packetization operation.
[0016] 3. At the initial stage of packet encapsulation, a full-coverage protocol element verification is performed on key elements such as subject, number of fields, type, and assignment range. During the unpacking stage, key information such as subject and control word sequence number is verified to ensure the protocol compliance of both sending and receiving. Attached Figure Description
[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments. In the accompanying drawings: Figure 1 This is a flowchart of a method according to an embodiment of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0019] like Figure 1 As shown, a method for message data serialization, encapsulation, and parsing that supports interface protocol verification includes the following steps: 1) Obtain the message data structure and realize the digital conversion of the message protocol; Read the predefined message interface protocol and convert it into a standardized data structure; The standardized data structure includes message subject, variable length identifier, field information, and control word field partitioning; The field information is stored in the typeData structure, and the control word field partition information is stored in the FieldInfo structure.
[0020] 2) Control the concatenation of character field segments; Call the encapsulation function to determine whether to perform protocol verification and then concatenate the bit fields. 2.1) Interface design of encapsulated functions: The input parameters of the encapsulation function are: message protocol data structure, bit field assignment container, message subject, control word field sequence number, check flag, and error type feedback; The return value of the encapsulated function is the numerical value of a single field. 2.2) Function implementation process; Verification mode determination: If verification is enabled, four checks will be performed in sequence: message subject compliance, field sequence number compliance, assignment container size compliance, and assignment range compliance. If the verification fails, an error message will be triggered. Only after the verification passes will bit field concatenation be performed. If verification is disabled, the concatenation process will proceed directly. The four verification items are as follows: a) Message subject compliance verification If the input message subject name does not match the interface protocol, for example, if the input subject name is "Msg3", but there is no message with the subject name Msg3 in the interface protocol, an error message will be displayed.
[0021] b) Control the field sequence number conformity verification of the character class If the field number of the control class in the input is inconsistent with the interface protocol, for example, the field number in the input is 3, but the field number of the control class in the interface protocol is 2, an error message will be displayed.
[0022] c) Verification of the size of the assignment container for the bit-field subfields If the size of the assignment container for the bit field in the input is inconsistent with the interface protocol, for example, if the size of the assignment container for the bit field in the input is 4, but the number of field partitions for the control word class in the interface protocol is 3, an error message will be displayed.
[0023] d) Verification of the assignment conformity of bit-field subfields If the assigned value of a bit field in the input is inconsistent with the interface protocol, for example, if a segment of the input bit field is assigned a value of 16, but the interface protocol specifies that the same segment of the control word class only has 4 binary bits and the value can only be [0-15], an out-of-bounds error will be displayed. Bit field concatenation: Based on the start and end bits of each partition defined in the protocol, the sub-field values are mapped to the corresponding binary bits and concatenated into a complete control word field value.
[0024] Assigning values to control words; The segmented assignments of the control word are concatenated into a single complete field; By reading the interface protocol data structure, the number of binary bits occupied by each interval of the bit field is obtained, including the start bit and the stop bit. By matching the values assigned to the bit field one by one, they are finally concatenated into a complete field. 3) Full message field serialization packetization; Call the encapsulation function to determine whether to perform protocol verification and perform serialization processing; 3.1) Interface design of encapsulated functions The input parameters of the encapsulation function are: message protocol data structure, container for assigning values to all message fields, message subject, checksum, and error type feedback; The return value of the encapsulation function is a sequenced byte stream. 3.2) Function implementation process: Message protocol structure verification: When verification is enabled, it performs verification of message subject conformity, field quantity conformity, and field type conformity, and blocks inputs that do not conform to the protocol. a) Message subject compliance verification If the input message subject name does not match the interface protocol, for example, if the input subject name is "Msg3", but there is no message with the subject name Msg3 in the interface protocol, an error message will be displayed.
[0025] b) Field quantity compliance check If the size of the input message field assignment container is inconsistent with the interface protocol, for example, if the size of the input message field assignment container is 5, but the number of fields in the interface protocol message is 8, an error message will be displayed.
[0026] c) Field type compliance verification If the type of a message field in the assignment container of the input message field is inconsistent with the interface protocol, for example: the type of a certain field in the input message is... uint16_t However, the type of this field in the interface protocol is... int16_t If so, an error message will be displayed.
[0027] Serialization processing: According to the field types and lengths defined in the protocol, all field values (including concatenated control words) are assigned and converted into a standard byte stream, and the serialization result is output; Assigning values to message fields; The message fields are encapsulated as a byte stream; By reading the interface protocol data structure, the data type of each field is obtained and matched one-to-one with the assignment container of the input message field. Finally, the data is serialized into a byte stream according to the length of each field. 4) Byte stream deserialization and parsing: Byte stream deserialization and parsing is the message field value; Call the encapsulation function to determine whether to perform protocol verification and perform deserialization and parsing of the byte stream; Input serialized byte stream and protocol data structure. When verification is enabled, first verify the message subject, then truncate the byte stream according to the field length, and deserialize it into a container of field values. 4.1) Interface design for encapsulated functions; The encapsulation function has five parameters: the data structure of the message protocol, the sequenced byte stream, the message subject, the judgment of whether to check according to the protocol, and the error type feedback. The return value of the encapsulation function is a container for assigning values to all message fields; 4.2) Function Implementation Process Message protocol structure verification: When verification is enabled, the message subject is verified; Byte stream deserialization and parsing: By reading the interface protocol data structure, the data type of each field is obtained, the byte stream is truncated according to the number of bytes occupied by each field, and finally deserialized and parsed into a numerical container of all message fields; 5) Control the splitting and parsing of character fields into bit-field subfields; Call the encapsulation function to determine whether to perform protocol verification and split the control word bit field; 5.1) Interface design for encapsulated functions; The encapsulation function has six parameters: the data structure of the message protocol, the value of a single field of the control word class (unsigned integer), the message subject, the field number of the control word class, and an indicator for whether to perform message protocol structure verification. Bool Error type feedback; The return value of the encapsulation function is: a container for assigning values to bit-field segments ( Vector ); 5.2) Function Implementation Process Control word bit field splitting: For control word fields, input their complete numerical values and protocol data structures, verify the subject and field sequence number, perform shifting and value extraction according to the start and end bits of the bit field partition, and split out the original assignment of each sub-field.
[0028] During function encapsulation, error type feedback and logging are implemented: violation issues during the verification and processing process are captured in real time through error type feedback strings, and error type prompts and log recordings are achieved; the logs clearly indicate the error message subject, error type, and specific location.
[0029] It should be understood that those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A method for message data serialization and parsing supporting interface protocol verification, characterized in that, The method comprises the following steps: 1) obtaining a message data structure to realize digital conversion of a message protocol; reading a predefined message interface protocol and converting the message interface protocol into a standardized data structure; the standardized data structure comprises a message subject, a variable-length identifier, field information, and a control word bit field partition; 2) control word bit field splicing; calling an encapsulation function, judging whether to perform protocol verification, and performing bit field splicing; 3) full message field serialization packaging; calling an encapsulation function, judging whether to perform protocol verification, and performing serialization processing; 4) byte stream deserialization unpacking: calling an encapsulation function, judging whether to perform protocol verification, and performing byte stream deserialization analysis; inputting a serialized byte stream and a protocol data structure, and verifying the message subject when verification is enabled, then intercepting the byte stream according to the field length, and deserializing into a field value container; 5) control word field splitting and parsing into a bit field; calling an encapsulation function, judging whether to perform protocol verification, and performing control word bit field splitting.
2. The message data serialization and deserialization method supporting interface protocol verification according to claim 1, characterized in that, In the step 1), the field information is stored through a typeData structure body, and the control word bit field partition information is stored through a FieldInfo structure body.
3. The method of claim 1, wherein the method further comprises: In the step 2), the encapsulation function is as follows: 2.1) interface design of the encapsulation function: input parameters of the encapsulation function: message protocol data structure, bit field assignment container, message subject, control word field serial number, verification identifier, error type feedback; return value of the encapsulation function: single field value; 2.2) function implementation process: verification mode judgment: if verification is enabled, an error prompt is triggered if verification fails, and bit field splicing is performed only after verification is passed; if verification is disabled, the splicing process is directly entered; bit field splicing: according to the start bit and the end bit of each partition defined by the protocol, the field assignment is mapped to the corresponding binary bit, and the complete control word field value is spliced.
4. The message data serialization and deserialization method of supporting interface protocol verification according to claim 3, characterized in that, In the step 2.2), if verification is enabled, the following four verifications are sequentially completed: message subject compliance, field serial number compliance, assignment container size compliance, and assignment interval compliance.
5. The message data serialization and deserialization method with support for interface protocol verification of claim 1, wherein, In the step 3), the encapsulation function is as follows: 3.1) interface design of the encapsulation function input parameters of the encapsulation function: message protocol data structure, all message field assignment containers, message subject, verification identifier, error type feedback; return value of the encapsulation function: serialized byte stream; 3.2) function implementation process: message protocol structure verification: when verification is enabled, compliance verification is completed, and inputs that do not comply with the protocol are intercepted; serialization processing: according to the field type and length defined by the protocol, all field assignments are converted into a standard byte stream, and the serialization result is output.
6. The message data serialization and deserialization method of supporting interface protocol verification according to claim 5, characterized in that, In the step 3.2), when verification is enabled, the following verifications are completed: message subject compliance, field quantity compliance, and field type compliance.
7. The message data serialization encapsulation and parsing method supporting interface protocol verification according to claim 1, characterized in that, In the step 4), the encapsulation function is as follows: 4.1) interface design of the encapsulation function; the encapsulation function has five parameters: message protocol data structure, serialized byte stream, message subject, judgment of whether to verify according to the protocol, and error type feedback; return value of the encapsulation function: all message field assignment containers; 4.2) function implementation process Message protocol structure verification: when starting verification, verify the message subject; Byte stream deserialization analysis: by reading the interface protocol data structure, the data type of each field is obtained, the byte stream is intercepted according to the number of bytes occupied by each field, and finally deserialized and analyzed into the numerical container of all message fields.
8. The method of claim 1, wherein the method further comprises: receiving a message from a network device; and determining whether the message is in accordance with the interface protocol. In step 5), the encapsulation function is as follows: 5.1) Interface design of encapsulation function; The parameters of the encapsulation function are 6, which are: the data structure of the message protocol, the numerical value of the single field of the control word class, the message subject, the field number of the control word class, the identification of whether to perform message protocol structure verification, and error type feedback; The return value of the encapsulation function is: the assignment container of the bit field subfield; 5.2) function implementation process Message protocol structure verification: when starting verification, complete the message subject compliance verification and control word field number compliance verification; Control word bit field splitting: for the control word field, input its complete numerical value and protocol data structure, after verifying the subject and field number, perform shift value according to the start and end bits of the bit field division, and split out the original assignment of each subfield. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to realize the steps of the method of any one of claims 1 to 8.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the method of any one of claims 1 to 8.
Citation Information
Patent Citations
Method and apparatus for serialization and deserialization
CN109117209A
General analysis system and method for network protocol message of ship information system
CN116708607A
Multi-source heterogeneous protocol analysis method suitable for satellite-borne protocol analysis equipment
CN119906770A
Automatic database mapping method and device based on structural body serialization and deserialization
CN120045600A
Protocol encoding method, protocol decoding method, computer program product and device
CN120238581A