Disclosure of Invention
The invention aims to provide a data transmission method, a data sending end, a data receiving end, electronic equipment and a computer readable storage medium, which can only transmit the true value of each service data by using a message, but not transmit the data attribute of each service data, thereby reducing the communication bandwidth required for transmitting the message data.
In order to solve the technical problems, the present invention provides a data transmission method, which is applied to a data transmitting end, and the method includes:
Receiving service data to be sent; each business data comprises a data attribute and a true value;
Determining the splicing sequence of the business data according to preset configuration information and the data attribute, and splicing the true values of the business data according to the splicing sequence to obtain message data;
And sending the message data to a data receiving end, so that the data receiving end determines the splicing sequence according to the preset configuration information, extracts the true value from the message data according to the splicing sequence, and restores the service data by using the true value.
Optionally, determining a splicing order among the service data according to the preset configuration information and the data attribute, and splicing the true values of the service data according to the splicing order to obtain message data, including:
determining the splicing sequence according to preset configuration information and the data attribute, determining a preset cache area corresponding to each service data, and writing the true value of the service data into the preset cache area;
And splicing the true values in each preset buffer area according to the splicing sequence to obtain the message data.
Optionally, the writing the real value of the service data into the preset buffer area includes:
And when the service data is determined to be fixed-length data according to the data attribute of the service data, writing the true value of the service data into the preset cache area.
Optionally, the writing the real value of the service data into the preset buffer area includes:
when the service data is determined to be non-fixed length data according to the data attribute of the service data, determining the length value of the real value, splicing the length value to the head of the real value, and writing the splicing result into the preset cache area.
The invention also provides a data transmission method, which is applied to the data receiving end, and comprises the following steps:
receiving message data sent by a data sending end;
Determining the splicing sequence of the true value of each business data in the message data according to preset configuration information and the data attribute of each business data, and extracting the true value from the message data according to the splicing sequence;
and restoring the business data by utilizing the true value and the corresponding data attribute.
Optionally, the determining, according to preset configuration information and data attributes of each service data, a splicing order of a real value of each service data in the message data, and extracting the real value from the message data according to the splicing order includes:
Determining the splicing sequence according to preset configuration information and data attributes of each service data, and determining a preset cache area corresponding to each service data;
Extracting the true value from the message data according to the splicing sequence, and writing the true value into a corresponding preset cache area;
correspondingly, the restoring the service data by using the true value and the corresponding data attribute includes:
and restoring the service data by using the true value stored in the preset cache area and the corresponding data attribute.
Optionally, the extracting the real value from the message data according to the concatenation order includes:
And determining the current target service data to be extracted according to the splicing sequence, and extracting the true value of the target service data from the message data according to the preset length of the target service data when the target service data is determined to be the fixed length data according to the data attribute of the target service data.
Optionally, the extracting the real value from the message data according to the concatenation order includes:
And determining the current target service data to be extracted according to the splicing sequence, extracting a length value positioned in a header of a target real value corresponding to the target service data from the message data when the target service data is determined to be non-fixed length data according to the data attribute of the target service data, and extracting the target real value according to the length value.
The invention also provides a data transmitting terminal, which comprises:
the receiving module is used for receiving the service data to be sent; each business data comprises a data attribute and a true value;
The splicing module is used for determining the splicing sequence among the business data according to preset configuration information and the data attribute, and splicing the true values of the business data according to the splicing sequence to obtain message data;
and the sending module is used for sending the message data to a data receiving end so that the data receiving end can determine the splicing sequence according to the preset configuration information, extract the true value from the message data according to the splicing sequence and restore the service data by utilizing the true value.
The invention also provides a data receiving end, which comprises:
The receiving module is used for receiving the message data sent by the data sending end;
the analysis module is used for determining the splicing sequence of the true value of each business data in the message data according to the preset configuration information and the data attribute of each business data, and extracting the true value from the message data according to the splicing sequence;
And the restoration module is used for restoring the service data by utilizing the true value and the corresponding data attribute.
The present invention also provides an electronic device including:
A memory for storing a computer program;
And a processor for implementing the data transmission method as described above when executing the computer program.
The present invention also provides a computer-readable storage medium having stored therein computer-executable instructions that, when loaded and executed by a processor, implement a data transmission method as described above.
The invention provides a data transmission method, which is applied to a data transmitting end, and comprises the following steps: receiving service data to be sent; each business data comprises a data attribute and a true value; determining the splicing sequence of the business data according to preset configuration information and the data attribute, and splicing the true values of the business data according to the splicing sequence to obtain message data; and sending the message data to a data receiving end, so that the data receiving end determines the splicing sequence according to the preset configuration information, extracts the true value from the message data according to the splicing sequence, and restores the service data by using the true value.
Therefore, when the data transmitting end receives the service data to be transmitted, the data attribute corresponding to the service data can be determined, and then the splicing sequence among the service data is determined according to the preset configuration information and the data attribute of each service data; and then, the data transmitting end uses the splicing sequence to splice the true values of the business data to obtain message data, and transmits the message data to the data receiving end. The receiving end also uses the same preset configuration information to determine the splicing sequence, and extracts the true value from the message data according to the sequence, and then uses the true value to restore the service data. In other words, in the present invention, the data attribute of the service data is only used to determine the splicing order between the service data, and is not added to the message data; the message data only contains the true value of the service data, so that the volume of the message data can be obviously reduced, and the communication bandwidth required for transmitting the message data is further reduced. The invention also provides a data transmission method applied to the data receiving end, a data sending end, a data receiving end, electronic equipment and a computer readable storage medium.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The data transmitting end and the data receiving end generally transmit service data in the form of messages. In the related art, when packet encapsulation is performed, data attributes (such as key names) and true values of service data are usually encapsulated in packet data at the same time. However, when the service data is more or the data attributes are the same, a large amount of repeated data attribute information is easily encapsulated in the message data, so that the volume of the message data is increased, and the communication bandwidth is easily wasted when the message data is transmitted. In view of this, the present invention can provide a data transmission method, which can only utilize the message to transmit the true value of each service data, but not transmit the data attribute of each service data, so as to reduce the communication bandwidth required for transmitting the message data. Referring to fig. 1, fig. 1 is a flowchart of a data transmission method according to an embodiment of the present invention, where the method is applied to a data transmitting end, and may include:
s101, receiving service data to be transmitted; each business data includes a data attribute and a true value.
In the embodiment of the invention, the data attribute is descriptive information of the service data, such as key name, data type, etc., and the true value is specific data content of the service data, wherein the data type can be integer type, floating point type, character type, etc. For example, in a key-value pair (key-value), the key value belongs to the data attribute, and the value belongs to the true value.
S102, determining the splicing sequence of the business data according to the preset configuration information and the data attribute, and splicing the true values of the business data according to the splicing sequence to obtain the message data.
In the existing message packaging scheme, data attributes (such as key names) and true values of service data are generally packaged in message data at the same time, for example, if the service data is transmitted in a key value pair form, the message data needs to contain key values and value values of the service data at the same time, which easily increases the volume of the message data and further increases the communication bandwidth required for transmitting the message data. In the embodiment of the invention, only the true value of the service data can be encapsulated in the message data, and the data attribute is not encapsulated; the use of data attributes is followed in the embodiment of the present invention to determine the splice order between the actual values of the business data. The real values are spliced according to a preset splicing sequence under the condition that the data attributes are not transmitted, and the sequence can be negotiated in advance by the data transmitting end and the data receiving end and stored in preset configuration information; further, in consideration of the data attribute having a function of uniquely marking service data, each service data may be represented by its corresponding data attribute in the above-described preset configuration information. When receiving the service data to be transmitted, the data transmitting end can find the splicing position corresponding to the data in preset configuration information according to the corresponding attribute data; when the data receiving end extracts the true value from the message data, the data attribute of the corresponding service data can be found in the preset configuration information according to the extraction sequence of the value, so that the service data can be recovered by utilizing the true value and the data attribute. Therefore, the data attribute of each service data can be prevented from being transmitted in the message data, and the volume of the message data and the bandwidth required for transmitting the message data can be reduced.
It should be noted that, the embodiment of the present invention is not limited to a specific form of the preset configuration information, as long as the data attribute of each service data and the splicing order between the service data can be recorded, preferably, the preset configuration information can be implemented by using an XML file (Extensible Markup Language ), because the XML file can structurally manage the data attribute of each service data, so as to facilitate analysis and determination of the splicing order.
Further, in order to improve the processing efficiency, a corresponding preset buffer area (buffer) may be set for each service data, each preset buffer area is marked with a data attribute of the corresponding service data, and the preset buffer areas are arranged according to the splicing order. Therefore, for the data transmitting end, when the service data to be transmitted is received, only a preset cache area corresponding to the data is determined according to the corresponding data attribute, the corresponding real value is temporarily stored in the area, and then when the message is packaged, only the real value is sequentially extracted from the preset cache area and spliced, so that each service data can be effectively managed, and the splicing efficiency can be improved; for the data receiving end, when receiving the message data, the real value can be extracted according to the splicing sequence, and the real value is written into the corresponding preset cache area according to the extraction times, so that when service data is restored, only the real value in the preset cache area and the data attribute marked by the area are extracted for restoration, and the restoration efficiency can be improved.
In one possible case, determining a splicing order among the service data according to the preset configuration information and the data attribute, and splicing the true values of the service data according to the splicing order to obtain the message data, which may include:
Step 11: determining a splicing sequence according to preset configuration information and data attributes, determining a preset cache area corresponding to each service data, and writing the true value of the service data into the preset cache area;
step 12: and splicing the true values in each preset buffer area according to the splicing sequence to obtain message data.
Further, when the true value is spliced, the data type of the service data can be further determined so as to determine whether the resolved information needs to be further added before the true value. For example, when it is determined that the service data is fixed-length data according to the data attribute of the service data, that is, the length of the real value of the service data is determined to be fixed length, the above-mentioned analysis information may not be added, and the splicing process may be directly performed on the real value.
In one possible case, writing the real value of the service data into the preset buffer area may include:
Step 21: and when the service data is determined to be fixed-length data according to the data attribute of the service data, writing the true value of the service data into a preset cache area.
For another example, when it is determined that the service data is non-fixed length data according to the data attribute of the service data, that is, it is determined that the length of the real value of the service data is not fixed, the length value corresponding to the real value may be determined, and the length value is added to the real value header, so that the data receiving end extracts the real value according to the length value.
In one possible case, writing the real value of the service data into the preset buffer area may include:
Step 31: when the service data is determined to be non-fixed length data according to the data attribute of the service data, determining the length value of the true value, splicing the length value to the head of the true value, and writing the splicing result into a preset cache area.
And S103, sending the message data to the data receiving end so that the data receiving end determines a splicing sequence according to the preset configuration information, extracting a true value from the message data according to the splicing sequence, and restoring the service data by using the true value.
Based on the above embodiment, when the data transmitting end receives the service data to be transmitted, the data transmitting end can firstly determine the data attribute corresponding to the service data, and then determine the splicing sequence among the service data according to the preset configuration information and the data attribute of each service data; and then, the data transmitting end uses the splicing sequence to splice the true values of the business data to obtain message data, and transmits the message data to the data receiving end. The receiving end also uses the same preset configuration information to determine the splicing sequence, and extracts the true value from the message data according to the sequence, and then uses the true value to restore the service data. In other words, in the present invention, the data attribute of the service data is only used to determine the splicing order between the service data, and is not added to the message data; the message data only contains the true value of the service data, so that the volume of the message data can be obviously reduced, and the communication bandwidth required for transmitting the message data is further reduced.
Based on the above-described embodiments, the following describes in detail the implementation on the data receiving side. Referring to fig. 2, fig. 2 is a flowchart of another data transmission method according to an embodiment of the present invention, where the method is applied to a data receiving end, and may include:
S201, receiving message data sent by a data sending end.
S202, determining the splicing sequence of the true value of each business data in the message data according to the preset configuration information and the data attribute of each business data, and extracting the true value from the message data according to the splicing sequence.
In the embodiment of the invention, the real values of the business data contained in the message data are spliced according to the preset splicing sequence, so that the real values of the business data can be sequentially extracted according to the sequence during analysis. Specifically, since the preset configuration information adopts the data attribute to represent each service data, when determining the splicing order, the splicing order can also be determined in the preset configuration information according to the data attribute of each service data related to the message.
Further, for convenience in processing, a corresponding preset buffer area may be set for each service data, each preset buffer area is marked with a data attribute of the corresponding service data, and the preset buffer areas are arranged according to the splicing order. Therefore, for the data receiving end, when receiving the message data, the true value can be extracted according to the splicing sequence, and the true value is written into the corresponding preset cache area according to the extraction times, so that when service data is restored, only the true value in the preset cache area and the data attribute marked by the area are extracted for restoration, and the restoration efficiency can be improved.
In one possible case, determining a concatenation order of the true value of each service data in the message data according to the preset configuration information and the data attribute of each service data, and extracting the true value from the message data according to the concatenation order, including:
step 41: determining a splicing sequence according to preset configuration information and data attributes of each service data, and determining a preset cache area corresponding to each service data;
step 42: and extracting the true value from the message data according to the splicing sequence, and writing the true value into a corresponding preset cache area.
Of course, when extracting the true value, the extraction may be performed in different manners according to the type of each service data. For example, when it is determined that the target service data to be extracted currently is fixed-length data, that is, when it is determined that the real value to be extracted currently is fixed-length, the real value may be extracted from the message according to the preset length corresponding to the service data.
In one possible case, extracting the true value from the message data according to the concatenation order may include:
Step 51: and determining the current target service data to be extracted according to the splicing sequence, and extracting the true value of the target service data from the message data according to the preset length of the target service data when the target service data is determined to be the fixed length data according to the data attribute of the target service data.
For another example, when it is determined that the target service data to be extracted currently is non-fixed length data, that is, it is determined that the length of the real value to be extracted currently is not fixed, at this time, since the data transmitting end has added the length value of the real value to the header of the real value, only the length value needs to be extracted, and the real value extraction is performed according to the value.
In one possible case, extracting the true value from the message data according to the concatenation order may include:
Step 61: and determining the current target service data to be extracted according to the splicing sequence, extracting a length value positioned in a header of a target true value corresponding to the target service data from the message data when the target service data is determined to be non-fixed length data according to the data attribute of the target service data, and extracting the target true value according to the length value.
S203, restoring the business data by using the true value and the corresponding data attribute.
Specifically, if the real value is temporarily stored in the corresponding preset buffer area, the real value stored in the preset buffer area and the corresponding data attribute can be directly utilized to restore the service data.
Accordingly, restoring the service data by using the real value and the corresponding data attribute may include:
Step 71: and restoring the service data by using the true value stored in the preset cache area and the corresponding data attribute.
The data transmitting end, the data receiving end, the electronic device and the computer readable storage medium provided by the embodiments of the present invention are described below, and the data transmitting end, the data receiving end, the electronic device and the computer readable storage medium described below and the data transmission method described above can be referred to correspondingly.
Referring to fig. 3, fig. 3 is a block diagram of a data transmitting end according to an embodiment of the present invention, where the apparatus may include:
A receiving module 301, configured to receive service data to be sent; each business data comprises a data attribute and a true value;
The splicing module 302 is configured to determine a splicing order among the service data according to the preset configuration information and the data attribute, and splice the real values of the service data according to the splicing order to obtain message data;
The sending module 303 is configured to send the message data to the data receiving end, so that the data receiving end determines a splicing order according to the preset configuration information, extracts a true value from the message data according to the splicing order, and restores the service data by using the true value.
Optionally, the splicing module 302 may include:
The cache sub-module is used for determining a splicing sequence according to preset configuration information and data attributes, determining preset cache areas corresponding to the service data, and writing the true values of the service data into the preset cache areas;
and the splicing sub-module is used for splicing the real values in each preset buffer area according to the splicing sequence to obtain the message data.
Optionally, the cache submodule may include:
and the first buffer unit is used for writing the true value of the service data into a preset buffer area when the service data is determined to be the fixed-length data according to the data attribute of the service data.
Optionally, the cache submodule may include:
and the second buffer unit is used for determining the length value of the true value when the service data is determined to be non-fixed length data according to the data attribute of the service data, splicing the length value to the head of the true value, and writing the splicing result into the preset buffer area.
Referring to fig. 4, fig. 4 is a block diagram of a data receiving end according to an embodiment of the present invention, where the apparatus may include:
A receiving module 401, configured to receive message data sent by a data sending end;
The parsing module 402 is configured to determine a splicing order of the real values of the service data in the message data according to the preset configuration information and the data attribute of the service data, and extract the real values from the message data according to the splicing order;
and the restoration module 403 is configured to restore the service data by using the real value and the corresponding data attribute.
Optionally, the parsing module 402 may include:
The information confirmation sub-module is used for determining a splicing sequence according to preset configuration information and data attributes of each service data and determining a preset cache area corresponding to each service data;
The buffer sub-module is used for extracting the true value from the message data according to the splicing sequence and writing the true value into a corresponding preset buffer area;
accordingly, the restoration module 403 is specifically configured to:
and restoring the service data by using the true value stored in the preset cache area and the corresponding data attribute.
Optionally, the cache submodule may include:
the first extraction unit is used for determining the current target service data to be extracted according to the splicing sequence, and extracting the true value of the target service data from the message data according to the preset length of the target service data when the target service data is determined to be the fixed length data according to the data attribute of the target service data.
Optionally, the cache submodule may include:
and the second extraction unit is used for determining the current target service data to be extracted according to the splicing sequence, extracting the length value positioned at the head of the target true value corresponding to the target service data from the message data when the target service data is determined to be non-fixed length data according to the data attribute of the target service data, and extracting the target true value according to the length value.
The embodiment of the invention also provides electronic equipment, which comprises:
A memory for storing a computer program;
And a processor for implementing the steps of the data transmission method as described above when executing the computer program.
Since the embodiments of the electronic device portion correspond to the embodiments of the data transmission method portion, the embodiments of the electronic device portion refer to the description of the embodiments of the data transmission method portion, and are not repeated herein.
The embodiment of the invention also provides a computer readable storage medium, and a computer program is stored on the computer readable storage medium, and when the computer program is executed by a processor, the steps of the data transmission method of any embodiment are realized.
Since the embodiments of the computer readable storage medium portion and the embodiments of the data transmission method portion correspond to each other, the embodiments of the storage medium portion are referred to the description of the embodiments of the data transmission method portion, and are not repeated herein.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The data transmission method, the data transmitting end, the data receiving end, the electronic equipment and the computer readable storage medium provided by the invention are described in detail. The principles and embodiments of the present invention have been described herein with reference to specific examples, the description of which is intended only to facilitate an understanding of the method of the present invention and its core ideas. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.