Ethernet data transmission method and device based on C + + language

By using a C++-based Ethernet data transmission method and a protobuf editor to automatically generate code files, the reliability and efficiency issues of Ethernet data transmission in autonomous driving were resolved, achieving accuracy and security in data transmission and preventing program crashes.

CN121125756APending Publication Date: 2025-12-12SUZHOU GUANGYU MINGSHENG INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511099321.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-07
Publication Date
2025-12-12

Smart Images

  • Figure CN121125756A_ABST
    Figure CN121125756A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data transmission, and provides a C + + language-based Ethernet data transmission method and device, and the method comprises the steps: building a structure object according to a code file under the condition that to-be-transmitted data is collected, and filling the to-be-transmitted data into the structure object; performing format conversion on the structure object after data filling based on the code file to obtain serialized data, and sending the serialized data; wherein the code file is automatically generated by analyzing a message body file in a proto format through a compiler, and the message body file is generated based on the data type of the data to be transmitted and a message definition rule of protobuf. According to the method and the device provided by the invention, the code file is automatically and correctly generated through the protobuf editor, and a lot of serialized and deserialized codes realized by the C language are not required to be maintained by handwritten codes, so that the maintenance workload is greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data transmission, and in particular to an Ethernet data transmission method and device based on C++ language. BACKGROUND

[0002] At present, in the field of automatic driving, various sensor data needs to be collected, such as Global Positioning System (GPS), Inertial Measurement Unit (IMU), laser radar, visual sensor and millimeter wave radar, etc. These sensor data inside the vehicle body is usually transmitted through a unified external gateway through a bus, which converts the vehicle Ethernet into a normal Ethernet data packet, and then transmits it to the outside through User Datagram Protocol (UDP). The external collector receives the data by using the same UDP protocol, and then performs data analysis, which can be real-time analysis or offline analysis. How to ensure that various sensor data can be correctly transmitted to the client through Ethernet for correct real-time processing or offline processing is an important problem to be solved.

[0003] In related technologies, C language is usually used to manage and write serialization code. However, when facing a large amount of sensor data or when the project changes the transmission of different data of the same sensor, the phenomenon of incorrect data transmission or program crash may occur, which reduces the data transmission reliability and efficiency. SUMMARY

[0004] The present application provides an Ethernet data transmission method and device based on C++ language to solve the defects of poor reliability and efficiency of Ethernet data transmission in the prior art. The present application provides an Ethernet data transmission method based on C++ language, applied to a sending end, comprising: When the to-be-transmitted data is collected, a structure object is created according to a code file, and the to-be-transmitted data is filled into the structure object; The structure object filled with data based on the code file is format-converted to obtain serialized data, and the serialized data is sent; The code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the to-be-transmitted data and the message definition rule of protobuf.

[0005] According to the Ethernet data transmission method based on C++ language provided by the present application, the structure object filled with data based on the code file is format-converted to obtain serialized data, comprising: Call the serialization function in the code file to convert the filled structure object into binary protocol data unit to obtain the serialized data.

[0006] The C++ language-based Ethernet data transmission method provided in the application comprises the following steps of: The memory allocation and release of the dynamic array field are processed based on the implementation file in the code file.

[0007] The application further provides a C++ language-based Ethernet data transmission method applied to a receiving end, comprising the following steps of: In the case of receiving the serialized data, a structure object corresponding to the serialized data is determined based on a code file; A deserialization function of the corresponding structure object is called to deserialize the serialized data into the structure object; The code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf.

[0008] The C++ language-based Ethernet data transmission method provided in the application comprises the following steps of: The serialized data is read, and a type identifier is obtained by performing type identifier field analysis based on the code file; The type identifier is matched with a predefined mapping table, and the matched structure object is taken as the structure object corresponding to the serialized data.

[0009] The application further provides a C++ language-based Ethernet data transmission device applied to a sending end, comprising the following steps of: A data filling unit is configured to create a structure object according to a code file in the case of collecting data to be transmitted, and fill the data to be transmitted into the structure object; A format conversion unit is configured to perform format conversion on the structure object filled with data based on the code file to obtain serialized data, and send the serialized data. The code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf.

[0010] The application further provides a C++ language-based Ethernet data transmission device applied to a receiving end, comprising the following steps of: An object determining unit is configured to determine a structure object corresponding to the serialized data based on the code file when the serialized data is received. A deserialization unit is configured to call a deserialization function of the corresponding structure object to deserialize the serialized data to the structure object. The code file is automatically generated by a compiler based on a proto format message body file.

[0011] The application further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the C++ language based Ethernet data transmission method when executing the computer program.

[0012] The application further provides a non-transitory computer readable storage medium, which stores a computer program, and the computer program is executable on a processor to implement the C++ language based Ethernet data transmission method.

[0013] The application further provides a computer program product, which includes a computer program, and the computer program is executable on a processor to implement the C++ language based Ethernet data transmission method.

[0014] The C++ language based Ethernet data transmission method and device can automatically and correctly generate code files by using a protobuf editor, and thus the maintenance of a large number of C language implemented serialization and deserialization codes can be avoided, and the workload of maintenance is greatly reduced. BRIEF DESCRIPTION OF DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the present application or prior art, the following will briefly introduce the drawings needed in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0016] Figure 1 is one of the flowcharts of the C++ language based Ethernet data transmission method provided by the application.

[0017] Figure 2Figure 2 is a flowchart of the C++ language-based Ethernet data transmission method provided by the present application.

[0018] Figure 3 Figure 3 is a flowchart of the C++ language-based Ethernet data transmission method provided by the present application.

[0019] Figure 4 Figure 4 is a structural schematic diagram of the C++ language-based Ethernet data transmission device provided by the present application.

[0020] Figure 5 Figure 5 is a structural schematic diagram of the C++ language-based Ethernet data transmission device provided by the present application.

[0021] Figure 6 Figure 6 is a structural schematic diagram of the electronic device provided by the present application. DETAILED DESCRIPTION

[0022] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below with reference to the drawings in the present application. Obviously, the described embodiments are some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the present application.

[0023] In the field of automatic driving, data communication, especially Ethernet communication, an important part is the serialization and deserialization of the transmitted data. Because various sensor devices have their own data, the data parameters are different, and therefore the data needs to be serialized uniformly, and then sent externally by the UDP protocol. The receiving end is also the same, data is received by the UDP protocol, and then the data is deserialized to parse the various sensor data in the data stream.

[0024] For performance considerations, the existing code uses C language to manually manage and write serialization methods. However, in the face of a large amount of sensor data and real-time analysis, it is necessary to correctly parse the data from the serialized data stream, which is a very basic but very important work content. For example, for array type data such as coordinates, obstacles, and multiple states of the same type of sensor, the client needs to correctly read the number of coordinate points, the number of obstacles, and the number of multiple states of the same type before the data can be correctly parsed. If the data verification fails or the number read exceeds the actual number, it will cause memory access out of bounds, and further cause the analysis client program to crash.

[0025] However, in the face of a large amount of sensor data, and project change transmission of different data of the same sensor, the initialization work is great, and it is difficult to avoid that due to incorrect initialization or incorrect amount of some data transmitted, the acquisition end receives illegal data and directly discards, or even worse, causes program crash. Once the crash problem occurs, it is very difficult to find out, so ensuring correct data transmission is an urgent problem to be solved.

[0026] To solve the above problems, the embodiment of the application provides an Ethernet data transmission method based on C++ language, in which initialization is performed before data transmission, a message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf, and then a code file in C++ language is automatically generated by a compiler by parsing the message body file in proto format. When the data to be transmitted is collected by the sending end, a structure object is created according to the code file, and the data to be transmitted is filled into the structure object; the structure object after data filling is subjected to format conversion based on the code file, so as to obtain serialized data, and the serialized data is sent.

[0027] The method provided by the embodiment of the application automatically and correctly generates a code file by using a protobuf editor, so that it is no longer necessary to manually write codes to maintain a large amount of serialization and deserialization codes implemented in C language, and the workload of maintenance is greatly reduced. Compared with the serialization code implemented in C language, when a large amount of data is transmitted, protobuf can obviously reduce the data amount.

[0028] In addition, the data is stored in an object mode in the serialization process, so that the data length of array type data can be automatically sensed, and the problem of out-of-bound access in the parsing process is avoided, so that the accuracy and safety of data transmission are ensured, and the problem of memory out-of-bound access of the user is avoided to cause program crash.

[0029] The embodiment of the application can be applied to a scene requiring Ethernet data transmission, for example, an automatic driving scene. The execution subject of the method can be an electronic device such as a terminal device, a computer, a server, a server cluster or a specially designed data transmission device, or a data transmission device arranged in the electronic device, and the data transmission device can be realized by software, hardware or a combination of both.

[0030] In the description of the embodiments of the present application, it should be understood that the terms "first", "second" are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, the meaning of "multiple" is two or more, unless otherwise explicitly and specifically limited.

[0031] Figure 1 is one of the flowcharts of the Ethernet data transmission method based on C++ language provided by the present application. The execution subject of the method can be a sending end, as shown in Figure 1 The method comprises the following steps: Step 110, in the case of collecting the data to be transmitted, creating a structure object according to the code file, and filling the data to be transmitted into the structure object; Step 120, based on the code file, performing format conversion on the structure object filled with data to obtain serialized data, and sending the serialized data; Wherein, the code file is automatically generated by a compiler parsing a proto format message body file, and the message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf.

[0032] Specifically, the data to be transmitted is the Ethernet data that needs to be transmitted. The data to be transmitted may, for example, be sensor data, such as temperature data collected by a temperature sensor, image data collected by a visual sensor, etc.

[0033] The code file refers to the C++ header file (.pb.h) and implementation file (.pb.cc) generated by parsing the.proto file through the Protobuf compiler protoc. The header file (.pb.h): declares the message class and its interface (such as field operation, serialization method). The implementation file (.pb.cc): implements the underlying logic of serialization / deserialization.

[0034] Before step 110 is executed, a message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf, and then a code file in C++ language is automatically generated by a compiler parsing the proto format message body file.

[0035] Here, the core rules of the message definition rules of protobuf can include field types, field numbers, version compatibility, etc. The message body file is a text-based interface definition file that describes the structure of data (field types, names, numbers, etc.) using the syntax rules of Protocol Buffers (Protobuf). The message body file is used to define the format of the data to be transmitted as a template for generating serialization / deserialization code.

[0036] The compiler parses the proto format message body file and generates serialization / deserialization code in the target C++ language.

[0037] On this basis, step 110 is performed. In this step, the structure is a custom data type used to combine multiple fields (variables) of different types into a logical unit. The structure object in this embodiment is a C++ class instance generated by the Protobuf compiler according to the.proto file, which can be used to represent a specific sensor data.

[0038] Example: If the.proto file defines a temperature sensor message TemperatureData, the generated TemperatureData class is a structure object that includes fields such as sensor_id, temperature, etc.

[0039] When the sending end collects the data to be transmitted, it encapsulates the original data (such as sensor readings) to be transmitted into the structure object generated by Protobuf. First, import the.pb.h file generated by Protobuf in the engineering code, create an instance of the message class (such as TemperatureData), and fill the data into the fields of the object through the generated Setter method. If the message contains a dynamic array (repeated), use the add_ method to add elements.

[0040] Then, the structure object after data filling is converted to obtain serialized data. The process of converting structured data (such as objects, structures) into binary or text format is called serialization. In Protobuf, the serialized data is a compact binary stream that can be directly transmitted over the network or stored.

[0041] In some embodiments, step 120 specifically includes calling a serialization function in the code file to convert the structure object after data filling into a binary protocol data unit to obtain serialized data.

[0042] Specifically, the serialization function is a member function provided in the class generated by Protobuf, which is used to convert the structure object into a binary protocol data unit, and encode the structured data in memory into a compact binary format for network transmission or storage.

[0043] After filling the field value through the Setter method and obtaining the structure object after data filling, the generated serialization function, such as the SerializeToString() method, is used to convert the object into a binary string. True indicates that the serialization is successful, and false indicates that the serialization fails (such as the field is not initialized or the memory is insufficient).

[0044] After obtaining the serialized data, the serialized data is sent through UDP, Socket, MQTT, etc.

[0045] The method provided by the embodiment of the application can automatically and correctly generate code files through a protobuf editor, so that it is no longer necessary to manually write codes to maintain a large number of serialization and deserialization codes implemented in C language, thereby greatly reducing the maintenance workload, avoiding errors caused by manual code writing, and improving the development efficiency and reliability. Compared with the serialization code implemented in C language, the same data structure can significantly reduce the data amount when a large amount of data is transmitted.

[0046] Based on any of the above embodiments, the message body file includes a type identification field of the to-be-transmitted data, a data load field and a dynamic array field, and the method further includes: The memory allocation and release of the dynamic array field are processed based on the implementation file in the code file.

[0047] Specifically, the type identification field is used to identify the sensor type (such as sensor_type), and is used to distinguish the data of different sensors. The data load field is used to store the actual transmitted data (such as temperature and humidity values). The dynamic array field is a field defined using the repeated keyword, supports dynamic addition, deletion, modification and query (such as multiple measurement values), can store multiple same type data, and is similar to a dynamic array.

[0048] The method function of the dynamic array operation includes add_readings(value): adding an element to the end of the array (automatically expanding the memory); mutable_readings(): obtaining an array pointer (supporting direct modification of elements); clear_readings(): clearing the array (automatically releasing the memory); readings_size(): obtaining the current length of the array, and the like.

[0049] When add_readings() is called, Protobuf automatically allocates memory to store the new element. For example, the initial capacity of repeated float readings is 0, and memory is allocated when the first element is added, and then expanded as needed.

[0050] When the SensorData object is destroyed, the memory occupied by the repeated field is automatically released. Calling clear_readings() will immediately release the memory. The memory of the dynamic array is managed by Protobuf, and manual operation will cause memory leakage or crash. Use readings_size() to check the array length to prevent out-of-bound access.

[0051] The method provided by the embodiment of the application can automatically and correctly initialize the number of arrays when adding array type data. The data is stored in an object manner during serialization, which can automatically sense the data length of the array type data and will not cause out-of-bound access during parsing. The method not only ensures the accuracy and security of data transmission, but also ensures that the user access will not cause program crash due to memory out-of-bound.

[0052] Based on any of the above embodiments, Figure 2 is a flowchart of a second Ethernet data transmission method based on C++ language provided by the application, as Figure 2 shown, the execution subject of the method can be a receiving end, including: Step 210, in the case of receiving serialized data, determining the structure object corresponding to the serialized data based on the code file; Step 220, calling the deserialization function function of the corresponding structure object, and deserializing the serialized data to the structure object; Wherein, the code file is automatically generated by the compiler parsing the proto format message body file, and the message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf.

[0053] Specifically, after the receiving end receives the serialized data, the corresponding structure object is first determined. In some embodiments, step 210 specifically includes: Step 211, reading the serialized data, and performing type identification field parsing based on the code file to obtain a type identification; Step 212, matching the type identification with a pre-defined mapping table, and taking the matched structure object as the structure object corresponding to the serialized data.

[0054] Specifically, the receiving end receives and reads the serialized data, parses the protocol header added in front of the serialized data, and obtains the type identifier (such as the sensor_type field). A mapping table of sensor_type to Protobuf message classes is maintained at the receiving end. Then the type identifier is matched with the predefined mapping table, and the matched structure object is taken as the structure object corresponding to the serialized data.

[0055] Then step 220 is performed, a deserialization function function of the corresponding structure object is called, and the serialized data is deserialized to the structure object. The deserialization function function may include, for example: ParseFromString(): parse a binary string to a structure object.

[0056] ParseFromArray(): directly parse from a byte array (suitable for non-string input).

[0057] If the message contains a repeated field (dynamic array), the code generated by Protobuf automatically allocates and releases memory.

[0058] The method provided by the embodiment of the application dynamically selects a structure class through the type identifier in the protocol header, does not need manual judgment of the data type, realizes automatic mapping of data to objects, the strong type constraint of Protobuf ensures matching of field types (for example, float will not be parsed as int), memory allocation and release of a dynamic array field are automatically completed by Protobuf, memory leakage is avoided, and an error state is returned when deserialization fails (for example, data is damaged), so that program crashes are avoided.

[0059] Based on any one of the above embodiments, Figure 3 is a third flowchart of the Ethernet data transmission method based on the C++ language provided by the application, as shown in Figure 3 The method comprises the following steps. According to the data type required, the corresponding.proto message body file is written according to the message definition rule of protobuf.

[0060] The protoc command is used to process the.proto message body file written in the first step, to generate the corresponding serialization and deserialization header file and implementation file of the C++ language version implementation.

[0061] For example: protoc --proto_path proto_1_0_0 --cpp_out cpp_1_0_0 proto / *.proto.

[0062] Add the generated.h and.cpp files in the engineering code, and then call the corresponding encode and decode functions when serialization and deserialization are required to correctly serialize and deserialize data.

[0063] The sender adds the generated.h header file and.cpp implementation file to its own project, fills the corresponding sensor structure body into the protobuf implementation when receiving sensor data, and then calls the serialization function generated by protobuf, and sends the obtained serialized data.

[0064] After receiving the data, the receiver feeds the data into the corresponding structure (defined in the network communication protocol, according to the corresponding parameters to know which type of sensor data is currently received), and then calls the deserialization function of the corresponding protobuf sensor structure. The data can be directly and correctly used.

[0065] The C++ language-based Ethernet data transmission device provided by the application is described below, and the C++ language-based Ethernet data transmission device described below can be correspondingly referred to the C++ language-based Ethernet data transmission method described above.

[0066] Based on the above embodiment, Figure 4 is one of the structure diagrams of the C++ language-based Ethernet data transmission device provided by the application, as Figure 4 shown, the device comprises: The data filling unit 410 is configured to create a structure object according to a code file when collecting the to-be-transmitted data, and fill the to-be-transmitted data into the structure object. The format conversion unit 420 is configured to perform format conversion on the structure object filled with data based on the code file to obtain serialized data, and send the serialized data. The code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the to-be-transmitted data and the message definition rule of protobuf.

[0067] Based on the above embodiment, the format conversion unit is specifically configured to: Call the serialization function in the code file to convert the structure object filled with data into a binary protocol data unit to obtain the serialized data.

[0068] Based on the above embodiment, further comprising a memory management unit for: Based on the implementation file in the code file, the memory allocation and release of the dynamic array field are processed.

[0069] Based on the above embodiment, Figure 5 is a structure diagram of an Ethernet data transmission device based on C++ language provided by the present application, as Figure 5 shown, the device comprises: The object determination unit 510 is configured to determine a structure object corresponding to the serialized data based on the code file when the serialized data is received. The deserialization unit 520 is configured to call a deserialization function function of the corresponding structure object, and deserialize the serialized data to the structure object. Wherein, the code file is automatically generated by a compiler parsing a proto format message body file, and the message body file is generated based on the data type of the data to be transmitted and the message definition rule of protobuf.

[0070] Based on the above embodiment, the object determination unit is specifically configured to: Read the serialized data, and perform type identification field parsing based on the code file to obtain a type identification. Match the type identification with a predefined mapping table, and take the matched structure object as the structure object corresponding to the serialized data.

[0071] Figure 6 An example of an entity structure diagram of an electronic device is shown in Figure 6As shown, the electronic device can include a processor 610, a communications interface 620, a memory 630, and a communications bus 640, wherein the processor 610, the communications interface 620, and the memory 630 complete communication with each other through the communications bus 640. The processor 610 can invoke a logic instruction in the memory 630 to execute a C++ language-based Ethernet data transmission method, which includes: in the case of collecting to-be-transmitted data, creating a structure object according to a code file, and filling the to-be-transmitted data into the structure object; based on the code file, performing format conversion on the data-filled structure object to obtain serialized data, and sending the serialized data; wherein the code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on a data type of the to-be-transmitted data and a protobuf message definition rule. Or the method includes: in the case of receiving serialized data, determining a structure object corresponding to the serialized data based on a code file; and invoking a deserialization function function of the corresponding structure object to deserialize the serialized data to the structure object.

[0072] In addition, the logic instruction in the memory 630 described above can be implemented in the form of a software function unit and sold or used as an independent product, and can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in various embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.

[0073] In another aspect, the present application also provides a computer program product comprising a computer program, which can be stored on a non-transitory computer readable storage medium, and the computer program can be executed by a processor to enable a computer to perform the C++ language-based Ethernet data transmission method provided by the above method, which comprises: in the case of collecting to-be-transmitted data, creating a structure object according to a code file, and filling the to-be-transmitted data into the structure object; performing format conversion on the structure object filled with data based on the code file to obtain serialized data, and sending the serialized data; wherein the code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the to-be-transmitted data and the message definition rule of protobuf. Or the method comprises: in the case of receiving serialized data, determining a structure object corresponding to the serialized data based on a code file; calling a deserialization function function of the corresponding structure object to deserialize the serialized data to the structure object.

[0074] In another aspect, the present application also provides a computer program product comprising a computer program, which can be stored on a non-transitory computer readable storage medium, and the computer program can be executed by a processor to enable a computer to perform the C++ language-based Ethernet data transmission method provided by the above method, which comprises: in the case of collecting to-be-transmitted data, creating a structure object according to a code file, and filling the to-be-transmitted data into the structure object; performing format conversion on the structure object filled with data based on the code file to obtain serialized data, and sending the serialized data; wherein the code file is automatically generated by a compiler by parsing a proto format message body file, and the message body file is generated based on the data type of the to-be-transmitted data and the message definition rule of protobuf. Or the method comprises: in the case of receiving serialized data, determining a structure object corresponding to the serialized data based on a code file; calling a deserialization function function of the corresponding structure object to deserialize the serialized data to the structure object.

[0075] The device embodiments described above are only schematic, wherein the units shown as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present embodiment scheme. Those skilled in the art can understand and implement without creative labor.

[0076] Those skilled in the art can clearly understand the technical solutions of the various embodiments from the above description of the embodiments, and the various embodiments can be implemented by means of software with the necessary general hardware platforms, and of course, can also be implemented by hardware. Based on such understanding, the above technical solutions, essentially or in other words, the part of the prior art that makes a contribution, can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, and the like, and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0077] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for some technical features therein; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A C++-based Ethernet data transmission method, applied at the transmitting end, characterized in that, include: Once the data to be transmitted is collected, a structure object is created based on the code file, and the data to be transmitted is filled into the structure object. Based on the code file, the data-filled structure object is format-converted to obtain serialized data, and the serialized data is sent. The code file is automatically generated by the compiler by parsing the proto format message body file, which is generated based on the data type of the data to be transmitted and the message definition rules of protobuf.

2. The Ethernet data transmission method based on C++ language according to claim 1, characterized in that, The process of converting the format of the data-filled structure object based on the code file to obtain serialized data includes: The serialization function in the code file is called to convert the data-filled structure object into a binary protocol data unit, thus obtaining the serialized data.

3. The Ethernet data transmission method based on C++ language according to claim 1, characterized in that, The message body file includes a type identifier field for the data to be transmitted, a data payload field, and a dynamic array field. The method further includes: The implementation file in the code file handles the memory allocation and release of dynamic array fields.

4. An Ethernet data transmission method based on C++ language, applied at the receiving end, characterized in that, include: Upon receiving serialized data, the structure object corresponding to the serialized data is determined based on the code file; Call the deserialization function of the corresponding structure object to deserialize the serialized data into the structure object; The code file is automatically generated by the compiler by parsing the proto format message body file, which is generated based on the data type of the data to be transmitted and the message definition rules of protobuf.

5. The Ethernet data transmission method based on C++ language according to claim 4, characterized in that, The step of determining the structure object corresponding to the serialized data based on the code file includes: Read the serialized data and parse the type identifier field based on the code file to obtain the type identifier; The type identifier is matched with a predefined mapping table, and the matched structure object is used as the structure object corresponding to the serialized data.

6. An Ethernet data transmission device based on C++ language, applied at the transmitting end, characterized in that, include: The data filling unit is used to create a structure object based on the code file when the data to be transmitted is collected, and to fill the structure object with the data to be transmitted. The format conversion unit is used to perform format conversion on the data-filled structure object based on the code file to obtain serialized data, and send the serialized data. The code file is automatically generated by the compiler by parsing the proto format message body file, which is generated based on the data type of the data to be transmitted and the message definition rules of protobuf.

7. An Ethernet data transmission device based on C++ language, applied at the receiving end, characterized in that, include: An object determination unit is used to determine the structure object corresponding to the serialized data based on a code file upon receiving serialized data. The deserialization unit is used to call the deserialization function of the corresponding structure object to deserialize the serialized data into the structure object. The code file is automatically generated by the compiler by parsing the proto format message body file, which is generated based on the data type of the data to be transmitted and the message definition rules of protobuf.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the Ethernet data transmission method based on the C++ language as described in any one of claims 1 to 5.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the Ethernet data transmission method based on the C++ language as described in any one of claims 1 to 5.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the Ethernet data transmission method based on the C++ language as described in any one of claims 1 to 5.