Character compiling method and device, equipment and medium
By updating and generating identifier bytes, using an encoding mapping table to find the target character and replacing it in the second type of bytes, the problem of excessively large data size in existing technologies is solved, and more efficient network transmission is achieved.
Patent Information
- Application Number
- CN202210806750.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-08
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2042-07-08
AI Technical Summary
Existing character encoding algorithms result in encoded data that is more than twice the size of the original data, consuming excessive network bandwidth and reducing transmission efficiency.
By acquiring at least two first-class bytes, updating them to second-class bytes, and generating identifier bytes, the target character is found using the encoding mapping table and replaced in the second-class bytes to generate third-class bytes. During decoding, the decoding mapping table is used for decoding, thereby reducing the data size.
The encoded data is 1.5 times larger than the original data, reducing storage space usage and network bandwidth consumption, and improving transmission efficiency.
Smart Images

Figure CN115293105B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computer, and particularly relates to a character compiling method and device, equipment and medium. BACKGROUND
[0002] Character encoding is used for encoding binary data in network transmission, and the encoded byte data is used for network transmission. The encoded data can be visualized in various software, specifically, complex byte array data is converted into realizable string data. However, the related character encoding algorithm encodes the byte array data, and the size of the encoded data is more than 2 times. Excessive network bandwidth is occupied, and transmission efficiency is reduced.
[0003] Therefore, a device capable of reducing data size and reducing network bandwidth occupation is needed. SUMMARY
[0004] The present disclosure discloses a character compiling method and device, equipment and medium.
[0005] The first aspect of the present disclosure provides a character compiling method, which comprises: obtaining at least two first type bytes; updating the first type bytes to second type bytes according to the two first type bytes, and generating an identification byte; taking first type data in the nth second type byte as an index to find an nth first type target character corresponding to the first type data in an encoding mapping table; replacing second type data corresponding to the nth first type target character into the nth second type byte to obtain an nth third type byte; wherein the first type data is different from the second type data.
[0006] Optionally, the method further comprises: determining whether to decode the third type byte through a decoding mapping table according to the identification byte; if it is determined to decode the third type byte, obtaining a fourth type byte according to the decoding mapping table and the third type byte; and converting the first type byte according to the identification byte and the fourth type byte.
[0007] Optionally, updating the first type bytes to second type bytes according to the two first type bytes and generating an identification byte comprises: if the highest bit in the first first type byte is a first value, setting a first marker position of the identification byte to a first value; and setting the highest bit of the first first type byte to a second value to obtain a first second type byte; if the first first type data in the first second type byte is the same as the corresponding data in the encoding mapping table and the corresponding first first type target character, setting a second marker position of the identification byte to a first value.
[0008] Optionally, the updating the first type of bytes to second type of bytes and generating an identification byte according to the two first type of bytes comprises: if the highest bit of the second first type of byte is a first value, setting a third flag bit of the identification byte to a first value; and setting the highest bit of the second first type of byte to a second value to obtain a second second type of byte; and if the second first type of data in the second second type of byte and the corresponding second first type of target character in the encoding mapping table are identical, setting a fourth flag bit of the identification byte to a first value.
[0009] Optionally, the searching for the n th first type of target character corresponding to the first type of data in the n th second type of byte in the encoding mapping table according to the first type of data in the n th second type of byte as an index comprises one of: searching for the first first type of target character corresponding to the first type of data of the first second type of byte in the encoding mapping table according to the first type of data of the first second type of byte as an index; or searching for the second first type of target character corresponding to the first type of data of the second second type of byte in the encoding mapping table according to the first type of data of the second second type of byte as an index.
[0010] Optionally, the replacing the binary data corresponding to the n th first type of target character into the n th second type of byte to obtain an n th third type of byte comprises at least one of: replacing the second type of data corresponding to the first first type of target character into the first second type of byte to obtain a first third type of byte; or replacing the second type of data corresponding to the second first type of target character into the second second type of byte to obtain a second third type of byte.
[0011] Optionally, the determining whether to decode the third type of byte through the decoding mapping table according to the identification byte comprises at least one of: if the data of the second flag bit of the identification byte is a first value, determining to decode the first third type of byte through the decoding mapping table; or if the data of the fourth flag bit of the identification byte is a first value, determining to decode the second third type of byte through the decoding mapping table.
[0012] Optionally, if it is determined to decode the third type of byte, a fourth type of byte is obtained according to the decoding mapping table and the third type of byte, including at least one of the following: if it is determined to decode a first third type of byte, a first first type of target character corresponding to first second type of data of the first third type of byte is taken as an index to search the decoding mapping table for first first type of data corresponding to the first first type of target character; the first first type of data is used to replace the first second type of data of the first third type of byte to obtain a first fourth type of byte; or, if it is determined to decode a second third type of byte, a second first type of target character corresponding to second second type of data of the second third type of byte is taken as an index to search the decoding mapping table for second first type of data corresponding to the second first type of target character; the second first type of data is used to replace the second second type of data of the second third type of byte to obtain a second fourth type of byte.
[0013] Optionally, the first type of byte is converted according to the identification byte and the fourth type of byte, including at least one of the following: if a value of a first flag bit of the identification byte is a first value, a value of a highest bit in a first fourth type of byte is set as the first value to obtain a first first type of byte; or, if a value of a third flag bit of the identification byte is the first value, a value of a highest bit in a second fourth type of byte is set as the first value to obtain a second first type of byte.
[0014] The second aspect of the present disclosure provides a character encoding device, the device comprising: an acquisition module configured to acquire at least two first type of bytes; an updating and generating module configured to update the first type of bytes to second type of bytes according to the two first type of bytes, and generate an identification byte; a searching module configured to search an encoding mapping table for an nth first type of target character corresponding to first type of data in an nth second type of byte according to the first type of data as an index; a first determining module configured to replace second type of data corresponding to the nth first type of target character into the nth second type of byte to obtain an nth third type of byte; wherein the first type of data and the second type of data are different.
[0015] Optionally, the device further comprises: a second determining module configured to determine whether to decode the third type of byte through a decoding mapping table according to the identification byte; a third determining module configured to obtain a fourth type of byte according to the decoding mapping table and the third type of byte if it is determined to decode the third type of byte; and a converting module configured to convert the first type of byte according to the identification byte and the fourth type of byte.
[0016] Optionally, the updating and generating module is configured to: if the highest bit of the first first-type byte is a first value, set a first flag bit of the identification byte to the first value; and set the highest bit of the first first-type byte to a second value to obtain a first second-type byte; and if the first first-type data in the first second-type byte is identical to corresponding data in the encoding mapping table and corresponds to a first first-type target character, set a second flag bit of the identification byte to the first value.
[0017] Optionally, the updating and generating module is configured to: if the highest bit of the second first-type byte is a first value, set a third flag bit of the identification byte to the first value; and set the highest bit of the second first-type byte to a second value to obtain a second second-type byte; and if the second first-type data in the second second-type byte is identical to corresponding data in the encoding mapping table and corresponds to a second first-type target character, set a fourth flag bit of the identification byte to the first value.
[0018] Optionally, the searching module is configured to at least one of: search for a first first-type target character corresponding to the first first-type data of the first second-type byte in the encoding mapping table according to the first first-type data of the first second-type byte as an index; or search for a second first-type target character corresponding to the first first-type data of the second second-type byte in the encoding mapping table according to the first first-type data of the second second-type byte as an index.
[0019] Optionally, the first determining module is configured to at least one of: replace second-type data corresponding to the first first-type target character into the first second-type byte to obtain a first third-type byte; or replace second-type data corresponding to the second first-type target character into the second second-type byte to obtain a second third-type byte.
[0020] Optionally, the second determining module is configured to at least one of: if the data of the second flag bit of the identification byte is a first value, determine to decode the first third-type byte through a decoding mapping table; or if the data of the fourth flag bit of the identification byte is a first value, determine to decode the second third-type byte through the decoding mapping table.
[0021] Optionally, the third determining module is at least configured to one of the following: if it is determined to decode a first third type byte, taking a first first type target character corresponding to first second type data of the first third type byte as an index, searching the decoding mapping table for first first type data corresponding to the first first type target character; replacing the first second type data of the first third type byte with the first first type data to obtain a first fourth type byte; or, if it is determined to decode a second third type byte, taking a second first type target character corresponding to second second type data of the second third type byte as an index, searching the decoding mapping table for second first type data corresponding to the second first type target character; replacing the second second type data of the second third type byte with the second first type data to obtain a second fourth type byte.
[0022] Optionally, the conversion module is at least configured to one of the following: if a value of a first flag bit of the identification byte is a first value, setting a value of a highest bit in a first fourth type byte to the first value to obtain a first first type byte; or, if a value of a third flag bit of the identification byte is the first value, setting a value of a highest bit in a second fourth type byte to the first value to obtain a second first type byte.
[0023] A third aspect of the present disclosure provides an electronic device, comprising: a memory for storing processor-executable instructions; a processor connected with the memory; wherein the processor is configured to execute the character compiling method provided in the first aspect.
[0024] A fourth aspect of the present disclosure provides a non-transitory computer-readable storage medium, the computer-readable storage medium storing computer-executable instructions, the computer-executable instructions being executed by a processor to implement the character compiling method provided in the first aspect.
[0025] The character compiling method provided by the embodiments of the present disclosure comprises: updating the first type byte to a second type byte and generating an identification byte according to the two first type bytes; taking first type data in an nth second type byte as an index, searching an encoding mapping table for an nth first type target character corresponding to the first type data; replacing second type data corresponding to the nth first type target character into the nth second type byte to obtain an nth third type byte; in this way, the encoded data of the embodiments of the present disclosure is three bytes, which is 1.5 times of the original two bytes, which reduces the storage space occupied by the encoded data, and also occupies less network bandwidth when used for network transmission, thereby improving transmission efficiency.
[0026] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0027] The accompanying drawings, which are incorporated in and form a part of the specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure.
[0028] Figure 1 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0029] Figure 2 is an encoding mapping table of a character compiling method according to an exemplary embodiment of the present disclosure;
[0030] Figure 3 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0031] Figure 4 is a decoding mapping table of a character compiling method according to an exemplary embodiment of the present disclosure;
[0032] Figure 5 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0033] Figure 6 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0034] Figure 7 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0035] Figure 8 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0036] Figure 9 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0037] Figure 10 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0038] Figure 11 is a flowchart of a character compiling method according to an exemplary embodiment of the present disclosure;
[0039] Figure 12 is a byte encoding diagram of a character compiling method according to an exemplary embodiment of the present disclosure;
[0040] Figure 13is a schematic diagram of a byte encoding result of a character compiling method according to an example embodiment of the present disclosure;
[0041] Figure 14 is a schematic diagram of a byte decoding of a character compiling method according to an example embodiment of the present disclosure;
[0042] Figure 15 is a schematic diagram of a byte decoding result of a character compiling method according to an example embodiment of the present disclosure;
[0043] Figure 16 is a schematic diagram of a structure of a character compiling device according to an example embodiment of the present disclosure;
[0044] Figure 17 is a schematic diagram of a structure of a character compiling device according to an example embodiment of the present disclosure. DETAILED DESCRIPTION
[0045] The example embodiments will be described in detail herein, with examples shown in the drawings. When the following description refers to the drawings, same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following example embodiments do not represent all implementations consistent with the present disclosure. Instead, they are merely examples of apparatuses and methods consistent with some aspects of the present disclosure as detailed in the attached application files.
[0046] In the related art, the most commonly used byte encoding algorithm is the hex algorithm, which uses 1 byte to be divided into high 4 bits and low 4 bits, and the two parts are converted respectively to make them converted into two displayable character data, each of which occupies 1 byte, i.e. 8 bits. The data size after the Hex encoding of the algorithm is 2 times the original size, and the bandwidth data occupied in the network transmission becomes 2 times the original size, which greatly occupies the network bandwidth.
[0047] In combination with Figure 1 As shown in the present disclosure, a character compiling method is provided, which comprises:
[0048] Step S101, obtaining at least two first type bytes;
[0049] Step S102, updating the first type bytes to second type bytes according to the two first type bytes, and generating an identification byte;
[0050] Step S103, taking the first type data in the nth second type byte as an index to find the nth first type target character corresponding to the first type data in the encoding mapping table;
[0051] In step S104, the second type of data corresponding to the nth first type of target character is replaced into the nth second type of byte to obtain an nth third type of byte; wherein the first type of data is different from the second type of data.
[0052] In the embodiments of the present disclosure, the first type of byte is a byte having 8 bits and storing the first type of byte of original binary data.
[0053] In step S101, the binary data can be split, and every two first type of bytes are taken as two first type of bytes to be processed. Here, the binary data can include a plurality of first type of bytes, for example, n first type of bytes. Wherein, the n is an integer greater than or equal to 2.
[0054] In one embodiment, if the n is an even number, then it can be divided into every two first type of bytes as a group of two first type of bytes to be processed.
[0055] Alternatively, if the n is an odd number greater than 2, in step S102, one extra first type of byte can be added with one identification byte, and for the rest of every two first type of bytes, only one identification byte is added.
[0056] In some embodiments, in step S102, an identification byte includes a placeholder, a display mark and a coding mark.
[0057] The placeholder is used for format placeholder.
[0058] The display mark is used for data display. The coding mark is used to mark whether the first type of byte to the second type of byte has changed part of the data and whether the data in the second type of byte has a corresponding first type of target character in the coding mapping table.
[0059] Here, it is determined whether the data in the second type of byte has a corresponding first type of target character in the coding mapping table after changing part of the data.
[0060] Here, the placeholder can occupy the 1st, 3rd and 4th bit positions of the identification byte, the display mark can occupy the 2nd bit position of the identification byte, and the coding mark can occupy the last 4 bit positions of the identification byte.
[0061] Here, each of the first type of bytes occupies two bit positions of the coding mark, for example, the first first type of byte occupies the first two bit positions of the coding mark, and the second first type of byte occupies the last two bit positions of the coding mark.
[0062] In some embodiments, in relation to the step S103, the encoding mapping table stores the corresponding relationship between the binary data and the characters. Figure 2 The corresponding relationship between the data and the characters in the encoding mapping table proposed by the embodiments of the present disclosure is different from the corresponding relationship between the data and the characters in the internationally-accepted American Standard Code for Information Interchange (ASCII).
[0063] Here, the encoding mapping table may be, but is not limited to, a 64-bit binary mapping table and a 32-bit binary mapping table.
[0064] Thus, due to the corresponding relationship between the first type of data and the first type of target character in the encoding mapping table, if the first type of data in the first second type of byte exists in the encoding mapping table, the first type of data can be inserted into the corresponding first first type of target character. By analogy, the search for the second first type of target character in relation to the second second type of byte is consistent with the search process of the first second type of byte.
[0065] In relation to the step S104, after the nth first type of target character is found, the second type of data corresponding to the first type of target character is replaced into the nth second type of byte according to the corresponding relationship in the internationally-accepted ASCII table, so as to obtain the converted nth third type of byte. Since the encoding mapping table proposed by the present disclosure is different from the corresponding relationship between the data and the characters in the ASCII table, the first type of data corresponding to the same first type of target character is different from the second type of data.
[0066] Thus, the data in the third type of byte is different from the data in the second type of byte, and the conversion or encryption of the data is realized. Moreover, in relation to the data encoded by the hex algorithm in the prior art, which is more than twice the original data, the encoded data in the embodiments of the present disclosure is three bytes, which is 1.5 times the original two bytes, and the encoded data occupies less storage space, and when used for network transmission, the network bandwidth is also less occupied, and the transmission efficiency is improved.
[0067] In combination with Figure 3 As shown in the figure, the method further includes:
[0068] In step S105, it is determined whether the third type of byte is decoded by a decoding mapping table according to the identification byte.
[0069] In step S106, if it is determined that the third type of byte is decoded, a fourth type of byte is obtained according to the decoding mapping table and the third type of byte.
[0070] Step S107, converting the fourth type of bytes to the first type of bytes according to the identification bytes and the fourth type of bytes.
[0071] In the embodiments of the present disclosure, regarding the step S105, it is determined that there is a change from the second type of bytes to the third type of bytes according to the record in the encoding mark in the identification bytes about whether the data in the second type of bytes has a corresponding first type of target character in the encoding mapping table, so that it is determined that the third type of bytes needs to be decoded by the decoding mapping table.
[0072] In some embodiments, regarding the step S106, the decoding mapping table is as shown in Figure 4 The corresponding relationship between the characters and the data stored in the decoding mapping table is consistent with the corresponding relationship between the characters and the data in the encoding mapping table. The difference is that in the decoding mapping table, the second type of data in the third type of bytes is needed to determine the corresponding first type of target character according to the ASCII table, and then the first type of target character is used as an index to find the corresponding first type of data, so that the first type of data is filled into the third type of bytes to obtain the fourth type of bytes.
[0073] Here, the decoding mapping table can be but is not limited to a 64-bit binary mapping table and a 32-bit binary mapping table.
[0074] In some embodiments, since the identification bytes also store information about the change of part of the data, and the encoding is performed before the step S103, the step S107 is performed after the step S106. Thus, the first type of bytes can be correctly decoded.
[0075] Specifically, according to the change of part of the data from one value to another value marked in the encoding mark, the step S107 will convert the other value stored in the fourth type of bytes back to the one value, so as to convert and obtain the original first type of bytes.
[0076] In this way, the third type of bytes after encoding can be accurately decoded according to the identification bytes to obtain the original first type of bytes.
[0077] In combination with Figure 5 In the embodiments of the present disclosure, the step S102 updates the first type of bytes to the second type of bytes according to the two first type of bytes, and generates an identification byte, which includes:
[0078] Step S1021, if the highest bit of the first first type of bytes is a first value, the first mark position of the identification byte is set to a first value; and the highest bit of the first first type of bytes is set to a second value to obtain a first second type of bytes.
[0079] Step S1022, if the first first-type data in the first second-type byte is identical to the corresponding data in the encoding mapping table and the corresponding first first-type target character, the second flag position of the identification byte is set to the first value.
[0080] Here, the original byte of the identification byte can be 01000000. Then, from left to right, the 1st, 3rd and 4th bit positions are set to 0 as display flags, and the 2nd bit position is set to 1 as a placeholder; the 5th and 6th bit positions are set to 0 as the encoding flags of the first first-type byte, and the 7th and 8th bit positions are also set to 0 as the encoding flags of the second first-type byte.
[0081] It should be noted that the value of the highest bit of the first-type byte is changed to 0 or 1, which can be constructed according to the data in the encoding mapping table. If the highest bit of the data in the encoding mapping table is 0, the value of the highest bit of the first-type byte is 1, which needs to be 0. If the highest bit of the data in the encoding mapping table is 1, the value of the highest bit of the first-type byte is 0, which needs to be 1. So that the modified data in the first-type byte corresponds to the encoding mapping table as much as possible. Then, the highest bit of the data in the encoding mapping table is 0 as an example for description, and the embodiments of the present disclosure are not limited thereto. The highest bit of the data in the encoding mapping table can also be 1, which is within the scope of the present disclosure, and the conversion process is consistent, only the value is different.
[0082] In some embodiments, regarding the step S1021, if the highest bit of the first first-type byte is 1, the data in the first first-type byte cannot find the corresponding first-type data in the encoding mapping table, so the highest bit of the first first-type byte needs to be set to 0, and the first flag position in the identification byte is set to 1. Here, the first flag position in the identification byte refers to the encoding flag of the 1st bit position in the encoding flag corresponding to the first first-type byte.
[0083] If the highest bit of the first first-type byte is 0, it does not need to be modified to 0 again. At this time, the encoding flag of the 1st bit position in the encoding flag corresponding to the first first-type byte is the original 0.
[0084] In this way, if the value of the highest bit of the first first-type byte changes to correspond to the encoding mapping table as much as possible, the value conversion can be marked through the 1st bit position of the encoding flag, i.e., the 5th bit position of the identification byte.
[0085] In some embodiments, regarding the step S1022, if the first first-type data in the first second-type byte has a corresponding same data in the encoding mapping table and a corresponding first first-type target character, it is indicated that encoding can be performed, and thus the second flag position of the identification byte is set to 1.
[0086] Here, the second flag position is the second bit of the encoding flag, that is, the sixth bit of the identification byte. Through the second flag position, it can be determined whether the first first-type byte is converted into a second-type byte according to the data in the encoding mapping table, thereby facilitating determination of whether to perform decoding according to the decoding mapping table in the subsequent decoding process.
[0087] In combination with Figure 6 As shown in the figure, in the step S102, according to the two first-type bytes, the first-type bytes are updated into second-type bytes, and an identification byte is generated, which includes:
[0088] In the step S1023, if the highest bit of the second first-type byte is a first value, the third flag position of the identification byte is set to the first value, and the highest bit of the second first-type byte is set to a second value to obtain a second second-type byte.
[0089] In the step S1024, if the second first-type data in the second second-type byte has a corresponding same data in the encoding mapping table and a corresponding second first-type target character, the fourth flag position of the identification byte is set to the first value.
[0090] Here, the change of the second first-type byte and the change of the two encoding flag positions are similar to the change of the first first-type byte, for example, if the highest bit of the second first-type byte is 1, the number in the third bit of the encoding flag position is set to 1, and the highest bit of the second first-type byte is modified to 0 to obtain a second second-type byte. If the data in the second second-type byte can be queried to have a corresponding first-type data in the encoding mapping table, the number in the fourth bit of the encoding flag position is set to 1. For the updating process of every two first-type bytes into the second-type byte, the generation process and the role of the identification byte, the same is true.
[0091] Here, the third flag position corresponds to the third bit of the encoding flag position, that is, the seventh bit of the identification byte; and the fourth flag position corresponds to the fourth bit of the encoding flag position, that is, the eighth bit of the identification byte.
[0092] Thus, the changes in the second type of bytes can be determined by the third and fourth flag bits, and the fourth flag bit can be used as the basis for whether to decode according to the decoding map table.
[0093] Combination Figure 7 As shown in this embodiment, step S103, which involves using the first type of data in the nth second type of byte as an index to search for the nth first type of target character corresponding to the first type of data in the encoding mapping table, includes one of the following:
[0094] Step S1031: Using the first type of data of the first type of the second type of byte as an index, search in the encoding mapping table for the first target character of the first type of the first type of data corresponding to the first type of the first type of the second type of byte;
[0095] or,
[0096] Step S1032: Using the first type of data of the second second type of byte as an index, search for the second first type of target character corresponding to the first type of data of the second second type of byte in the encoding mapping table.
[0097] In some embodiments, regarding step S1031, according to as follows Figure 2 In the encoding mapping table shown, if the first type of data of the first second type byte is 0x00 in the encoding mapping table, then the corresponding first type of target character is 'A'. If the first type of data is 0x01 in the encoding mapping table, then the corresponding first type of character is 'B'. If it is any other value or the first type of data of the second second type byte in step S1032, the process of finding the corresponding first type of target character in the encoding mapping table is repeated accordingly.
[0098] It should be noted that in the encoding and decoding mapping tables, x represents 0 for 8-bit bytes, so 0x00 corresponds to 00000000; 0x01 corresponds to 00000001.
[0099] Thus, the second type of bytes can be encrypted using the encoding mapping table.
[0100] Combination Figure 8 As shown in this embodiment, step S104, which involves replacing the binary data corresponding to the nth first-type target character with the nth second-type byte to obtain the nth third-type byte, includes at least one of the following:
[0101] Step S1041: Replace the second type of data corresponding to the first first type of target character with the first second type of byte to obtain the first third type of byte;
[0102] Or,
[0103] Step S1042, replacing the second type of data corresponding to the second first type of target character into the second second type of byte to obtain a second third type of byte.
[0104] In some embodiments, regarding the second type of data corresponding to the first type of target character, the corresponding second type of data can be found according to the internationally recognized ASCII table. Then the found second type of data is replaced into the second type of byte to obtain the third type of byte.
[0105] For example, assuming that the first type of target character 'A' corresponds to the second type of data 01000001, 01000001 is filled into the second type of byte to obtain the third type of byte. For other characters, the same method is used.
[0106] In this way, the encryption coding from the second type of byte to the third type of byte is realized.
[0107] In combination Figure 9 As shown in the figure, in the embodiments of the present disclosure, the step S105 of determining whether to decode the third type of byte through the decoding mapping table according to the identification byte at least includes one of the following:
[0108] Step S1051, if the data of the second flag bit of the identification byte is the first value, it is determined to decode the first third type of byte through the decoding mapping table;
[0109] Or,
[0110] Step S1052, if the data of the fourth flag bit of the identification byte is the first value, it is determined to decode the second third type of byte through the decoding mapping table.
[0111] In some embodiments, the step S1051 corresponds to the step S1022, if the data of the second flag bit of the identification byte is the first value 1, it indicates that the first third type of byte has been encoded through the encoding mapping table, so the first third type of byte needs to be decoded through the decoding mapping table.
[0112] If the data of the second flag bit is the second value 0, it indicates that the first third type of byte has not been encoded through the encoding mapping table, so the first third type of byte does not need to be decoded through the decoding mapping table.
[0113] In some embodiments, corresponding to the step S1052, if the fourth flag bit of the identification byte is the first value 1, it indicates that the second third-type byte is encoded by the encoding mapping table, and thus the second third-type byte needs to be decoded by the decoding mapping table.
[0114] If the fourth flag bit is the second value 0, it indicates that the second third-type byte is not encoded by the encoding mapping table, and thus the first third-type byte does not need to be decoded by the decoding mapping table.
[0115] In this way, the second flag bit and the fourth flag bit in the encoding flag can be used to determine whether the third-type byte needs to be decoded.
[0116] In combination with Figure 10 In the embodiments of the present disclosure, the step S106, if it is determined that the third-type byte needs to be decoded, the fourth-type byte is obtained according to the decoding mapping table and the third-type byte, and at least one of the following is included:
[0117] In step S1061, if it is determined that the first third-type byte needs to be decoded, the first first-type data corresponding to the first second-type data of the first third-type byte is used as an index to search the decoding mapping table to find the first first-type data corresponding to the first first-type character.
[0118] In step S1062, the first first-type data is used to replace the first second-type data of the first third-type byte to obtain the first fourth-type byte.
[0119] Or,
[0120] In step S1063, if it is determined that the second third-type byte needs to be decoded, the second first-type data corresponding to the second second-type data of the second third-type byte is used as an index to search the decoding mapping table to find the second first-type data corresponding to the second first-type character.
[0121] In step S1064, the second first-type data is used to replace the second second-type data of the second third-type byte to obtain the second fourth-type byte.
[0122] In the embodiments of the present disclosure, in the step S1061, if the first first-type character corresponding to the first second-type data is ‘A’, the first first-type data can be found in the decoding mapping table as shown in Table 2. Figure 4The first first-type data corresponding to the 'A' in the decoding mapping table is 0x00. If the first first-type target character is another character, the corresponding first first-type data can be found in the decoding mapping table.
[0123] If the first first-type data is 0x00, the first second-type data such as 01000001 is replaced by 0x00, and the data in the first fourth-type byte is 0x00.
[0124] The process of the step S1063 is similar to that of the step 1061, except that the first-type target character can be different. The step S1063 can be analogized from the step S1061. Similarly, the step S1064 can be analogized from the step S1062.
[0125] In this way, the fourth-type byte after decoding corresponding to the decoding mapping table can be obtained.
[0126] In combination Figure 11 As shown, in the embodiments of the present disclosure, the step S107, according to the identification byte and the fourth-type byte, converts to obtain the first-type byte, at least including one of the following:
[0127] The step S1071, if the value of the first flag bit of the identification byte is a first value, the value of the highest bit in the first fourth-type byte is set to the first value, to obtain the first first-type byte;
[0128] Or,
[0129] The step S1072, if the value of the third flag bit of the identification byte is the first value, the value of the highest bit in the second fourth-type byte is set to the first value, to obtain the second first-type byte.
[0130] In some embodiments, the step S1071 can be regarded as the reverse process of the step S1021 in the above-mentioned embodiments. If the value of the first flag bit in the identification byte is the first value 1, it indicates that the highest bit of the first first-type byte is set from 1 to the second value 0 to obtain the first second-type byte during encoding. Here, the data of the first second-type byte is actually consistent with that of the first fourth-type byte. Therefore, the 0 in the fourth-type byte is modified to 1, to obtain the original first first-type byte.
[0131] Similarly, the step S1072 is the reverse process of the step S1023 in the above embodiment. If the third flag bit in the identification byte is the first value 1, it means that the highest bit of the first first-type byte is changed from 1 to 0 to obtain the second second-type byte. Here, the data of the second second-type byte is actually the same as that in the second fourth-type byte. Therefore, the 0 in the fourth-type byte is changed to 1, thereby obtaining the original second first-type byte.
[0132] In this way, the correct decoding is realized, and the original first-type byte is obtained.
[0133] The byte encoding algorithm is a very important algorithm in the network, and is usually used for encoding binary data in network transmission, and the encoded byte data is used for network transmission. The encoded data can be visualized in various software. The encoding algorithm can convert invisible and complex byte array data into displayable string data
[0134] Currently, the most commonly used byte encoding algorithm is the Hex algorithm, which divides 1 byte into high 4 bits and low 4 bits, and converts the two parts into two displayable character data respectively. However, the size of the data after Hex encoding is twice the original size, and the bandwidth occupied in network transmission is twice the original size, which greatly occupies the network bandwidth.
[0135] The present disclosure mainly optimizes the large encoded data, so as to make the encoded data smaller and facilitate data transmission.
[0136] The embodiment of the present disclosure proposes a dictionary mapping-based byte encoding algorithm to encode binary data in view of the problem of large encoded data in the current encoding algorithm. According to the algorithm, the size of the encoded data is greatly reduced, the bandwidth occupation in the network transmission process is reduced, the transmission efficiency is improved, and the data transmission is facilitated.
[0137] The core idea of the present disclosure is to establish a 64-bit mapping dictionary, and add 1 byte of encoding mark to each 2 bytes (16-bit binary) of data for encoding conversion. The encoding mark includes 3 placeholder marks, 1 display mark and 2 groups of encoding marks. The encoding mark is mainly used to indicate whether the highest bit in the two bytes is changed and whether the subsequent bits are mapped.
[0138] The technical effects of the present disclosure are as follows:
[0139] 1. Reduce the amount of encoded data, reduce resource occupation: according to the encoding algorithm proposed in the present disclosure, the original binary data is encoded, and the size of the encoded data is 1.5 times of the original data. Compared with the hex encoding algorithm, the amount of encoded data can be effectively reduced, the encoding efficiency can be improved, the data transmission amount in the data transmission process can be reduced, and the occupation of network, storage and other resources can be reduced.
[0140] 2. Improve the encoding efficiency: compared with the commonly used encoding algorithm, the encoding algorithm proposed in the present disclosure consumes less resources in the encoding process and has higher speed, thereby effectively improving the encoding efficiency.
[0141] The specific process of the encoding algorithm proposed in the present disclosure is as follows:
[0142] Encoding process:
[0143] Step S201, a byte encoding dictionary mapping table is constructed, as shown in the following table: Figure 2 Here, the byte encoding dictionary mapping table can be expressed by the encoding mapping table in the above embodiment.
[0144] Step S202, all binary data is split, and every two bytes of data is a group. One byte of encoding mark byte 01000000 is added before every 2 bytes of binary data. As shown in the following table: Figure 12 Here, the encoding mark byte can be expressed by the identification byte in the above embodiment.
[0145] From left to right, the 1st, 3rd and 4th bits of the encoding mark byte represent the placeholder, the 2nd bit represents the display mark, and the last 4 bits represent the encoding mark. The 5th and 6th bits are the encoding mark of the first byte of binary data, and the 7th and 8th bits represent the encoding mark of the second byte of binary data.
[0146] Step S203, the 2 bytes of binary data are respectively judged and processed, taking the first byte of binary data as an example:
[0147] 1) If the highest bit of the first byte is 1, the 5th bit of the encoding mark of the first byte is set to 1, and the highest bit of the first byte is set to 0. Here, the first byte can be expressed by the first first type byte in the above embodiment.
[0148] 2) If the first byte data after 1) is located in the byte encoding mapping table, the first byte data is replaced with the corresponding data in the byte encoding mapping table.
[0149] The binary data processing of the second byte is the same as that of the first byte, except that the encoding mark of the second byte is the last two bits in the encoding byte. Here, the second byte can be expressed by the second first type byte in the above embodiment.
[0150] Step S204, the result of the above encoding is as shown in Figure 13 .
[0151] Step S205, if there are multiple groups, the multiple groups of encoded results are spliced in order.
[0152] The decoding process is as follows:
[0153] Step S301, a byte decoding mapping table is constructed, as shown in Figure 4 .
[0154] Step S302, the encoded data is split, and each three bytes are a group, and each group of data is decoded;
[0155] Step S303, in each group of data, the first byte of data is an encoding marker byte, and the last two bytes are encoding data bytes, and the encoding marker byte and the encoding data byte are split first, as shown in Figure 14 .
[0156] Step S304, the encoding data byte is restored according to the encoding marker byte. Taking the first byte data in the encoding data as an example:
[0157] 1) If the 6th bit in the identification byte is 1, the first byte data is replaced using the corresponding value of the first byte data in the byte decoding mapping table.
[0158] 2) If the 5th bit in the identification byte is 1, the highest bit of the first byte data after 1) is set to 1;
[0159] The processing process of the second byte data is the same as that of the first byte, except that the encoding marker bit used is the last two bits in the encoding byte;
[0160] Step S305, the result of the above decoding is as shown in Figure 15 , which is consistent with the data in Figure 12 .
[0161] Step S306, if there are multiple groups, the multiple groups of decoded data are spliced in order.
[0162] In combination with Figure 16 , in the embodiment of the present disclosure, a character compiling device 400 is provided, and the device 400 comprises:
[0163] An acquisition module 401 is configured to acquire at least two first type bytes;
[0164] An updating and generating module 402 is configured to update the first type bytes to second type bytes according to the two first type bytes, and generate an identification byte.
[0165] The searching module 403 is configured to search, according to first type data in the n th second type byte as an index, a n th first type target character corresponding to the first type data in an encoding mapping table.
[0166] The first determining module 404 is configured to replace second type data corresponding to the n th first type target character into the n th second type byte to obtain an n th third type byte; wherein the first type data is different from the second type data.
[0167] In combination Figure 17 As shown in the figure, in the embodiment of the present disclosure, the device 400 further comprises:
[0168] The second determining module 405 is configured to determine whether to decode the third type byte by using a decoding mapping table according to the identification byte.
[0169] The third determining module 406 is configured to, if it is determined to decode the third type byte, obtain a fourth type byte according to the decoding mapping table and the third type byte.
[0170] The conversion module 407 is configured to convert the first type byte according to the identification byte and the fourth type byte.
[0171] In the embodiment of the present disclosure, the updating and generating module 402 is configured to:
[0172] If the highest bit in the first first type byte is a first value, the first mark of the identification byte is set to the first value, and the highest bit in the first first type byte is set to a second value to obtain a first second type byte.
[0173] If the first first type data in the first second type byte is the same as corresponding data in the encoding mapping table and corresponding first first type target character, the second mark of the identification byte is set to the first value.
[0174] In the embodiment of the present disclosure, the updating and generating module 402 is configured to:
[0175] If the highest bit in the second first type byte is the first value, the third mark of the identification byte is set to the first value, and the highest bit in the second first type byte is set to the second value to obtain a second second type byte.
[0176] If the second first type data in the second second type byte is the same as corresponding data in the encoding mapping table and corresponding second first type target character, the fourth mark of the identification byte is set to the first value.
[0177] In the embodiments of the present disclosure, the searching module 403 is at least configured to one of the following:
[0178] According to the first type data of the first second type byte as an index, the first first type target character corresponding to the first type data of the first second type byte is searched in the encoding mapping table;
[0179] Or,
[0180] According to the first type data of the second second type byte as an index, the second first type target character corresponding to the first type data of the second second type byte is searched in the encoding mapping table.
[0181] In the embodiments of the present disclosure, the first determining module 404 is at least configured to one of the following:
[0182] The second type data corresponding to the first first type target character is replaced into the first second type byte to obtain a first third type byte;
[0183] Or,
[0184] The second type data corresponding to the second first type target character is replaced into the second second type byte to obtain a second third type byte.
[0185] In the embodiments of the present disclosure, the second determining module 405 is at least configured to one of the following:
[0186] If the data of the second mark bit of the identification byte is the first value, it is determined to decode the first third type byte through the decoding mapping table;
[0187] Or,
[0188] If the data of the fourth mark bit of the identification byte is the first value, it is determined to decode the second third type byte through the decoding mapping table.
[0189] In the embodiments of the present disclosure, the third determining module 406 is at least configured to one of the following:
[0190] If it is determined to decode the first third type byte, the first first type target character corresponding to the first second type data of the first third type byte is taken as an index to search the decoding mapping table to find the first first type data corresponding to the first first type target character;
[0191] The first first type data is replaced with the first second type data of the first third type byte to obtain a first fourth type byte;
[0192] Or,
[0193] If it is determined to decode the second third-type byte, a second first-type target character corresponding to second second-type data of the second third-type byte is taken as an index to search the decoding mapping table for second first-type data corresponding to the second first-type target character;
[0194] The second first-type data is substituted for the second second-type data of the second third-type byte to obtain a second fourth-type byte.
[0195] In the embodiments of the present disclosure, the conversion module 407 is at least configured as one of the following:
[0196] If the value of the first flag bit of the identification byte is a first value, the value of the highest bit in the first fourth-type byte is set to the first value to obtain the first first-type byte.
[0197] Or,
[0198] If the value of the third flag bit of the identification byte is the first value, the value of the highest bit in the second fourth-type byte is set to the first value to obtain the second first-type byte.
[0199] The embodiments of the present disclosure provide an electronic device, comprising:
[0200] a memory for storing processor-executable instructions;
[0201] a processor connected with the memory;
[0202] The processor is configured to execute the character encoding method provided in any of the preceding technical solutions.
[0203] The processor can include various types of storage media, which is a non-transitory computer storage medium, and can continue to store information on it after the electronic device is powered off.
[0204] The processor can be connected with the memory through a bus or the like, for reading the executable program stored on the memory, for example, to execute the method described in one or more of the preceding technical solutions.
[0205] An embodiment of the present disclosure provides a structure of an electronic device. The electronic device includes a processing component, which further includes one or more processors, and a memory resource represented by a memory, for storing instructions executable by the processing component, such as an application program. The application program stored in the memory can include one or more than one module each corresponding to a set of instructions. In addition, the processing component is configured to execute the instructions to perform any of the above methods applied to the electronic device, for example, the method described in one or more of the preceding technical solutions.
[0206] The electronic device can further include a power component configured to perform power management of the electronic device, a wired or wireless network interface configured to connect the electronic device to a network, and an input / output (I / O) interface. The electronic device can operate based on an operating system stored in the memory, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.
[0207] The embodiment of the present disclosure provides a non-transitory computer readable storage medium, when instructions in the storage medium are executed by a processor of a computer, the computer can execute the character compiling method of the foregoing one or more technical solutions.
[0208] Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the description hereof in light of the disclosure herein. The disclosure is intended to cover any alternatives, modifications, and equivalents of the specific embodiments of the disclosure to follow in the spirit and scope of the present disclosure as defined by the appended claims. The specification and drawings are, accordingly, to be regarded as illustrative rather than restrictive.
[0209] It should be understood that the present disclosure is not limited to the precise structures herein described and illustrated in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the claims appended hereto.
Claims
1. A character encoding method, characterized by, The method comprises: obtaining at least two first type bytes; updating the first type bytes to second type bytes and generating an identification byte according to the two first type bytes; finding an nth first type target character corresponding to first type data in the nth second type byte in an encoding mapping table according to the first type data as an index; replacing second type data corresponding to the nth first type target character into the nth second type byte to obtain an nth third type byte according to a corresponding relationship in an American Standard Code for Information Interchange (ASCII) table; wherein the encoding mapping table is different from the corresponding relationship between data and characters in the ASCII table, and the first type data is different from the second type data; The method further comprises: determining whether to decode the third type bytes through a decoding mapping table according to the identification byte; if it is determined to decode the third type bytes, obtaining fourth type bytes according to the decoding mapping table and the third type bytes; converting to obtain the first type bytes according to the identification byte and the fourth type bytes; updating the first type bytes to second type bytes and generating an identification byte according to the two first type bytes, comprising: if the highest bit in the first first type byte is a first value, setting a first marker position of the identification byte to the first value; and setting the highest bit in the first first type byte to a second value to obtain a first second type byte; if the first first type data in the first second type byte has corresponding same data and a corresponding first first type target character in the encoding mapping table, setting a second marker position of the identification byte to the first value; if the highest bit in the second first type byte is the first value, setting a third marker position of the identification byte to the first value; and setting the highest bit in the second first type byte to the second value to obtain a second second type byte; if the second first type data in the second second type byte has corresponding same data and a corresponding second first type target character in the encoding mapping table, setting a fourth marker position of the identification byte to the first value.
2. The character encoding method of claim 1, wherein, The finding of the nth first type target character corresponding to the first type data in the nth second type byte in the encoding mapping table according to the first type data as an index comprises one of: finding a first first type target character corresponding to the first type data of the first second type byte in the encoding mapping table according to the first type data of the first second type byte as an index; or finding a second first type target character corresponding to the first type data of the second second type byte in the encoding mapping table according to the first type data of the second second type byte as an index.
3. The character encoding method of claim 1, wherein, The replacing of binary data corresponding to the nth first type target character into the nth second type byte to obtain the nth third type byte comprises at least one of: replacing second type data corresponding to the first first type target character into the first second type byte to obtain a first third type byte; or Replacing the second type of data corresponding to the second first type target character into the second second type byte to obtain a second third type byte.
4. The character encoding method of claim 1, wherein, The determining whether to decode the third type byte through a decoding mapping table according to the identification byte at least includes one of the following: If the data of the second flag bit of the identification byte is a first value, it is determined that the first third type byte is decoded through the decoding mapping table. Or, If the data of the fourth flag bit of the identification byte is a first value, it is determined that the second third type byte is decoded through the decoding mapping table.
5. The character compilation method of claim 1, wherein, If it is determined that the third type byte is decoded, the fourth type byte is obtained according to the decoding mapping table and the third type byte, and at least one of the following is included: If it is determined that the first third type byte is decoded, a first first type target character corresponding to the first second type data of the first third type byte is taken as an index to search the decoding mapping table to find a first first type data corresponding to the first first type target character; The first first type data is replaced with the first second type data of the first third type byte to obtain a first fourth type byte. Or, If it is determined that the second third type byte is decoded, a second first type target character corresponding to the second second type data of the second third type byte is taken as an index to search the decoding mapping table to find a second first type data corresponding to the second first type target character; The second first type data is replaced with the second second type data of the second third type byte to obtain a second fourth type byte.
6. The character compilation method of claim 1, wherein, The conversion to obtain the first type byte according to the identification byte and the fourth type byte at least includes one of the following: If the value of the first flag bit of the identification byte is a first value, the value of the highest bit in the first fourth type byte is set to a first value to obtain a first first type byte. Or, If the value of the third flag of the identification byte is a first value, the value of the highest bit in the second fourth type byte is set to a first value to obtain a second first type byte.
7. A character compiling apparatus characterized by comprising: The device comprises: An acquisition module is configured to acquire at least two first type bytes; An updating and generating module is configured to update the first type byte to a second type byte and generate an identification byte according to the two first type bytes; A searching module is configured to search an encoding mapping table to find an nth first type target character corresponding to first type data in an nth second type byte according to the first type data as an index; A first determining module is configured to replace second type data corresponding to the nth first type target character into the nth second type byte to obtain an nth third type byte according to a corresponding relationship in an American Standard Code for Information Interchange (ASCII) table; wherein the encoding mapping table is different from the corresponding relationship between data and characters in the ASCII table, and the first type data is different from the second type data; A second determining module is configured to determine whether to decode the third type byte through a decoding mapping table according to the identification byte. a third determining module, configured to, if it is determined to decode the third type of byte, obtain a fourth type of byte according to the decoding mapping table and the third type of byte; a converting module, configured to convert the first type of byte according to the identification byte and the fourth type of byte; wherein the updating and generating module is configured to: if the highest bit of the first first type of byte is a first value, set a first flag position of the identification byte to the first value, and set the highest bit of the first first type of byte to a second value to obtain a first second type of byte; if the first first type of data in the first second type of byte is the same as corresponding data in the encoding mapping table and corresponds to a first first type of target character, set a second flag position of the identification byte to the first value; if the highest bit of the second first type of byte is the first value, set a third flag position of the identification byte to the first value, and set the highest bit of the second first type of byte to the second value to obtain a second second type of byte; if the second first type of data in the second second type of byte is the same as corresponding data in the encoding mapping table and corresponds to a second first type of target character, set a fourth flag position of the identification byte to the first value.
8. The character compiling apparatus according to claim 7, wherein the searching module is at least configured as one of: searching for the first first type of target character corresponding to the first first type of data of the first second type of byte in the encoding mapping table according to the first first type of data of the first second type of byte as an index; or searching for the second first type of target character corresponding to the first first type of data of the second second type of byte in the encoding mapping table according to the first first type of data of the second second type of byte as an index.
9. The character compiling apparatus according to claim 7, wherein the first determining module is at least configured as one of: replacing the second type of data corresponding to the first first type of target character into the first second type of byte to obtain a first third type of byte; or replacing the second type of data corresponding to the second first type of target character into the second second type of byte to obtain a second third type of byte.
10. The character compiling apparatus according to claim 7, wherein the second determining module is at least configured as one of: if the data of the second flag position of the identification byte is the first value, determining to decode the first third type of byte through the decoding mapping table; or if the data of the fourth flag position of the identification byte is the first value, determining to decode the second third type of byte through the decoding mapping table.
11. The character compiling apparatus according to claim 7, wherein the third determining module is at least configured as one of: if it is determined to decode the first third type of byte, taking the first first type of target character corresponding to the first second type of data of the first third type of byte as an index to search for the first first type of data corresponding to the first first type of target character in the decoding mapping table; replacing the first first type of data in the first third type of byte with the first second type of data to obtain a first fourth type of byte; or If it is determined to decode the second third-type byte, a second first-type target character corresponding to second second-type data of the second third-type byte is taken as an index to search the decoding mapping table to find second first-type data corresponding to the second first-type target character; The second first-type data is substituted for the second second-type data of the second third-type byte to obtain a second fourth-type byte.
12. The character compiling apparatus according to claim 7, characterized by, The conversion module is configured to at least one of the following: If the first flag bit of the identification byte is the first value, the value of the highest bit in the first fourth-type byte is set to the first value to obtain the first first-type byte; Or, If the third flag bit of the identification byte is the first value, the value of the highest bit in the second fourth-type byte is set to the first value to obtain the second first-type byte.
13. An electronic device, comprising: The method comprises: a memory for storing processor-executable instructions; a processor connected with the memory; wherein the processor is configured to execute the character encoding method provided in any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium, comprising: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by the processor to implement the character encoding method provided in any one of claims 1 to 6.
Citation Information
Patent Citations
Coding and decoding method and device in cloud desktop scene, electronic equipment and storage medium
CN114286094A