CN112995199B - Data encoding and decoding method, device, transmission system, terminal equipment and storage medium - Google Patents

Data encoding and decoding method, device, transmission system, terminal equipment and storage medium Download PDF

Info

Publication number
CN112995199B
CN112995199B CN202110335553.2A CN202110335553A CN112995199B CN 112995199 B CN112995199 B CN 112995199B CN 202110335553 A CN202110335553 A CN 202110335553A CN 112995199 B CN112995199 B CN 112995199B
Authority
CN
China
Prior art keywords
data
preset
algorithm
decoding
encoding
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110335553.2A
Other languages
Chinese (zh)
Other versions
CN112995199A (en
Inventor
李格非
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110335553.2A priority Critical patent/CN112995199B/en
Publication of CN112995199A publication Critical patent/CN112995199A/en
Application granted granted Critical
Publication of CN112995199B publication Critical patent/CN112995199B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/04Protocols for data compression, e.g. ROHC

Abstract

The embodiment of the invention discloses a data encoding and decoding method, a data encoding and decoding device, a transmission system, a terminal device and a storage medium, wherein the data encoding method comprises the following steps: acquiring data to be encoded, wherein the data to be encoded comprises key data and value data; acquiring a Huffman dictionary corresponding to the key data, and acquiring a preset coding algorithm corresponding to the value data; in the process of sequentially coding data to be coded, the value data are coded based on a preset coding algorithm, and data except the value data are coded based on a Huffman dictionary. A large amount of repeated key data are coded based on the Huffman dictionary to obtain binary data, so that the occupied space after compression can be reduced, and the compression efficiency and the transmission efficiency are improved. In addition, due to the random randomness of the value data, the value data is compressed by adopting other preset coding algorithms, the problem that the processing efficiency is low due to the fact that the Huffman dictionary is very large when the value data is coded based on the Huffman dictionary can be solved, and the coding efficiency can be improved.

Description

Data encoding and decoding method, device, transmission system, terminal equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a data coding and decoding method, a data coding and decoding device, a data transmission system, terminal equipment and a storage medium.
Background
Conventionally, structured data such as Extensible Markup Language (XML) and JavaScript Object Notation (JSON) is widely used in network transmission.
In the process of implementing the invention, the inventor finds that at least the following technical problems exist in the prior art: a large amount of repetitive data exist in the structured data, and after the structured data are compressed by a conventional compression algorithm, the occupied space of the repetitive data is still large, so that the compression efficiency and the transmission efficiency are low.
Disclosure of Invention
The embodiment of the invention provides a data coding and decoding method, a data coding and decoding device, a transmission system, a terminal device and a storage medium, which can improve the compression efficiency and the transmission efficiency of data.
In a first aspect, an embodiment of the present invention provides a data encoding method, including:
acquiring data to be encoded, wherein the data to be encoded comprises key data and value data;
acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data;
and sequentially encoding the data to be encoded, encoding the value data based on the preset encoding algorithm in the encoding process, and encoding the data except the value data in the data to be encoded based on the Huffman dictionary.
In a second aspect, an embodiment of the present invention provides a data decoding method, including:
receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded includes value data to be decoded;
acquiring a target Huffman dictionary based on the dictionary identification, and acquiring a preset decoding algorithm corresponding to a preset coding algorithm adopted in sequence based on the algorithm identification;
and sequentially decoding the data to be decoded, decoding the value data to be decoded based on a sequentially acquired preset decoding algorithm in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
In a third aspect, an embodiment of the present invention provides a data encoding apparatus, including:
the device comprises a to-be-coded data acquisition module, a data acquisition module and a data acquisition module, wherein the to-be-coded data acquisition module is used for acquiring the to-be-coded data, and the to-be-coded data comprises key data and value data;
the coding algorithm acquisition module is used for acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data;
and the coding module is used for sequentially coding the data to be coded, coding the value data based on the preset coding algorithm in the coding process, and coding the data except the value data in the data to be coded based on the Huffman dictionary.
In a fourth aspect, an embodiment of the present invention provides a data decoding apparatus, including:
the data receiving module is used for receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded comprises value data to be decoded;
the decoding algorithm obtaining module is used for obtaining a target Huffman dictionary based on the dictionary identification and obtaining a preset decoding algorithm corresponding to a preset coding algorithm adopted in sequence based on the algorithm identification;
and the decoding module is used for sequentially decoding the data to be decoded, decoding the value data to be decoded based on a preset decoding algorithm which is sequentially acquired in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
In a fifth aspect, an embodiment of the present invention provides a data transmission system, including a data encoding apparatus and a data decoding apparatus according to any embodiment of the present invention;
the data encoding device sends data to be decoded, dictionary identification and algorithm identification of a preset encoding algorithm adopted by the data to be decoded in sequence in the encoding process to the data decoding device.
In a sixth aspect, an embodiment of the present invention provides a terminal device, including:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a data encoding method or a data decoding method as described in any of the embodiments of the present invention.
In a seventh aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements a data encoding method or a data decoding method according to any embodiment of the present invention.
The embodiment of the invention provides a data coding and decoding method, a data coding and decoding device, a transmission system, a terminal device and a storage medium, wherein the data coding method comprises the following steps: acquiring data to be encoded, wherein the data to be encoded comprises key data and value data; acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data; and sequentially coding the data to be coded, coding the value data based on a preset coding algorithm in the coding process, and coding the data except the value data in the data to be coded based on the Huffman dictionary.
By encoding a large amount of repetitive key data based on the huffman dictionary, the key data can be converted into binary data. Compared with the character data obtained after the traditional compression, the binary data can greatly reduce the occupied space after the compression, thereby improving the compression efficiency and the transmission efficiency. Further, due to the random randomness of the value data, if the value data is encoded using the huffman dictionary, it is necessary to generate a very large huffman dictionary in the early stage, and the huffman dictionary is too large, which causes a problem of low encoding efficiency. Therefore, by compressing the value data by using other preset encoding algorithms, the encoding efficiency can be further improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description will be given below of the drawings required for the embodiments or the technical solutions in the prior art, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flow chart illustrating a data encoding method according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a data encoding method according to a second embodiment of the present invention;
fig. 3 shows a flow chart of a data decoding method provided by a third embodiment of the present invention;
fig. 4 is a schematic structural diagram illustrating a data encoding apparatus according to a fourth embodiment of the present invention;
fig. 5 shows a schematic structural diagram of a data decoding apparatus according to a fifth embodiment of the present invention;
fig. 6 is a schematic structural diagram illustrating a data transmission system according to a sixth embodiment of the present invention;
fig. 7 shows a schematic hardware structure diagram of a terminal device according to a seventh embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described through embodiments with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without making any creative effort based on the embodiments in the present invention, belong to the protection scope of the present invention. In the following embodiments, optional features and examples are provided in each embodiment, and various features described in the embodiments may be combined to form multiple alternatives, and each numbered embodiment should not be regarded as only one technical solution.
Example one
Fig. 1 shows a flowchart of a data encoding method according to an embodiment of the present invention, where the data encoding method according to the embodiment of the present invention is applicable to a case where data is encoded and compressed, for example, before key-value pair information is transmitted, key-value pair information is compressed and encoded. The method may be performed by a data encoding apparatus (which may be simply referred to as an encoding apparatus), which is implemented in software and/or hardware, and is preferably configured in a terminal device, such as a device at an encoding end.
As shown in fig. 1, the data encoding method provided in the embodiment of the present invention includes the following steps:
s110, acquiring data to be encoded, wherein the data to be encoded comprises key data and value data.
In this embodiment of the present invention, the process of the encoding device acquiring the data to be encoded may include: receiving a data coding instruction, and reading data to be coded from a storage position carried by the data coding instruction; alternatively, the data to be transmitted may be treated as data to be encoded, or the like, in response to a data transmission instruction. In addition, the data to be encoded may also be obtained based on other instructions, which is not exhaustive here.
The data to be encoded may include, but is not limited to, key data and value data, and may also include symbol data such as "=", "<" and ">", for example. The data to be encoded may be considered as structured data including a series of key-value pairs (key-value pairs) composed of key data and value data. Illustratively, the data to be encoded may include, but is not limited to, XML data, JSON data, structured data in other known or custom formats, and the like.
Taking XML data as an example, the XML data contains a large number of known repetitive common fields, such as tag names (ImageView, textView, etc.) and attribute names (height, width, etc.), which can be referred to as key data. Accordingly, a value corresponding to each key data, for example, 200 in width = "200", may be referred to as value data. In a conventional compression algorithm, after the common fields such as the tag names and the attribute names are encoded, the occupied space is still large, which results in low compression efficiency and transmission efficiency. The data coding method provided by the embodiment of the invention can solve the technical problems and improve the compression efficiency and the transmission efficiency.
S120, acquiring a Huffman dictionary corresponding to the key data, and acquiring a preset coding algorithm corresponding to the value data.
The Huffman dictionary may be considered as a dictionary generated by encoding sample data based on a Huffman Coding (Huffman Coding) method. In addition, the huffman coding method may be considered as a method of constructing a binary code having the shortest average length of the anomalus prefix according to the occurrence probability of characters in the sample data.
And aiming at the sample data under different application scenes, the Hoffman dictionaries correspondingly generated are different. When the sample data and the data to be encoded belong to the same application scene, the data to be encoded may be encoded based on the huffman dictionary corresponding to the sample data. The application scenario may be understood as a scenario in which a specified function is executed by applying structured data in a specified format, for example, a scenario in which layout description is performed by using XML data, or a scenario in which parameter configuration is performed by using JSON data.
Since the value data in the sample data may be a combination of characters and numbers of arbitrary length, if the value data is huffman-coded, the huffman dictionary is too bulky and lacks versatility, and coding efficiency is also lowered. In this embodiment, huffman coding may be performed on data other than the value data in the sample data, for example, huffman coding may be performed on repeatedly appearing elements such as key data and character data, so that the huffman dictionary is more simplified, the universality is higher, and the coding efficiency is improved.
After the generated huffman dictionary, the encoding apparatus may store the huffman dictionary corresponding to each application scene. Compared with character data in data to be encoded, key data in data to be encoded can better represent application scenes of data to be encoded. Therefore, the Huffman dictionary generated based on the sample data in the same application scene can be acquired from the pre-storage position according to the key data in the data to be encoded.
The preset encoding algorithm may be any preset encoding algorithm, and may include, but is not limited to, a Lempel-Ziv series compression algorithm, a PPM series compression algorithm, an arithmetic compression algorithm, a custom compression algorithm, and the like. In addition, the preset encoding algorithm may also be a text form conversion method without compression, which is not exhaustive herein.
The preset encoding algorithm usable by the encoding apparatus may include at least one, and the value data in the data to be encoded may also include at least one. When the value data is plural, the same preset encoding method may be adopted to encode it, or different preset encoding methods may be adopted to encode it. The encoding device may acquire a preset encoding algorithm corresponding to the value data based on a preset correspondence rule, or may randomly acquire the preset encoding algorithm.
S130, sequentially encoding the data to be encoded, encoding the value data based on a preset encoding algorithm in the encoding process, and encoding the data except the value data in the data to be encoded based on the Huffman dictionary.
The data to be encoded may be encoded sequentially according to a preset sequence, such as a data reading sequence or a data transmission sequence. In the encoding process, whether the data to be encoded currently is value data or not can be judged; if so, encoding the current data by using a preset encoding algorithm; otherwise, the current data can be coded by utilizing the Huffman dictionary.
The encoding of the value data based on the preset encoding algorithm may include calculating the value data by using the preset encoding algorithm; encoding data other than the value data in the data to be encoded based on the huffman dictionary may include querying a binary code corresponding to the current character or character string using the huffman dictionary.
By encoding the value data based on a preset encoding algorithm and encoding the data to be encoded except the value data based on the Huffman dictionary, various encoding modes can be flexibly applied to encode high-frequency data (key data, character data and the like) and non-high-frequency data (value data) in the data to be encoded, so that the compression efficiency and the transmission efficiency can be improved, and the problem that the encoding efficiency is low due to the fact that the Huffman dictionary is too large can be solved.
In some optional embodiments, during the encoding process, the method further includes: and determining data between the first preset character and the second preset character in the data to be coded as value data.
Wherein the first preset character and the second preset character may respectively represent a start position and an end position of the value data. It is considered that data after the first preset character is first data of the value data, and data before the second preset character is last data of the value data. The first preset characters in different structured data may be different, the second preset characters in different structured data may also be different, and the first preset characters and the second preset characters in the same structured data may be the same or different.
Taking XML data as an example, the value data is often marked with english quotation marks (") for the start and end positions of the value data. When the XML data is coded, the value data between two English quotation marks can be coded based on a preset coding algorithm, and other data can be coded by utilizing a Huffman dictionary.
In these optional embodiments, by setting the first preset character and the second preset character, the determination of the value data is realized, which is helpful for realizing switching between a coding mode for coding based on the huffman dictionary and a coding mode for coding based on the preset coding algorithm in the coding process.
The data coding method provided by the embodiment of the invention comprises the steps of obtaining data to be coded, wherein the data to be coded comprises key data and value data; acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data; and sequentially encoding the data to be encoded, encoding the value data based on a preset encoding algorithm in the encoding process, and encoding the data except the value data in the data to be encoded based on the Huffman dictionary.
The key data can be converted into binary data by encoding a large amount of repetitive key data based on the huffman dictionary. Compared with the character data obtained after the traditional compression, the binary data can greatly reduce the occupied space after the compression, thereby improving the compression efficiency and the transmission efficiency. Further, due to the random randomness of the value data, if the value data is encoded by using the huffman dictionary, a very large huffman dictionary needs to be generated in the early stage, and the huffman dictionary is too large, which results in a problem of low encoding efficiency. Therefore, by compressing the value data by using other preset encoding algorithms, the encoding efficiency can be further improved.
Example two
On the basis of the above embodiments, the present embodiment elaborates the generation step of the huffman dictionary before encoding, the acquisition step of the huffman dictionary and the preset encoding algorithm during encoding, and the transmission step after encoding is completed. By generating the Huffman dictionary in the preset application scene, data coding can be performed by using the Huffman dictionary when data transmission is performed in the corresponding application scene. The Huffman dictionary required by the coding process can be obtained through query based on the application scene corresponding to the key data; and a more appropriate preset encoding algorithm can be obtained through querying based on the data type of the value data. By sending the encoded data to the decoding end, the encrypted transmission of the compressed data can be realized, and the data transmission efficiency can be improved.
Fig. 2 shows a flowchart of a data encoding method according to a second embodiment of the present invention. Referring to fig. 2, the data encoding method includes the steps of:
s210, obtaining sample data in a preset application scene, and counting the frequency of data except the value data in the sample data.
In this embodiment, the obtaining of the sample data in the preset application scene may be obtaining a batch of sample data in the preset application scene from a preset storage location. Furthermore, the value data and other data in the sample data can be distinguished according to the first preset character and the second preset character, and the frequency of the data except the value data in the sample data can be obtained by counting the times of the other data appearing in the sample data range.
And S220, coding the data except the value data in the sample data according to frequency based on a Huffman coding method to obtain a Huffman dictionary under a preset application scene.
The data excluding the value data can be subjected to frequency statistics to obtain the approximate use frequency of each repeated element in the preset application scene. Theoretically, when the data volume of the sample data is larger, the approximate using frequency of the repeating elements in the preset application scene is more accurate, and the encoding accuracy is higher. Furthermore, coding can be performed according to the occurrence frequency of each repeated element based on a Huffman coding method, so that a Huffman dictionary under a preset application scene is obtained. Furthermore, a corresponding relationship between a preset application scene and the huffman dictionary, i.e., a scene-dictionary corresponding relationship, may also be generated and stored.
For example, when the application scene is preset as a scene in which the XML data is used for layout description, the sample data may include, for example:
Figure BDA0002997398350000101
wherein, the data in the English quotation mark (") is value data; view, imageView, textView, etc. are tag names; height, width, bgColor, etc. as attribute names; (<), (>), (=), and (") and the like are character data.
Illustratively, table 1 shows the frequency of counting the repeated elements and binary codewords obtained by huffman coding the repeated elements in a scenario of performing layout description by using XML data.
TABLE 1
View ImageView TextView TagView height width bgColor < > "
20 15 10 5 50 50 12 80 60 30 200
00101 00100 0000001 0000000 0011 0001 000001 010 011 00001 1
In table 1, repeated elements such as characters or character strings are counted in the first row, the frequency of the repeated elements in the second row is calculated, and the third row is a codeword corresponding to each repeated element generated based on huffman coding. Wherein, the huffman dictionary can be generated based on the repeated elements, the generated code words and the corresponding relationship between the repeated elements and the code words.
In this embodiment, the steps S210 to S220 may be performed by the encoding device, or may be performed by another device (e.g., a dictionary generating device). After the huffman dictionary under the preset application scene is generated, the huffman dictionary under the preset scene and the scene-dictionary correspondence can be sent to the encoding end to which the encoding device belongs and the decoding end to which the data decoding device belongs in a trusted mode. And when the Huffman dictionary in the preset scene is updated, the Huffman dictionary can be synchronously updated at the encoding end and the decoding end. Therefore, under the condition that the encoding end and the decoding end are separated, the encoding and decoding of the data to be encoded under the same scene can be realized based on the same Huffman dictionary, the data compression transmission can be favorably realized, and the transmission efficiency can be improved.
And S230, acquiring data to be encoded, wherein the data to be encoded comprises key data and value data.
S241, determining a target application scene of data to be coded according to the key data; and determining a Hoffman dictionary corresponding to the target application scene based on a preset scene-dictionary corresponding relation.
In this embodiment, the target application scenario is determined according to the key data, for example, the target application scenario may be output according to the key data in the data to be encoded based on a machine learning model trained in advance; as another example, the application scenario with the highest similarity is determined from the preset application scenarios as the target application scenario based on the key data in the data to be encoded and the similarity of the key data in each preset application scenario. In addition, the target application scenario may also be determined based on other methods, which are not specifically limited herein.
After the target application scene is determined, the huffman dictionary corresponding to the target application scene can be obtained through query according to the pre-stored scene-dictionary corresponding relation.
And S242, determining a preset encoding algorithm corresponding to the data type of the value data according to the data type of the value data and a preset type-algorithm corresponding relation.
The value data may be composed of elements such as text, numbers, and characters, and when the value data is composed of text, the data type may be a text type; when the value data consists of numbers, the data type can be a number type; when the value data is a character string composed of characters, the data type thereof may be a character string type. The data types of the value data may also include other types, which are not exhaustive herein.
In which, a better coding algorithm may be set for each type of data in advance according to empirical values or experimental values. Accordingly, the encoding apparatus or another apparatus (for example, a setting apparatus for presetting an encoding algorithm) may generate a type-algorithm correspondence according to the data type and the set encoding algorithm in response to the setting instruction, send the type-algorithm correspondence to the encoding end, and may update the type-algorithm correspondence. In addition, the coding device or other devices can also send specific implementation of each preset coding algorithm to the coding end to realize coding of the coding end; and sending the specific implementation of the preset decoding algorithm corresponding to each preset encoding algorithm to a decoding end so as to realize decoding of the decoding end.
Correspondingly, the encoding device can inquire the preset encoding algorithm corresponding to the data type according to the pre-stored type-algorithm corresponding relation and encode the value data according to the specific implementation of the preset encoding algorithm, so that the encoding of each type of value data according to a better encoding algorithm is realized, and the encoding flexibility and the encoding effect can be improved.
And S250, sequentially coding the data to be coded, coding the value data based on a preset coding algorithm in the coding process, and coding the data except the value data in the data to be coded based on the Huffman dictionary.
For example, referring to the sample data provided in this embodiment and table 1, when encoding is performed on the first sentence < View height = "600" width = "400" >, the encoding process may be:
the data in the XML file is read in a streaming mode, and from the first data (<), the data can be converted into binary codes by utilizing a Huffman dictionary firstly; for example, one can convert (<) to binary 010, view to binary 00101, height to 0011, (=) to 00001, and (") to 1;
when the encoding is finished with the first preset character ("), the data can be regarded as value data, and the data can be switched to encode the value data 600 by using a preset encoding algorithm;
when the data is coded to the second preset character ("), the current value data can be considered to be coded completely, and the data can be switched to be converted into binary codes by utilizing a Huffman dictionary, so that the data are repeatedly switched, the data are coded based on a preset coding algorithm, and the data except the value data in the data to be coded are coded based on the Huffman dictionary until the data to be coded are coded completely.
Because the Huffman coding is the encoding with different word heads, the identification and decoding of different code words can be carried out without setting division among the encoded code words. For example, the data to be encoded is "< ImageView", the binary code word encoded by the huffman dictionary is "01000100", and the original data which needs to occupy 10 bytes can be converted into 8-bit binary data, so that the storage space occupied after compression can be greatly reduced, the content can be represented by using a small amount of storage space, and the compression efficiency and the transmission efficiency can be improved.
And S260, transmitting the dictionary identification of the Huffman dictionary and the algorithm identification of the preset coding algorithm sequentially adopted in the coding process to a decoding end along with the coded data, so that the decoding end decodes the coded data on the basis of the dictionary identification and the algorithm identification.
When the Huffman dictionary in the preset application scene is generated, the dictionary identification of the Huffman dictionary in the preset scene can be generated, wherein the dictionary identification can only point to the Huffman dictionary in the preset application scene. And, the dictionary identifier and the scene identifier of the preset application scene may be utilized to generate the scene-dictionary correspondence.
The preset coding algorithms may be preset with corresponding algorithm identifiers, the decoding algorithms may also be preset with corresponding algorithm identifiers, and the algorithm identifiers of the paired coding algorithms and decoding algorithms may be the same or may correspond to each other. It can be understood that the encoding end can determine the specific implementation of the corresponding preset encoding algorithm according to the algorithm identifier of the preset encoding algorithm; the decoding end can determine the corresponding algorithm identification of the preset decoding algorithm according to the algorithm identification of the preset coding algorithm, and further can determine the specific implementation of the preset decoding algorithm. Moreover, the type-algorithm corresponding relation can be generated by using the algorithm identification of the preset coding algorithm and the type identification of the data type.
The encoding device can reserve a space with a fixed size at a preset position of encoded data so as to store dictionary identification and algorithm identification of a preset encoding algorithm adopted in sequence. Correspondingly, after receiving the data sent by the encoding device, the decoding end may obtain the dictionary identifier and the algorithm identifier from a predetermined preset position to decode the data. Through the cooperative cooperation of the encoding end and the decoding end, the data compression transmission is realized, the transmission efficiency is improved, and the data security is ensured.
On the basis of the embodiment, the embodiment of the invention elaborates the generation step of the Huffman dictionary before coding, the acquisition step of the Huffman dictionary and the preset coding algorithm in the coding process, and the sending step after the coding is finished. By generating the Huffman dictionary in the preset application scene, data coding can be performed by using the Huffman dictionary when data transmission is performed in the corresponding application scene. The Huffman dictionary required by the coding process can be obtained through query based on the application scene corresponding to the key data; through the data type based on the value data, a proper preset coding algorithm can be obtained through query. By sending the encoded data to the decoding end, the encrypted transmission of the compressed data can be realized, and the data transmission efficiency can be improved.
In addition, the data encoding method proposed by the embodiment of the present invention and the above embodiment belong to the same inventive concept, and the technical details that are not described in detail in the embodiment can be referred to the above embodiment, and the embodiment and the above embodiment have the same beneficial effects.
EXAMPLE III
Fig. 3 shows a flowchart of a data decoding method according to a third embodiment of the present invention. The data decoding method provided by the embodiment of the invention can be applied to the condition of decoding and decompressing data, for example, the condition of decoding the encoded data after receiving the encoded data of which the essential content is key value pair information. The method may be performed by a data decoding apparatus (which may be simply referred to as a decoding apparatus) implemented in software and/or hardware, and is preferably configured in a terminal device, for example, a device at a decoding end.
As shown in fig. 3, the data decoding method provided in the embodiment of the present invention includes the following steps:
s310, receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded includes value data to be decoded.
When the encoding device transmits the dictionary identification of the Huffman dictionary and the algorithm identification of the preset encoding algorithm sequentially adopted in the encoding process to the decoding end along with the encoded data, for the decoding end, the encoded data is the data to be decoded, and the data with the data encoded is the data to be encoded.
After receiving the data sent by the encoding device, the decoding device can obtain the dictionary identifier and the algorithm identifier of the preset encoding algorithm sequentially adopted by the data to be decoded in the encoding process from the preset position.
S320, acquiring a target Huffman dictionary based on the dictionary identification, and acquiring a preset decoding algorithm corresponding to the sequentially adopted preset coding algorithm based on the algorithm identification.
In the embodiment of the present invention, the decoding apparatus may store in advance: the Huffman dictionary under each preset scene and the corresponding relation between the scene and the dictionary. The step of generating the huffman dictionary in each preset scene may refer to the above embodiments. The scene-dictionary correspondence may be generated based on the dictionary identifier and the scene identifier of the preset application scene. And the Huffman dictionary under each preset scene can be synchronously updated with the Huffman dictionary under each preset scene in the coding device.
Accordingly, after obtaining the dictionary identifier, the decoding apparatus obtains the target huffman dictionary based on the dictionary identifier, and may include: and inquiring a target Huffman dictionary corresponding to the dictionary identification from the prestored Huffman dictionaries under all preset scenes according to the preset scene-dictionary corresponding relation, wherein the target Huffman dictionary can be considered to be the same as the Huffman dictionary used in the data coding process.
In addition, the decoding device may further have stored therein in advance: the corresponding relation between the algorithm identifications of the paired preset encoding algorithm and preset decoding algorithm, the corresponding relation between the algorithm identification of each preset decoding algorithm and the specific implementation of the preset decoding algorithm, and the specific implementation of each preset decoding algorithm.
Correspondingly, the obtaining, by the decoding device, the preset decoding algorithm corresponding to the sequentially adopted preset encoding algorithm based on the algorithm identifier may include: determining algorithm identifications of preset decoding algorithms corresponding to the sequentially adopted preset coding algorithms based on the algorithm identifications according to the corresponding relationship between the pre-stored preset coding algorithms and the algorithm identifications of the preset decoding algorithms; and determining the preset decoding algorithm according to the algorithm identification of the preset decoding algorithm which is determined in sequence. The step of determining the preset decoding algorithm according to the sequentially determined algorithm identifiers of the preset decoding algorithm may be that the specific implementation of the preset decoding algorithm is queried according to a correspondence between the pre-stored algorithm identifier of each preset decoding algorithm and the specific implementation of the preset decoding algorithm, so as to implement decoding based on the specific implementation of the preset decoding algorithm.
S330, sequentially decoding the data to be decoded, decoding the data to be decoded based on the sequentially acquired preset decoding algorithm in the decoding process, and decoding the data except the data to be decoded in the data to be decoded based on the target Huffman dictionary.
In the embodiment of the present invention, the data to be decoded may be sequentially decoded according to a preset order, such as a data receiving order. In the decoding process, whether the data to be decoded currently is the data to be decoded or not can be judged; if so, decoding the current data by using a preset decoding algorithm which is acquired in sequence; otherwise, decoding the current data by utilizing the target Huffman dictionary. And the sequentially identified data to be decoded is decoded through the sequentially acquired preset decoding algorithm, so that the decoding accuracy can be ensured.
Decoding the value data to be decoded based on a preset decoding algorithm, wherein the decoding may include performing operation on the value data to be decoded by using the preset decoding algorithm; decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary, which may include querying the original data corresponding to the current codeword by using the target Huffman dictionary.
In some optional embodiments, in the decoding process, the method further includes: and determining data between the coded first preset character and the coded second preset character in the data to be decoded as value data to be decoded.
In these alternative implementations, the first preset character and the second preset character may refer to the description of the above embodiments. By setting the first preset character after encoding and the second preset character after encoding, the judgment of the value data to be decoded is realized, and the switching between the decoding mode of decoding based on the target Huffman dictionary and the decoding mode of decoding based on the preset decoding algorithm in the decoding process is facilitated.
The data decoding method provided by the embodiment of the invention comprises the steps of receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded includes value data to be decoded; acquiring a target Huffman dictionary based on the dictionary identification, and acquiring a preset decoding algorithm corresponding to a preset coding algorithm adopted in sequence based on the algorithm identification; and sequentially decoding the data to be decoded, decoding the value data to be decoded based on a preset decoding algorithm which is sequentially acquired in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
The correct Huffman dictionary and the preset decoding algorithm can be obtained based on the dictionary identification and the preset algorithm identification, so that the data to be decoded is decoded under the condition that the encoding end and the decoding end are separated. Through the cooperative cooperation of the encoding end and the decoding end, the data compression transmission is realized, the transmission efficiency is improved, and the data security is ensured.
In addition, the embodiment of the present invention and the data encoding method proposed by the above embodiment belong to the same inventive concept, and the technical details that are not described in detail in the embodiment can be referred to the above embodiment, and the embodiment and the above embodiment have the same beneficial effects.
Example four
Fig. 4 shows a schematic structural diagram of a data encoding apparatus according to a fourth embodiment of the present invention. The embodiment of the invention can be applied to the condition of coding and compressing data, for example, the condition of compressing and coding the key value pair information before the key value pair information is transmitted as the essential content. The data encoding method provided by the embodiment can be realized through the data encoding device provided by the invention.
As shown in fig. 4, the data encoding apparatus in the embodiment of the present invention includes:
a data to be encoded obtaining module 410, configured to obtain data to be encoded, where the data to be encoded includes key data and value data;
a coding algorithm obtaining module 420, configured to obtain a huffman dictionary corresponding to the key data and obtain a preset coding algorithm corresponding to the value data;
and the encoding module 430 is configured to sequentially encode the data to be encoded, encode the value data based on a preset encoding algorithm in the encoding process, and encode the data, excluding the value data, in the data to be encoded based on the huffman dictionary.
In some optional embodiments, the data encoding apparatus further includes:
the dictionary generation module is used for acquiring sample data in a preset application scene and counting the frequency of data except the value data in the sample data; and coding the data except the value data in the sample data according to the frequency based on a Huffman coding method to obtain a Huffman dictionary under a preset application scene.
In some optional embodiments, the coding algorithm obtaining module includes:
the dictionary acquisition unit is used for determining a target application scene of data to be encoded according to the key data; and determining a Hoffman dictionary corresponding to the target application scene based on a preset scene-dictionary corresponding relation.
In some optional embodiments, the encoding algorithm obtaining module includes:
and the algorithm acquisition unit is used for determining a preset coding algorithm corresponding to the data type of the value data according to the data type of the value data and a preset type-algorithm corresponding relation.
In some optional embodiments, the encoding module is specifically configured to:
in the encoding process, data between a first preset character and a second preset character in the data to be encoded is determined as value data.
In some optional embodiments, the data encoding apparatus comprises:
and the sending module is used for sending the dictionary identification of the Huffman dictionary and the algorithm identification of the preset coding algorithm sequentially adopted in the coding process to the decoding end along with the coded data so that the decoding end decodes the coded data based on the dictionary identification and the algorithm identification.
The data encoding apparatus provided by the embodiment of the present invention belongs to the same inventive concept as the data encoding method provided by the above embodiment, and the technical details that are not described in detail in the embodiment of the present invention can be referred to the above embodiment, and the embodiment of the present invention has the same beneficial effects as the above embodiment.
EXAMPLE five
Fig. 5 shows a schematic structural diagram of a data decoding apparatus according to a fifth embodiment of the present invention. The embodiment of the invention can be applied to the situation of decoding and decompressing data, for example, the situation of decoding the coded data after receiving the coded data of which the essential content is the key value pair information. The data decoding device provided by the invention can realize the data decoding method provided by the embodiment.
As shown in fig. 5, the data decoding apparatus in the embodiment of the present invention includes:
the data receiving module 510 is configured to receive data to be decoded, a dictionary identifier, and an algorithm identifier of a preset encoding algorithm that is sequentially adopted by the data to be decoded in an encoding process; wherein the data to be decoded comprises value data to be decoded;
a decoding algorithm obtaining module 520, configured to obtain a target huffman dictionary based on the dictionary identifier, and obtain a preset decoding algorithm corresponding to a sequentially adopted preset encoding algorithm based on the algorithm identifier;
the decoding module 530 is configured to decode the data to be decoded in sequence, and in the decoding process, decode the value data to be decoded based on the preset decoding algorithm obtained in sequence, and decode the data to be decoded, except the value data to be decoded, in the data to be decoded based on the target huffman dictionary.
In this embodiment, when the encoding device transmits the dictionary identifier of the huffman dictionary and the algorithm identifier of the preset encoding algorithm sequentially adopted in the encoding process to the decoding end along with the encoded data, for the decoding end, the encoded data is the data to be decoded, and the data with the encoded value data is the value data to be encoded.
And the data receiving module can acquire the dictionary identification and the algorithm identification of the preset coding algorithm sequentially adopted by the data to be decoded in the coding process from a preset position after receiving the data sent by the coding device.
In the embodiment of the present invention, the decoding apparatus may pre-store therein: the Huffman dictionary under each preset scene and the corresponding relation between the scene and the dictionary. The scene-dictionary correspondence may be generated based on the dictionary identifier and the scene identifier of the preset application scene. And the Huffman dictionary under each preset scene can be synchronously updated with the Huffman dictionary under each preset scene in the coding device.
Correspondingly, the decoding algorithm obtaining module may be configured to query a target huffman dictionary from the pre-stored huffman dictionaries in each preset scene according to the preset scene-dictionary correspondence after obtaining the dictionary identifier, where the target huffman dictionary may be considered to be the same as the huffman dictionary used in the data encoding process.
In addition, the decoding device may further have stored therein in advance: the corresponding relation between the algorithm identifications of the paired preset encoding algorithm and preset decoding algorithm, the corresponding relation between the algorithm identification of each preset decoding algorithm and the specific implementation of the preset decoding algorithm, and the specific implementation of each preset decoding algorithm.
Accordingly, the decoding algorithm obtaining module may be configured to: determining algorithm identifications of preset decoding algorithms corresponding to the sequentially adopted preset coding algorithms based on the algorithm identifications according to the corresponding relationship between the pre-stored preset coding algorithms and the algorithm identifications of the preset decoding algorithms; and determining the preset decoding algorithm according to the algorithm identification of the preset decoding algorithm which is determined in sequence. The specific implementation of the preset decoding algorithm is inquired according to the corresponding relationship between the pre-stored algorithm identifier of each preset decoding algorithm and the specific implementation of the preset decoding algorithm, so as to realize decoding based on the specific implementation of the preset decoding algorithm.
In this embodiment, the decoding module may be specifically configured to: and decoding the data to be decoded in sequence according to a preset sequence such as a data receiving sequence. In the decoding process, whether the data to be decoded currently is the data to be decoded or not can be judged; if so, decoding the current data by using a preset decoding algorithm which is acquired in sequence; otherwise, decoding the current data by utilizing the target Huffman dictionary.
Decoding the value data to be decoded based on a preset decoding algorithm, wherein the decoding may include operating the value data to be decoded by using the preset decoding algorithm; decoding data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary, which may include querying original data corresponding to the current codeword by using the target Huffman dictionary.
In this embodiment, the decoding module is further configured to: and determining data between the encoded first preset character and the encoded second preset character in the data to be decoded as the value data to be decoded.
The data decoding apparatus provided by the embodiment of the present invention belongs to the same inventive concept as the data decoding method provided by the above embodiment, and the technical details that are not described in detail in the embodiment of the present invention can be referred to the above embodiment, and the embodiment of the present invention has the same beneficial effects as the above embodiment.
EXAMPLE six
Fig. 6 shows a schematic structural diagram of a data transmission system according to a sixth embodiment of the present invention. The embodiment of the invention can be suitable for the condition of encrypting and transmitting data, for example, before the essential content is key value pair information, the key value pair information is compressed and encoded by using the encoding terminal; accordingly, the decoding side receives the encoded data having the key value pair information as the substantial content and then decodes the encoded data. The data transmission system provided by the invention can realize the data coding method and the data decoding method provided by the embodiment.
As shown in fig. 6, the data transmission system in the embodiment of the present invention includes a data encoding device 610 and a data decoding device 620 in any embodiment of the present invention;
the data coding device sends the data to be decoded, the dictionary identification and the algorithm identification of the preset coding algorithm adopted by the data to be decoded in sequence in the coding process to the data decoding device.
Through the cooperative cooperation of the encoding end and the decoding end, the data encoding and decoding and compression transmission are realized under the condition that the encoding end and the decoding end are separated, the transmission efficiency is improved, and the data security is ensured.
In this embodiment, the data encoding device 610 may include:
the device comprises a to-be-coded data acquisition module, a data acquisition module and a data acquisition module, wherein the to-be-coded data acquisition module is used for acquiring the to-be-coded data, and the to-be-coded data comprises key data and value data;
the encoding algorithm acquisition module is used for acquiring a Huffman dictionary corresponding to the key data and acquiring a preset encoding algorithm corresponding to the value data;
and the coding module is used for sequentially coding the data to be coded, coding the value data based on a preset coding algorithm in the coding process, and coding the data except the value data in the data to be coded based on the Huffman dictionary.
In some optional embodiments, the data encoding apparatus further includes:
the dictionary generation module is used for acquiring sample data in a preset application scene and counting the frequency of data except the value data in the sample data; and coding the data except the value data in the sample data according to frequency based on a Huffman coding method to obtain a Huffman dictionary under a preset application scene.
In some optional embodiments, the coding algorithm obtaining module includes:
the dictionary acquisition unit is used for determining a target application scene of data to be encoded according to the key data; and determining a Hoffman dictionary corresponding to the target application scene based on a preset scene-dictionary corresponding relation.
In some optional embodiments, the coding algorithm obtaining module includes:
and the algorithm acquisition unit is used for determining a preset coding algorithm corresponding to the data type of the value data according to the data type of the value data and a preset type-algorithm corresponding relation.
In some optional embodiments, the encoding module is specifically configured to: in the encoding process, data between a first preset character and a second preset character in the data to be encoded is determined as value data.
In some optional embodiments, the data encoding apparatus further comprises:
and the sending module is used for sending the dictionary identification of the Huffman dictionary and the algorithm identification of the preset coding algorithm sequentially adopted in the coding process to the decoding end along with the coded data so that the decoding end decodes the coded data based on the dictionary identification and the algorithm identification.
In this embodiment, the data decoding apparatus 620 may include:
the data receiving module is used for receiving the data to be decoded, the dictionary identification and the algorithm identification of the preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded includes value data to be decoded;
the decoding algorithm obtaining module is used for obtaining a target Huffman dictionary based on the dictionary identification and obtaining a preset decoding algorithm corresponding to a preset coding algorithm adopted in sequence based on the algorithm identification;
and the decoding module is used for sequentially decoding the data to be decoded, decoding the value data to be decoded based on the sequentially acquired preset decoding algorithm in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
In some optional embodiments, the decoding algorithm obtaining module may be configured to query a target huffman dictionary from pre-stored huffman dictionaries in each preset scene according to a preset scene-dictionary correspondence, where the target huffman dictionary may be considered to be the same as a huffman dictionary used in the data encoding process.
In some optional embodiments, the decoding algorithm obtaining module may be configured to: determining algorithm identifications of preset decoding algorithms corresponding to the sequentially adopted preset coding algorithms based on the algorithm identifications according to the corresponding relationship between the pre-stored preset coding algorithms and the algorithm identifications of the preset decoding algorithms; and determining the preset decoding algorithm according to the algorithm identification of the preset decoding algorithm which is determined in sequence. The specific implementation of the preset decoding algorithm is inquired according to the corresponding relationship between the pre-stored algorithm identifier of each preset decoding algorithm and the specific implementation of the preset decoding algorithm, so as to realize decoding based on the specific implementation of the preset decoding algorithm.
In some optional embodiments, the decoding module may be further specifically configured to: and decoding the data to be decoded in sequence according to a preset sequence such as a data receiving sequence. In the decoding process, whether the data to be decoded currently is the data to be decoded or not can be judged; if so, decoding the current data by using a preset decoding algorithm which is acquired in sequence; otherwise, decoding the current data by utilizing the target Huffman dictionary.
Decoding the value data to be decoded based on a preset decoding algorithm, wherein the decoding may include operating the value data to be decoded by using the preset decoding algorithm; decoding data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary, which may include querying original data corresponding to the current codeword by using the target Huffman dictionary.
In some optional embodiments, the decoding module may be further operable to: and determining data between the encoded first preset character and the encoded second preset character in the data to be decoded as the value data to be decoded.
The data transmission system provided by the embodiment of the present invention is the same as the data encoding device and the data decoding device provided by the above embodiment, and the technical details that are not described in detail in the embodiment of the present invention can be referred to the above embodiment, and the embodiment of the present invention has the same beneficial effects as the above embodiment.
EXAMPLE seven
Fig. 7 shows a schematic diagram of a hardware structure of a terminal device according to a seventh embodiment of the present invention. The terminal device in the embodiments of the present invention may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the use range of the embodiment of the present invention.
As shown in fig. 7, the terminal device 700 may include a processing means (e.g., a central processing unit, a graphic processor, etc.) 701, which may perform various appropriate actions and processes according to a program stored in a Read-Only Memory (ROM) 702 or a program loaded from a storage means 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data necessary for the operation of the terminal apparatus 700 are also stored. The processing device 701, the ROM 702, and the RAM703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Generally, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the terminal device 700 to communicate with other devices wirelessly or by wire to exchange data. While fig. 7 illustrates a terminal device 700 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, the processes described above with reference to the flowcharts may be implemented as a computer software program according to an embodiment of the present invention. For example, embodiments of the invention include a computer program product comprising a computer program embodied on a computer-readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via the communication means 709, or may be installed from the storage means 708, or may be installed from the ROM 702. When executed by the processing device 701, the computer program performs the above-described functions defined in the data encoding method or the data decoding method provided by the embodiment of the present invention.
The terminal provided by the embodiment of the present invention belongs to the same inventive concept as the data encoding method and the data decoding method provided by the above embodiment, and the technical details that are not described in detail in the embodiment of the present invention can be referred to the above embodiment, and the embodiment of the present invention has the same beneficial effects as the above embodiment.
Example eight
An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the data encoding method or the data decoding method provided by the above-described embodiment.
It should be noted that the computer readable storage medium mentioned above in the embodiments of the present invention may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an Erasable Programmable Read-Only Memory (EPROM) or FLASH Memory (FLASH), an optical fiber, a portable compact disc Read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In embodiments of the invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In yet another embodiment of the invention, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer-readable storage medium may be included in the terminal device or may be separately present without being incorporated in the terminal device.
The terminal device stores one or more programs, and when the one or more programs are executed by the terminal device, the terminal device is enabled to:
acquiring data to be encoded, wherein the data to be encoded comprises key data and value data;
acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data;
sequentially encoding data to be encoded, encoding the value data based on a preset encoding algorithm in the encoding process, and encoding data except the value data in the data to be encoded based on a Huffman dictionary;
or, causing the terminal device to:
receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded comprises value data to be decoded;
acquiring a target Huffman dictionary based on the dictionary identification, and acquiring a preset decoding algorithm corresponding to a sequentially adopted preset coding algorithm based on the algorithm identification;
and sequentially decoding the data to be decoded, decoding the data to be decoded based on a preset decoding algorithm which is sequentially acquired in the decoding process, and decoding the data except the data to be decoded in the data to be decoded based on the target Huffman dictionary.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functional pages noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present invention may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), system on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments illustrated herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in some detail by the above embodiments, the invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the invention, and the scope of the invention is determined by the scope of the appended claims.

Claims (14)

1. A method of encoding data, comprising:
acquiring data to be encoded, wherein the data to be encoded comprises key data and value data;
acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data;
sequentially encoding the data to be encoded, encoding the value data based on the preset encoding algorithm in the encoding process, and encoding the data except the value data in the data to be encoded based on the Huffman dictionary;
wherein, the acquiring of the preset encoding algorithm corresponding to the value data includes:
and determining a preset encoding algorithm corresponding to the data type of the value data according to the data type of the value data and a preset type-algorithm corresponding relation.
2. The method of claim 1, wherein the huffman dictionary is generated based on the steps of:
acquiring sample data in a preset application scene, and counting the frequency of data except value data in the sample data;
and coding the data except the value data in the sample data according to frequency based on a Huffman coding method to obtain the Huffman dictionary under the preset application scene.
3. The method according to claim 1, wherein the obtaining of the huffman dictionary corresponding to the key data comprises:
determining a target application scene of the data to be coded according to the key data;
and determining a Hoffman dictionary corresponding to the target application scene based on a preset scene-dictionary corresponding relation.
4. The method of claim 1, wherein during the encoding process, further comprising:
and determining data between a first preset character and a second preset character in the data to be coded as value data.
5. The method of claim 1, further comprising:
and sending the dictionary identification of the Huffman dictionary and the algorithm identification of a preset coding algorithm sequentially adopted in the coding process to a decoding end along with the coded data, so that the decoding end decodes the coded data on the basis of the dictionary identification and the algorithm identification.
6. A method of decoding data, comprising:
receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded comprises value data to be decoded; the value data to be decoded is data of the value data after being encoded, and a preset encoding algorithm adopted in the value data in the encoding process is determined according to the data type of the value data and a preset type-algorithm corresponding relation;
acquiring a target Huffman dictionary based on the dictionary identification, and acquiring a preset decoding algorithm corresponding to a sequentially adopted preset coding algorithm based on the algorithm identification;
and sequentially decoding the data to be decoded, decoding the value data to be decoded based on a preset decoding algorithm which is sequentially acquired in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
7. The method of claim 6, wherein obtaining a target Huffman dictionary based on the dictionary identification comprises:
and inquiring a target Hofmann dictionary corresponding to the dictionary identification from the prestored Hofmann dictionaries under all preset scenes according to the preset scene-dictionary corresponding relation.
8. The method according to claim 6, wherein the obtaining of the preset decoding algorithm corresponding to the sequentially adopted preset encoding algorithm based on the algorithm identification comprises:
determining algorithm identifications of preset decoding algorithms corresponding to the sequentially adopted preset coding algorithms based on the algorithm identifications according to the corresponding relationship between the pre-stored preset coding algorithms and the algorithm identifications of the preset decoding algorithms;
and determining the preset decoding algorithm according to the algorithm identification of the preset decoding algorithm which is determined in sequence.
9. The method of claim 6, further comprising, during the decoding process:
and determining data between the coded first preset character and the coded second preset character in the data to be decoded as value data to be decoded.
10. A data encoding apparatus, comprising:
the device comprises a to-be-coded data acquisition module, a data acquisition module and a data acquisition module, wherein the to-be-coded data acquisition module is used for acquiring the to-be-coded data, and the to-be-coded data comprises key data and value data;
the coding algorithm acquisition module is used for acquiring a Huffman dictionary corresponding to the key data and acquiring a preset coding algorithm corresponding to the value data;
the encoding module is used for sequentially encoding the data to be encoded, encoding the value data based on the preset encoding algorithm in the encoding process, and encoding the data except the value data in the data to be encoded based on the Huffman dictionary;
wherein, the coding algorithm obtaining module comprises:
and the algorithm acquisition unit is used for determining a preset coding algorithm corresponding to the data type of the value data according to the data type of the value data and a preset type-algorithm corresponding relation.
11. A data decoding apparatus, comprising:
the data receiving module is used for receiving data to be decoded, dictionary identification and algorithm identification of a preset coding algorithm adopted by the data to be decoded in sequence in the coding process; wherein the data to be decoded includes value data to be decoded; the value data to be decoded is data of the value data after being encoded, and a preset encoding algorithm adopted in the value data in the encoding process is determined according to the data type of the value data and a preset type-algorithm corresponding relation;
the decoding algorithm obtaining module is used for obtaining a target Huffman dictionary based on the dictionary identification and obtaining a preset decoding algorithm corresponding to a preset coding algorithm adopted in sequence based on the algorithm identification;
and the decoding module is used for sequentially decoding the data to be decoded, decoding the value data to be decoded based on a sequentially acquired preset decoding algorithm in the decoding process, and decoding the data except the value data to be decoded in the data to be decoded based on the target Huffman dictionary.
12. A data transmission system comprising a data encoding apparatus as claimed in claim 10, and a data decoding apparatus as claimed in claim 11;
the data encoding device sends data to be decoded, dictionary identification and algorithm identification of a preset encoding algorithm adopted by the data to be decoded in sequence in the encoding process to the data decoding device.
13. A terminal device, characterized in that the terminal comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a data encoding method as claimed in any one of claims 1 to 5, or to implement a data decoding method as claimed in any one of claims 6 to 9.
14. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out a data encoding method as claimed in any one of claims 1 to 5, or carries out a data decoding method as claimed in any one of claims 6 to 9.
CN202110335553.2A 2021-03-29 2021-03-29 Data encoding and decoding method, device, transmission system, terminal equipment and storage medium Active CN112995199B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110335553.2A CN112995199B (en) 2021-03-29 2021-03-29 Data encoding and decoding method, device, transmission system, terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110335553.2A CN112995199B (en) 2021-03-29 2021-03-29 Data encoding and decoding method, device, transmission system, terminal equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112995199A CN112995199A (en) 2021-06-18
CN112995199B true CN112995199B (en) 2023-03-10

Family

ID=76337932

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110335553.2A Active CN112995199B (en) 2021-03-29 2021-03-29 Data encoding and decoding method, device, transmission system, terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112995199B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115941808A (en) * 2023-03-02 2023-04-07 深圳依时货拉拉科技有限公司 Json data compression method and device based on self-training dictionary coding
CN117278055B (en) * 2023-11-07 2024-04-16 杭州易靓好车互联网科技有限公司 Vehicle sales information optimized storage method based on data analysis

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103997651A (en) * 2014-05-17 2014-08-20 北京中和卓远科技有限公司 Data compression method and device for composite images
CN109257077A (en) * 2018-11-15 2019-01-22 东南大学 A kind of new spatial modulator approach of combination huffman coding and Bose-Chaudhuri-Hocquenghem Code
CN109660262A (en) * 2019-01-30 2019-04-19 重庆农村商业银行股份有限公司 A kind of character coding method and system applied to E-mail address
CN112003625A (en) * 2020-08-14 2020-11-27 山东云海国创云计算装备产业创新中心有限公司 Huffman coding method, system and equipment
CN112332854A (en) * 2020-11-27 2021-02-05 平安普惠企业管理有限公司 Hardware implementation method and device of Huffman coding and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8610604B2 (en) * 2011-11-24 2013-12-17 International Business Machines Corporation Compression algorithm incorporating a feedback loop for dynamic selection of a predefined Huffman dictionary

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103997651A (en) * 2014-05-17 2014-08-20 北京中和卓远科技有限公司 Data compression method and device for composite images
CN109257077A (en) * 2018-11-15 2019-01-22 东南大学 A kind of new spatial modulator approach of combination huffman coding and Bose-Chaudhuri-Hocquenghem Code
CN109660262A (en) * 2019-01-30 2019-04-19 重庆农村商业银行股份有限公司 A kind of character coding method and system applied to E-mail address
CN112003625A (en) * 2020-08-14 2020-11-27 山东云海国创云计算装备产业创新中心有限公司 Huffman coding method, system and equipment
CN112332854A (en) * 2020-11-27 2021-02-05 平安普惠企业管理有限公司 Hardware implementation method and device of Huffman coding and storage medium

Also Published As

Publication number Publication date
CN112995199A (en) 2021-06-18

Similar Documents

Publication Publication Date Title
CN106407201B (en) Data processing method and device and computer readable storage medium
US9094038B2 (en) Compressing and decompressing signal data
CN112995199B (en) Data encoding and decoding method, device, transmission system, terminal equipment and storage medium
CN109831409B (en) Data transmission method and device, computer readable storage medium and electronic equipment
CN107395209B (en) Data compression method, data decompression method and equipment thereof
CN108733317B (en) Data storage method and device
CN115208414B (en) Data compression method, data compression device, computer device and storage medium
WO2018157853A1 (en) Method, device, and equipment for use in determining coding and decoding of polar code
CN112399479B (en) Method, electronic device and storage medium for data transmission
CN115567589B (en) Compression transmission method, device and equipment of JSON data and storage medium
CN113630125A (en) Data compression method, data encoding method, data decompression method, data encoding device, data decompression device, electronic equipment and storage medium
CN110602498B (en) Self-adaptive finite state entropy coding method
US8018359B2 (en) Conversion of bit lengths into codes
CN107645665B (en) WebP entropy coding method and device
CN112434231B (en) Data processing method and device and electronic equipment
CN115103191A (en) Image processing method, device, equipment and storage medium
CN114611120A (en) Data encryption method, device, equipment and medium
CN114070470A (en) Encoding and decoding method and device
US10742783B2 (en) Data transmitting apparatus, data receiving apparatus and method thereof having encoding or decoding functionalities
CN113760343A (en) Method and device for processing service request
CN111737572A (en) Search statement generation method and device and electronic equipment
CN111949627B (en) Method, device, electronic equipment and medium for tabulating log files
CN110545108B (en) Data processing method and device, electronic equipment and computer readable storage medium
CN115833847B (en) Polar code decoding method, polar code decoding device, communication equipment and storage medium
CN110874308B (en) Method and device for generating unique value

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant