CN-116667862-B - Data transmission method and related device
Abstract
The embodiment of the application discloses a data transmission method and a related device, which can be applied to various scenes such as cloud technology, artificial intelligence, intelligent traffic, auxiliary driving and the like. The embodiment of the application can automatically realize cross-platform transmission of complex types of data and has universality. The data transmission method comprises the steps of obtaining first data of a first operation platform, wherein the first operation platform is borne in a sending device, when the data type of the first data is complex, encoding the first data based on a preset encoding mode to obtain second data, wherein the preset encoding mode is obtained by attribute information of the first data, and sending the second data to a receiving device so that the second operation platform borne in the receiving device processes the first data, and the first operation platform is different from the second operation platform.
Inventors
- Huang Xuanke
Assignees
- 腾讯科技(深圳)有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20220217
Claims (15)
- 1. A method for transmitting data, which is applied to a transmitting device for realizing cross-platform data transmission by using Flutter standard communication mode, the method comprises: Acquiring first data of a first operation platform, wherein the first operation platform is loaded in the sending device; When the data type of the first data is a complex type, determining a basic type corresponding to each attribute information of the first data according to a preset coding mode, wherein the complex type data is composed of basic type data, the basic type is a data type of Dart programming language, the complex type is other data types except Dert programming language, the preset coding mode is obtained from the attribute information of the first data, the data format of the first data is converted into a Json character string through the preset coding mode, the type object of the complex type data comprises structure information of the complex type data, and the structure information comprises a coding and decoding mode corresponding to the complex type data and corresponding attribute information; performing splicing processing on the type name, the separator and the basic type corresponding to each attribute information of the first data to obtain second data; and sending the second data to a receiving device so that a second operation platform carried in the receiving device processes the first data, wherein the first operation platform is different from the second operation platform.
- 2. The method of claim 1, wherein the data type of the first data is a complex type, comprising: Matching the data type of the first data with a preset basic type in a preset basic type set; And when the data type of the first data is not matched with any preset basic type in the preset basic type set, determining that the data type of the first data is a complex type.
- 3. A method for transmitting data, applied to a receiving device that implements cross-platform data transmission using Flutter standard communication, the method comprising: Receiving second data sent by a sending device, wherein the second data is obtained by encoding first data in a first operation platform by the sending device based on a preset encoding mode, the first operation platform is loaded in the sending device, and the second data is obtained in such a way that when the data type of the first data is a complex type, a basic type corresponding to each attribute information of the first data is determined according to the preset encoding mode, the complex type data is composed of basic type data, the basic type is the data type of Dart programming language, and the complex type is other data types except Dert programming languages; performing splicing processing on the type name and separator of the first data and the basic type corresponding to each attribute information to obtain second data, wherein the data format of the first data is converted into a Json character string through the preset coding mode, the type object of the complex type data comprises structure information of the complex type data, and the structure information comprises a coding and decoding mode corresponding to the complex type data and corresponding attribute information; And when the data type of the second data is complex, decoding the second data based on a preset decoding mode to obtain the first data, wherein the first data is processed by a second operation platform carried in the receiving device, the preset decoding mode is obtained by attribute information of the first data, and the first operation platform is different from the second operation platform.
- 4. The method of claim 3, wherein decoding the second data based on a preset decoding manner when the data type of the second data is a complex type, to obtain the first data, includes: When the data type of the second data is a complex type, acquiring a type name of the first data and a basic type corresponding to each attribute information in the first data from the second data based on the preset decoding mode; And processing the basic type corresponding to each attribute information to obtain the first data.
- 5. The method of claim 4, wherein the obtaining, based on the preset decoding manner, the type name of the first data and the basic type corresponding to each attribute information in the first data from the second data includes: and when the separator is included in the second data, acquiring the type name of the first data and the basic type corresponding to each attribute information in the first data based on the preset decoding mode.
- 6. The method according to any one of claims 3-5, wherein the data type of the second data is a complex type, comprising: Matching the data type of the second data with a preset basic type in a preset basic type set; And when the data type of the second data is not matched with any preset basic type in the preset basic type set, determining that the data type of the second data is a complex type.
- 7. A transmitting apparatus for implementing cross-platform data transmission using Flutter standard communication, comprising: the acquisition unit is used for acquiring first data of a first operation platform, and the first operation platform is borne in the sending device; The processing unit is used for determining a basic type corresponding to each attribute information of the first data according to a preset coding mode when the data type of the first data is a complex type, wherein the data of the complex type is composed of data of the basic type, the basic type is a data type of Dart programming language, the complex type is other data types except Dert programming language, the preset coding mode is obtained from the attribute information of the first data, the data format of the first data is converted into a Json character string through the preset coding mode, the type object of the data of the complex type comprises structure information of the data of the complex type, and the structure information comprises a coding and decoding mode corresponding to the data of the complex type and corresponding attribute information; And the sending unit is used for sending the second data to a receiving device so that a second operation platform borne in the receiving device processes the first data, and the first operation platform is different from the second operation platform.
- 8. The apparatus of claim 7, wherein the processing unit is configured to match a data type of the first data with a preset base type in a set of preset base types, and determine that the data type of the first data is a complex type when the data type of the first data does not match any of the preset base types in the set of preset base types.
- 9. A receiving device for implementing cross-platform data transmission using Flutter standard communication, comprising: The system comprises a receiving unit, a transmitting unit, a receiving unit and a splicing unit, wherein the receiving unit is used for receiving second data sent by the transmitting unit, the second data is obtained by encoding first data in a first operation platform based on a preset encoding mode by the transmitting unit, the first operation platform is loaded in the transmitting unit, the second data is obtained by determining a basic type corresponding to each attribute information of the first data according to the preset encoding mode when the data type of the first data is a complex type, the complex type data is composed of data of the basic type, the basic type is a data type of Dart programming language, the complex type is other data types except Dert programming languages, and the type name, a separator and the basic type corresponding to each attribute information of the first data are spliced to obtain second data; And the processing unit is used for decoding the second data based on a preset decoding mode when the data type of the second data is complex, so as to obtain the first data, wherein the first data is processed by a second operation platform carried in the receiving device, the preset decoding mode is obtained by attribute information of the first data, and the first operation platform is different from the second operation platform.
- 10. The apparatus of claim 9, wherein the processing unit is configured to: When the data type of the second data is a complex type, acquiring a type name of the first data and a basic type corresponding to each attribute information in the first data from the second data based on the preset decoding mode; And processing the basic type corresponding to each attribute information to obtain the first data.
- 11. The apparatus of claim 10, wherein the processing unit is configured to: and when the separator is included in the second data, acquiring the type name of the first data and the basic type corresponding to each attribute information in the first data based on the preset decoding mode.
- 12. The apparatus according to any one of claims 9-11, wherein the processing unit is configured to: Matching the data type of the second data with a preset basic type in a preset basic type set; And when the data type of the second data is not matched with any preset basic type in the preset basic type set, determining that the data type of the second data is a complex type.
- 13. A data transmission apparatus, characterized in that the data transmission apparatus includes an input/output (I/O) interface, a processor, and a memory, Program instructions are stored in the memory; The processor is configured to execute program instructions stored in the memory and to perform the method of any one of claims 1 to 2, or 3 to 6.
- 14. A computer readable storage medium comprising instructions which, when run on a computer device, cause the computer device to perform the method of any one of claims 1 to 2, or 3 to 6.
- 15. A computer program product comprising instructions which, when run on a computer or processor, cause the computer or processor to perform the method of any of claims 1 to 2, or 3 to 6.
Description
Data transmission method and related device Technical Field The embodiment of the application relates to the technical field of communication, in particular to a data transmission method and a related device. Background The cross-platform communication refers to the act of transmitting data carried by an operation platform of a certain device to an operation platform carried by another device, i.e. implementing mutual exchange of data between the certain operation platform and the another operation platform. In related schemes, cross-platform communications are typically implemented based on the manner in which Flutter standard communications are employed. The Flutter standard communication method does not support complex type data exchange, and is only applicable to basic type data exchange. In the process of using Flutter standard communication modes, a developer needs to manually judge the type of communication data, and when the type of the communication data is complex, codes need to be manually written to realize splitting the communication data into basic types of data. Each basic type of data is then transferred independently to another platform. In this way, the developer in another platform writes the code again manually to enable the combination of the received basic types of data into complex types of data. However, the data structure of each complex type of data may not be consistent. If the current Flutter standard communication mode is still used for realizing cross-platform transmission of complex type data, not only is the manual writing process continuously repeated for each complex type data required, but also the process is long and tedious, and the universality is not achieved. Disclosure of Invention The embodiment of the application provides a data transmission method and a related device, which can automatically realize cross-platform transmission of complex types of data and have universality. In a first aspect, an embodiment of the present application provides a method for data transmission. The method can be applied in a transmitting device. The method comprises the steps of obtaining first data of a first operation platform, wherein the first operation platform is carried in the sending device, when the data type of the first data is complex, encoding the first data based on a preset encoding mode to obtain second data, wherein the preset encoding mode is obtained from attribute information of the first data, sending the second data to a receiving device, and enabling the second operation platform carried in the receiving device to process the first data, wherein the first operation platform is different from the second operation platform. In a second aspect, an embodiment of the present application provides another method for data transmission. The method can be applied in a receiving device. The method comprises the steps of receiving second data sent by a sending device, wherein the second data is obtained by encoding first data in a first operation platform based on a preset encoding mode by the sending device, the first operation platform is loaded in the sending device, decoding the second data based on a preset decoding mode when the data type of the second data is a complex type, and obtaining the first data, the first data is processed by the second operation platform loaded in the receiving device, the preset decoding mode is obtained by attribute information of the first data, and the first operation platform is different from the second operation platform. A third aspect of an embodiment of the present application provides a transmitting apparatus. The transmitting apparatus may include an acquisition unit, a processing unit, and a transmitting unit. The device comprises an acquisition unit, a sending unit and a receiving unit, wherein the acquisition unit is used for acquiring first data of a first operation platform, and the first operation platform is loaded in the sending device. And the processing unit is used for encoding the first data based on a preset encoding mode to obtain second data when the data type of the first data is complex, wherein the preset encoding mode is obtained from attribute information of the first data. And the sending unit is used for sending the second data to a receiving device so that a second operation platform borne in the receiving device processes the first data, and the first operation platform is different from the second operation platform. In one possible design, the processing unit is configured to determine, when the data type of the first data is a complex type, a basic type corresponding to each attribute information of the first data according to the preset encoding mode. And the processing unit performs splicing processing on the type name, the separator and the basic type corresponding to each attribute information of the first data to obtain the second data. In another possible embodiment, the processing unit is config