Netty-based tcp message analysis method

By building an asynchronous non-blocking TCP communication framework based on Netty, the processing problems of the Internet of Vehicles platform in massive device access and high concurrent data interaction are solved, and efficient analysis and management of different types of TCP messages are achieved, and the processing capabilities of the Internet of Vehicles system are improved.

CN120567951APending Publication Date: 2025-08-29江苏开沃汽车有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510612888.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-13
Publication Date
2025-08-29

AI Technical Summary

Technical Problem

The existing Internet of Vehicles platforms are difficult to cope with the needs of massive device access and high concurrent data interaction, and cannot effectively process different types of TCP packets.

Method used

Based on Netty's NIO model, an asynchronous non-blocking TCP communication framework is built. By defining the EvCommand enumeration type, analyzing the packets is distinguished by calling the corresponding codec functions, configuring the thread group model and channel options, implementing the unpacking and packet grouping of packets, and using appropriate codec functions for encoding and decoding.

Benefits of technology

It supports concurrent access to vehicle terminals of 10,000-level vehicle terminals, improves the processing efficiency of the Internet of Vehicles platform, and is suitable for scenarios such as intelligent connected vehicles, fleet management and remote diagnosis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_1
    Figure SMS_1
  • Figure SMS_2
    Figure SMS_2
  • Figure SMS_3
    Figure SMS_3
Patent Text Reader

Abstract

The invention relates to the technical field of Internet of Vehicles, in particular to a netty-based tcp message analysis method, which comprises the following steps: step 1, constructing an asynchronous non-blocking TCP communication framework based on a NIO model of Netty, defining an EvCommand enumeration type to distinguish the message type for each type of tcp message, calling a corresponding coding and decoding function to analyze the message, and sending the message to a server; defining Handler to be registered in a coding and decoding function of netty to process different types of tcp messages; step 2, unpacking and packing the message obtained from the client; and step 3, selecting a proper encoding and decoding function to encode and decode the message. According to the method, a Netty high-performance communication layer is constructed, an asynchronous non-blocking TCP communication framework is constructed based on a NIO model of Netty, any number and types of tcp messages can be supported, concurrent access of ten-thousand-level vehicle terminals is supported, and the method is suitable for application of multiple scenes such as intelligent network connection automobiles, motorcade management, remote diagnosis and vehicle-mounted information service.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of vehicle networking technology, and in particular to a TCP message parsing method based on Netty. Background Art

[0002] With the increasing prevalence of intelligent driving, the number of in-vehicle devices has exploded, posing unprecedented challenges to the connected vehicle (IoV) service architecture. In real-world scenarios, IoV systems may need to simultaneously manage millions of in-vehicle devices, which continuously collect a wide range of data. The secure storage of this massive amount of data is crucial, as it not only impacts personal privacy but also serves as a crucial foundation for subsequent data analysis and intelligent decision-making.

[0003] The existing Internet of Vehicles platform has the following limitations in its technical implementation: Netty can only register one encoding and decoding processing function separately and cannot handle multiple types of TCP messages. As a result, the Internet of Vehicles platform has different encoding and decoding processing methods for different types of TCP messages and different specific processing steps. Therefore, the Netty open source framework cannot be directly applied and needs to be expanded. As a result, the Internet of Vehicles platform is unable to cope with the needs of massive device access and high-concurrency data interaction in the Internet of Vehicles scenario. Summary of the Invention

[0004] The technical problem to be solved by the present invention is that the existing Internet of Vehicles platform is difficult to cope with the needs of massive device access and high-concurrency data interaction in Internet of Vehicles scenarios.

[0005] To this end, the present invention provides a TCP message parsing method based on Netty.

[0006] The technical solution adopted by the present invention to solve its technical problem is:

[0007] A TCP message parsing method based on Netty, including:

[0008] Step 1: Build an asynchronous non-blocking TCP communication framework based on Netty's NIO model. For each type of TCP message, define the EvCommand enumeration type to distinguish the message type, call the corresponding encoding and decoding function to parse the message, and define a Handler to register with Netty's encoding and decoding function to process different types of TCP messages.

[0009] Step 2: Unpack and repack the message received from the client;

[0010] Step 3: Select appropriate encoding and decoding functions to encode and decode the message.

[0011] Furthermore, in step one, the thread group models bossGroup and workerGroup are configured; the child channel is set using the childOption method; the ChannelInitializer is set through the childHandler method; the maximum length of a single data frame is defined, and the starting subscript position of the length field is defined in the data frame. The data frame must satisfy bytes.length (byte length) - lengthFieldLength (field length) = byteslengthFieldOffset (byte length field offset).

[0012] Furthermore, in step 2, the 4th byte of a complete TCP message is the message displacement identification code, the 21st byte is the data unit encryption method, the length field byte of the message starts from the 22nd byte, the length is two bytes, the default is big-endian mode, and the extra bytes are not removed. The last byte of the message is the check code, which occupies one byte. When the data unit is encrypted, it should be encrypted first and then verified, and verified first and then decrypted.

[0013] Furthermore, the check code adopts a BCC (exclusive check) method, and the check range starts from the first byte of the command unit and is exclusive-ORed with the next byte until the byte before the check code.

[0014] Furthermore, the data encoding method specifically includes:

[0015] Define a constructor EvPayload with five parameters, and assign the five parameters command command, response code responseCode, vehicle identification number vin, encryption model encryptionModel and data unit dataCell to the corresponding member variables of the class respectively;

[0016] Create an unpooled ByteBuf object dataBuf;

[0017] Call the encoding method of the data body to obtain the encoded bytes and write these bytes to dataBuf;

[0018] Call the encodeHeader method to encode the header information, passing in the number of readable bytes of dataBuf as a parameter to obtain the header ByteBuf object headerBuf;

[0019] Use the Unpooled.wrappedBuffer method to merge headerBuf and dataBuf into a new ByteBuf object contentBuf to complete the packet operation;

[0020] Call the createBcc method to calculate the CRC value from the second byte to the second-to-last byte in contentBuf and write the value to contentBuf;

[0021] Get the readable byte count readableBytes of contentBuf and create a byte array bytes of size readableBytes;

[0022] Read the data in contentBuf into a bytes array and return the array.

[0023] Furthermore, the data decoding method includes:

[0024] Assign the incoming ByteBuf object buf to the class member variable byteBuf;

[0025] Call the decodeHeader method to decode the header information of buf;

[0026] Read an unsigned short integer value from buf as the length of the data body, bodyLen. If bodyLen is greater than 0, read a data slice of length bodyLen from buf to obtain the ByteBuf object bodyBuf. Try to call the decodeBody method to decode bodyBuf. If optional has a value, call another decodeBody method, passing in bf and the class contained in optional to decode the data body.

[0027] Furthermore, the decodeHeader method includes: resetting the reading index of the incoming ByteBuf object buf; skipping the first 2 bytes of buf; reading a byte from buf and determining the command command through the EvCommand.valueOf method; reading a byte from buf and determining the response code responseCode through the EvResponseCode.valueOf method; reading 17 characters from buf, converting them into a string and assigning them to vin; reading a byte from buf and determining the encryption model encryptionModel through the EncryptionModel.valueOf method.

[0028] Furthermore, the decodeBody method includes calling the getCommand method to obtain the command, and then calling the getBodyClass method of the command to obtain an Optional object optional containing possible codec classes.

[0029] Furthermore, in step three, if the data type is full Can data, the full Can data decoding method decodeFullCanData is used for decoding.

[0030] Furthermore, the full Can data decoding method decodeFullCanData includes:

[0031] Read an unsigned short integer value from the passed-in ByteBuf object buf as the length of the data body bodyLen;

[0032] Use the full Can data header decoding method decodeFullCanDataHeader. If bodyLen is greater than 0, read a data slice with a length of bodyLen from buf to obtain the ByteBuf object bodyBuf;

[0033] Call the decodeFullCanBody method to decode the data body, passing in bodyBuf and isHTIModel to decode the full Can data body; if an exception is caught during the decoding process, use the log.warn method to record the warning log message "decodeerror:", read a byte from buf, and assign it to the variable bcc.

[0034] The beneficial effect of this invention is that the platform builds a high-performance Netty communication layer and an asynchronous non-blocking TCP communication framework based on Netty's NIO model, supporting concurrent access of tens of thousands of vehicle terminals. It focuses on vehicle remote communication services, real-time data transmission, multi-terminal collaborative management, and the efficient development and deployment of Internet of Vehicles (IoV) ecosystem applications, and is suitable for scenarios such as intelligent connected vehicles, fleet management, remote diagnosis, and in-vehicle information services.

[0035] Specifically, this application defines EvCommand to distinguish different types of TCP messages, defines DataCell to perform encoding and decoding of different types of TCP messages, defines Handler to register with Netty's encoding and decoding functions to process different types of TCP messages, and extends Netty's encoding and decoding functions so that it can support any number of types of TCP messages. DETAILED DESCRIPTION

[0036] In the description of the present invention, it should be noted that, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed, detachable, or integral connections; mechanical or electrical connections; direct or indirect connections through an intermediate medium; and internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on the specific circumstances.

[0037] A TCP packet parsing method based on Netty includes the following steps:

[0038] Step 1: Build a TCP communication framework

[0039] An asynchronous, non-blocking TCP communication framework is built based on Netty's NIO model, supporting concurrent access from tens of thousands of vehicle terminals. It's important to note that for each type of TCP message, an EvCommand enumeration type is defined to differentiate them. A DataCell is then defined to encode and decode the TCP messages, and a handler is registered with Netty's decoding function to call the DataCell's encoding and decoding functions to parse the corresponding TCP message type.

[0040] Configure the thread group model: the bossGroup is responsible for receiving client connection requests, while the workerGroup is responsible for processing I / O operations for established connections. This division of labor model improves processing efficiency in high-concurrency scenarios.

[0041] Specifies that the channel type used by the server is NIO implementation (asynchronous communication based on Java NIO). This configuration defines how the underlying network communication is implemented.

[0042] Some options of the server channel are set through the option method, such as SO_BACKLOG (setting the connection queue length) and TCP_NODELAY (setting whether to disable the Nagle algorithm, that is, whether the message is sent immediately).

[0043] The childOption method is used to set some options for the child channel (that is, the channel created after the client connection is established), including SO_KEEPALIVE (setting whether to maintain a long connection) and SO_REUSEADDR (setting whether to allow reuse of local addresses and ports).

[0044] A ChannelInitializer is set up through the childHandler method. When a new client connection is established, the initChannel method is called to initialize the channel pipeline (ChannelPipeline). Specifically, in the initChannel method, an IdleStateHandler is first added to detect the idle state of the connection, followed by a LengthFieldBasedFrameDecoder for parsing message frames based on the length field. Next, a custom MessageDecoder and MessageEncoder are added for message encoding and decoding. Finally, a business thread group (businessGroup) and a gateway handler (gatewayHandler) are added to the pipeline.

[0045] Defines the maximum length of a single data frame. When sending a data frame, the length field is defined as the length field starting from the lengthFieldOffset position to the lengthFieldOffset + lengthFieldLength position. Defines the starting subscript position of the length field in the data frame. Specifically, when sending a data frame, the length field begins at the position with lengthFieldOffset as the starting subscript.

[0046] It should be noted that the data frame must satisfy the formula bytes.length (byte length) - lengthFieldLength (field length) = byteslengthFieldOffset (byte length field offset).

[0047] After receiving data from the client T-Box, the server parses the data. The specific parsing process is as follows:

[0048] Step 2: Unpack and repack the message received from the client

[0049] First, the TCP message is unpacked and assembled according to the received data frame. The length field byte of a complete TCP message starts from the 22nd byte and is two bytes long. The default is big-endian mode, and no extra bytes are removed. In this way, a complete TCP message is assembled, and then the message is parsed according to the data unit format of each message:

[0050] For example, the command identification data frame received from OTA is VEHICLE_LOGIN: 0x01, "Vehicle Login", Direction.UP. It includes three parameters, the command value 0x01 expressed in hexadecimal, the character string "Vehicle Login" describing the operation, and Direction.UP indicating the direction of the operation. Refer to the format of Table 1 for parsing: if the third byte in the TCP message is 01, it means that the group of messages is a vehicle login message, and so on. The 17 bytes starting from the 5th byte are the vehicle VIN code, with a length of 17 bytes. Starting from the 25th byte, it is the specific data unit, that is, the actual content of each specific TCP message. Distinguish according to getBodyClasss and call the decode function of different DataCells.

[0051] Table 1 Message data packet structure and definition

[0052]

[0053]

[0054] Table 2 Command identifier definition

[0055] coding definition direction 0x90 Version detection Downward Ox50 Version information reporting Upward 0x91 Version upgrade notification Downward Ox51 Upgrade result reporting Upward 0x52 Upgrade log reporting Upward

[0056] Step 3: Message encoding and decoding

[0057] Define a public class named EvPayload, which is a generic class. The type parameter T must be a type that implements the ICodec interface, and this class inherits from BasicPayload. Declare a private member variable body in this class, whose type is the generic type T, which is used to represent the data unit.

[0058] S3.1 Constructor:

[0059] Define a five-parameter constructor, EvPayload(EvCommand command, EvResponseCode responseCode, String vin, EncryptionModel encryptionModel, TdataCell), which assigns the command command, response code responseCode, vehicle identification number vin, encryption model encryptionModel, and data unit dataCell to the corresponding member variables of the class. This distinguishes different services based on the type in EvCommand.

[0060] S3.2 The data encoding method specifically includes:

[0061] Create an unpooled ByteBuf object dataBuf.

[0062] S3.2.1 calls the encode method of the data body to obtain the encoded bytes and writes these bytes to dataBuf.

[0063] S3.2.2 calls the encodeHeader method to encode the header information, passing in the number of readable bytes of dataBuf as a parameter, and obtains the header ByteBuf object headerBuf. The header information encoding method encodeHeader specifically includes:

[0064] Create an unpooled ByteBuf object byteBuf; write the byte of the start symbol START_SYMBOL to byteBuf; write the ID byte of the command command; write the code byte of the response code responseCode; write the character sequence of the vehicle identification number vin; write the ID byte of the encryption model encryptionModel; write the data length dataLength (short integer); return the encoded header ByteBuf object byteBuf.

[0065] S3.2.3 uses the Unpooled.wrappedBuffer method to merge headerBuf and dataBuf into a new ByteBuf object contentBuf to complete the packet operation.

[0066] S3.2.4 calls the createBcc method to calculate the CRC value from the second byte to the second-to-last byte in contentBuf and writes the value to contentBuf.

[0067] S3.2.5 Get the readable byte count readableBytes of contentBuf and create a byte array bytes of size readableBytes.

[0068] S3.2.6 Read the data in contentBuf into a bytes array and return the array.

[0069] If an exception is caught during the above process, the log.error method is used to record the log information of "message encoding error" and return null.

[0070] S3.3 data decoding methods include:

[0071] S3.3.1 Assign the passed ByteBuf object buf to the class member variable byteBuf.

[0072] S3.3.2 Call the decodeHeader method to decode the header information of buf: reset the reading index of the passed-in ByteBuf object buf; skip the first 2 bytes of buf; read a byte from buf and determine the command command through the EvCommand.valueOf method; read a byte from buf and determine the response code responseCode through the EvResponseCode.valueOf method; read 17 characters from buf, convert it to a string and assign it to vin; read a byte from buf and determine the encryption model encryptionModel through the EncryptionModel.valueOf method.

[0073] S3.3.3 Read an unsigned short integer value from buf as the length of the data body, bodyLen.

[0074] If bodyLen is greater than 0, read a data slice of length bodyLen from buf to obtain the ByteBuf object bodyBuf, and try to call the decodeBody method to decode bodyBuf: call the getCommand method to obtain the command, and then call the getBodyClass method of the command to obtain an Optional object optional containing possible codec classes;

[0075] If optional has a value, another decodeBody method is called, passing in bf and the class contained in optional to decode the data body.

[0076] Another decodeBody method can be used to decode the data body using RSA keys. The decodeBodyWithRSAKeys method creates a RemoteControlCommand object, passes in the public key pubKey and private key priKey, casts them to the generic type T, and assigns them to body. The decode method of body is called to decode the data body.

[0077] The data body can also be decoded according to the class instantiation method decodeBody (private method, overloaded): use the passed class bodyClass to create an instance through reflection, cast it to the generic T type, assign it to body, and call the body's decode method to decode the data body.

[0078] If an exception is caught during the decoding process, the log.warn method is used to record the warning log message "decode error:", read a byte from buf, and assign it to the variable bcc.

[0079] S3.3.4 If the data type is full Can data, the header decoding method and data decoding method in step S3.3.3 must use the following method to decode the data body:

[0080] Full Can data decoding method decodeFullCanData:

[0081] Read an unsigned short integer value from the passed-in ByteBuf object buf as the length of the data body, bodyLen.

[0082] Use the full Can data header decoding method decodeFullCanDataHeader: assign the incoming ByteBuf object buf to the class member variable byteBuf; reset the reading index of buf; skip the first 2 bytes of buf; read a byte from buf, and determine the command command through the EvCommand.valueOf method; read a byte from buf, and determine the response code responseCode through the EvResponseCode.valueOf method; read 17 characters from buf, convert it to a string and assign it to vin; read a byte from buf, and determine the encryption model encryptionModel through the EncryptionModel.valueOf method.

[0083] If bodyLen is greater than 0, a data slice of length bodyLen is read from buf to obtain the ByteBuf object bodyBuf.

[0084] Try calling the decodeFullCanBody method to decode the data body, passing in bodyBuf and isHTIModel to decode the full Can data body; if an exception is caught during the decoding process, use the log.warn method to log the warning message "decode error:", read a byte from buf, and assign it to the variable bcc.

[0085] The decoding process of the full Can data body decoding method decodeFullCanBody includes: creating a FullCanData object fullCanData; calling the setIsHTIModel method of fullCanData, passing in isHTIModel to set related properties; forcibly converting fullCanData to the generic T type and assigning it to body.

[0086] Example 1

[0087] The data format of the OTA upgrade notification TCP message is shown in the following table

[0088] Table 3 Version upgrade notification data format and definition

[0089]

[0090]

[0091] Table 4 Time definition

[0092] Data representation content Length / Bytes Data Type Valid value range Year 1 BYTE 0~99 moon BYTE 1~12 day 1 BYTE 1~31 Hour 1 BYTE 0~23 minute 1 BYTE 0~59 Second 1 BYTE 0~59

[0093] Table 5 ECU version information data format and definition

[0094]

[0095]

[0096] Table 6 Version number definition

[0097] byte Bit Data Definition 0 0…7 "S" 1 0…7 "W" 2 0…7 ":" 3 0…7 "a\blc" 4 0…7 Dot 5 0…7 "0-255" 6 0…7 Dot 7 0…7 "0-255"

[0098] The encoding and decoding process of the OTA upgrade notification TCP message includes:

[0099] Step 1: Define a public class named OtaVersionNotice, which inherits from the EvDataCell class. Declare multiple member variables:

[0100] time: The type is GBTime, indicating the time when the version upgrade was issued.

[0101] serialNumber: String type, indicating the serial number of this upgrade.

[0102] ecuId: String type, indicating the physical addressing ID of the ECU to be updated.

[0103] currentVersion: String type, indicating the current version number.

[0104] upgradeVersion: String type, indicating the version number to be upgraded.

[0105] downloadType: The type is int, indicating the download mode (0x00: silent download; 0x01: non-silent download).

[0106] upgradeType: The type is int, indicating the upgrade method (0x00: silent upgrade; 0x01: non-silent upgrade).

[0107] urlLength: type is int, indicating the length of the upgrade URL.

[0108] upgradeUrl: String type, indicating the upgrade URL.

[0109] upgradeTime: type is GBTime, indicating the upgrade time (some decoding and encoding operations in the code are commented and not fully used).

[0110] packageSize: type is int, indicating the size of the software package.

[0111] packageMd5: String value, indicating the MD5 value of the software package.

[0112] Step 2: Data encoding method:

[0113] Create an unpooled ByteBuf object buffer.

[0114] Call the encode method of time to obtain the encoded byte array and write it to the buffer; convert the serialNumber to a character sequence and write it to the buffer; convert the ecuId to a byte array using the ByteBufUtil.decodeHexDump method and write it to the buffer.

[0115] Encode the current version number currentVersion:

[0116] Split currentVersion into string array strparts1 by \\.;

[0117] If the length of strparts1 is 3, then strparts1[0] plus . is converted to a character sequence and written to the buffer; strparts1[1] is converted to an integer and written to a byte in the buffer; . is converted to a character sequence and written to the buffer; strparts1[2] is converted to an integer and written to a byte in the buffer;

[0118] Otherwise, convert "SW:c"+"." into a character sequence and write it to buffer; write the byte corresponding to the integer 1 to buffer; convert "." into a character sequence and write it to buffer; write the byte corresponding to the integer 11 to buffer.

[0119] Encode the upgrade version number upgradeVersion:

[0120] Split upgradeVersion into the string array strparts2 by \\.; convert strparts2[0] with . plus . into a character sequence and write it to buffer; convert strparts2[1] into an integer and write a byte to buffer; convert . into a character sequence and write it to buffer; convert strparts2[2] into an integer and write a byte to buffer; write downloadType as a byte to buffer; write upgradeType as a byte to buffer; convert upgradeUrl into the byte array urlBytes, calculate its length and write it to buffer as an unsigned short integer; write urlBytes into buffer; write packageSize as an integer to buffer; convert packageMd5 into a character sequence and write it to buffer.

[0121] Use the ByteBufUtil.getBytes method to get the byte array in the buffer and return the array as the encoded result.

[0122] Step 3: Data decoding:

[0123] Create a GBTime object time and call its decode method, passing in the ByteBuf object buf for time-related decoding operations.

[0124] Read a 19-character sequence from buf, convert it to String type, and assign it to serialNumber.

[0125] Create a byte array ecuIdBytes of length 2, read 2 bytes from buf into ecuIdBytes, and then use the ByteBufUtil.hexDump method to convert it into a hexadecimal string and assign it to ecuId.

[0126] Parse the current version number currentVersion according to a specific format:

[0127] Read a 5-character sequence from buf, convert it to String type, and assign it to prefix1;

[0128] Read a byte from buf and assign it to version1;

[0129] Skip 1 byte in buf;

[0130] Read a byte from buf and assign it to version2.

[0131] Use the String.format method to combine prefix1, version1, and version2 into a version number format and assign it to currentVersion.

[0132] Parse the upgrade version number upgradeVersion in a similar way to the above:

[0133] Read a 5-character sequence from buf, convert it to String type, and assign it to prefix2;

[0134] Read a byte from buf and assign it to version1;

[0135] Skip 1 byte in buf;

[0136] Read a byte from buf and assign it to version2.

[0137] Use the String.format method to combine prefix2, version1, and version2 into a version number format and assign it to upgradeVersion.

[0138] Read a byte from buf and assign it to downloadType to get the download method;

[0139] Read a byte from buf and assign it to upgradeType to get the upgrade method;

[0140] Read an unsigned short integer value from buf and assign it to urlLength to obtain the length of the upgrade URL;

[0141] Read a character sequence of length urlLength from buf, convert it to String type, and assign it to upgradeUrl;

[0142] Read an integer value from buf and assign it to packageSize to get the package size;

[0143] Read a 32-character sequence from buf, convert it to a String type, and assign it to packageMd5 to obtain the MD5 value of the software package.

[0144] With the above-described preferred embodiments of the present invention as a guide, and with reference to the above description, relevant personnel are fully capable of making various changes and modifications without departing from the technical spirit of this invention. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A TCP message parsing method based on Netty, characterized in that: include, Step 1: Build an asynchronous non-blocking TCP communication framework based on Netty's NIO model. For each type of TCP message, define the EvCommand enumeration type to distinguish the message type, call the corresponding encoding and decoding function to parse the message, and define a Handler to register with Netty's encoding and decoding function to process different types of TCP messages. Step 2: Unpack and repack the message received from the client; Step 3: Select appropriate encoding and decoding functions to encode and decode the message.

2. The method for parsing TCP packets based on Netty according to claim 1, wherein: In step one, configure the thread group models bossGroup and workerGroup; use the childOption method to set the child channel; set the ChannelInitializer through the childHandler method; define the maximum length of a single data frame, and define the starting subscript position of the length field in the data frame. The data frame must satisfy bytes.length (byte length) - lengthFieldLength (field length) = byteslengthFieldOffset (byte length field offset).

3. The TCP message parsing method based on Netty according to claim 1 is characterized in that, In step 2, the 4th byte of a complete TCP message is the message displacement identification code, the 21st byte is the data unit encryption method, the length field byte of the message starts from the 22nd byte, the length is two bytes, the default is big-endian mode, and the extra bytes are not removed. The last byte of the message is the check code, which occupies one byte. When the data unit is encrypted, it should be encrypted first and then verified, and then decrypted.

4. The method for parsing TCP packets based on Netty according to claim 3, wherein: The check code adopts the BCC (exclusive-or check) method, and the check range starts from the first byte of the command unit and is exclusive-ored with the next byte until the byte before the check code.

5. The method for parsing TCP packets based on Netty according to claim 1, wherein: The data encoding method specifically includes: Define a constructor EvPayload with five parameters, and assign the five parameters command command, response code responseCode, vehicle identification number vin, encryption model encryptionModel and data unit dataCell to the corresponding member variables of the class respectively; Create an unpooled ByteBuf object dataBuf; Call the encoding method of the data body to obtain the encoded bytes and write these bytes to dataBuf; Call the encodeHeader method to encode the header information, passing in the number of readable bytes of dataBuf as a parameter to obtain the header ByteBuf object headerBuf; Use the Unpooled.wrappedBuffer method to merge headerBuf and dataBuf into a new ByteBuf object contentBuf to complete the packet operation; Call the createBcc method to calculate the CRC value from the second byte to the second-to-last byte in contentBuf and write the value to contentBuf; Get the readable byte count readableBytes of contentBuf and create a byte array bytes of size readableBytes; Read the data in contentBuf into a bytes array and return the array.

6. The method for parsing TCP packets based on Netty according to claim 1, wherein: Data decoding methods include: Assign the incoming ByteBuf object buf to the class member variable byteBuf; Call the decodeHeader method to decode the header information of buf; Read an unsigned short integer value from buf as the length of the data body, bodyLen. If bodyLen is greater than 0, read a data slice of length bodyLen from buf to obtain the ByteBuf object bodyBuf. Try to call the decodeBody method to decode bodyBuf. If optional has a value, call another decodeBody method, passing in bf and the class contained in optional to decode the data body.

7. The method for parsing TCP packets based on Netty according to claim 6, wherein: The decodeHeader method includes: resetting the reading index of the incoming ByteBuf object buf; skipping the first 2 bytes of buf; reading a byte from buf and determining the command command through the EvCommand.valueOf method; reading a byte from buf and determining the response code responseCode through the EvResponseCode.valueOf method; reading 17 characters from buf, converting it into a string and assigning it to vin; reading a byte from buf and determining the encryption model encryptionModel through the EncryptionModel.valueOf method.

8. The method for parsing TCP packets based on Netty according to claim 6, wherein: The decodeBody method includes calling the getCommand method to obtain the command, and then calling the getBodyClass method of the command to obtain an Optional object optional containing possible codec classes.

9. The method for parsing TCP packets based on Netty according to claim 1, wherein: In step three, if the data type is full Can data, the full Can data decoding method decodeFullCanData is used for decoding.

10. The method for parsing TCP packets based on Netty according to claim 9, characterized in that: The full Can data decoding method decodeFullCanData includes: Read an unsigned short integer value from the passed-in ByteBuf object buf as the length of the data body bodyLen; Use the full Can data header decoding method decodeFullCanDataHeader. If bodyLen is greater than 0, read a data slice with a length of bodyLen from buf to obtain the ByteBuf object bodyBuf; Call the decodeFullCanBody method to decode the data body, passing in bodyBuf and isHTIModel to decode the full Can data body; if an exception is caught during the decoding process, use the log.warn method to log the warning message "decodeerror:", read a byte from buf, and assign it to the variable bcc.