Text coding and decoding method and related equipment

By introducing underflow boundaries and continuous modulo operations into the text encoding method, the problems of poor flexibility and low efficiency of existing text encoding schemes are solved, and a wide range of applicable and efficient text encoding effect is achieved.

CN119026571APending Publication Date: 2024-11-26HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310595969.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-24
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Existing text encoding schemes are inflexible, unable to adapt to different base values, and have low encoding efficiency, failing to approach optimal encoding efficiency.

Method used

By combining underflow boundary and continuous modulo operation, a text encoding method applicable to different base values ​​is designed to determine the current encoding state value and printable characters, achieving a highly flexible and widely applicable text encoding.

Benefits of technology

It enables text encoding with different base values ​​according to actual needs, with encoding efficiency approaching the optimal encoding efficiency and improving resource utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119026571A_ABST
    Figure CN119026571A_ABST
Patent Text Reader

Abstract

The invention discloses a text encoding and decoding method and related equipment. The text encoding method comprises the following steps: determining a current encoding state value and an encoding underflow boundary according to a base value; determining printable characters corresponding to the plurality of character strings based on the current coding state value, the coding underflow boundary and the base value, wherein a plurality of character strings in the plurality of character strings have no length limitation; and determining an encoding result of the to-be-encoded binary data based on the plurality of printable characters. According to the method, the coding underflow boundary and the continuous modulo operation are combined, text coding corresponding to different base values can be carried out on binary data according to actual requirements, the text coding effect with high flexibility and wide application range is achieved, the coding underflow boundary is reasonably determined based on the determined base value, and the coding underflow boundary is more accurate. The coding efficiency of the method can approach to the optimal coding efficiency corresponding to the determined base value, so that the subsequent use of fewer resources to carry or transmit the coding result becomes possible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a text encoding and decoding method and related equipment. Background Art

[0002] In many data transmission scenarios, because the transmission channel or medium does not support binary data, the transmission protocol requires that the binary data to be transmitted be processed and converted into printable characters supported by the transmission channel and medium for data carrying and transmission. The process of converting binary data into printable characters is called text encoding, and printable characters are the text in "text encoding".

[0003] At present, all text encodings are based on fixed base value encoding schemes. For example, Base45 is a text encoding scheme with a base value of 45. The encoding principle of Base45 is: divide the input binary data into blocks according to the length of two bytes, and for each block, perform continuous division with the divisor being 45 and take the remainder operation to obtain three remainders between 0 and 44, and map the three remainders between 0 and 44 to one of the 45 printable characters as the output of the block based on the Base45 text encoding scheme.

[0004] It can be seen that different text encoding schemes need to be designed for text encoding requirements with different base values, which has poor flexibility. Summary of the invention

[0005] Based on this, the present application provides a text encoding and decoding method and related equipment, which are suitable for various base values ​​and can perform text encoding corresponding to different base values ​​on binary data according to actual needs, thereby achieving a text encoding effect with strong flexibility and a wide range of applicability.

[0006] In the first aspect, the present application provides a text encoding method, which is applied to a communication device having a function corresponding to the text encoding method provided by the present application. In the text encoding method, the communication device first determines a first current encoding state value and a first encoding underflow boundary according to a first base value, wherein the first base value is determined from a plurality of base values, and the first encoding underflow boundary is the minimum value of the first current encoding state value allowed; then, the communication device can determine the first printable characters corresponding to a plurality of first character strings based on the first current encoding state value, the first encoding underflow boundary and the first base value, and the "plurality" in the "plurality of first character strings" has no length limit. As an example, the communication device can determine the first printable characters corresponding to the first character strings based on the first current encoding state value, the first encoding underflow boundary and the first base value, which can include: if the first current encoding state value is less than the first encoding underflow boundary, the communication device reads the first character string of the first encoding length to be encoded in the first binary data, and updates the first current encoding state value based on the first character string; if the first current encoding state value is greater than or equal to the first encoding underflow boundary, the communication device determines the first printable character based on the first current encoding state value and the first base value, and updates the first current encoding state value based on the first base value; thus, the communication device determines the encoding result of the first binary data based on the multiple first printable characters. It can be seen that in this method, by combining the encoding underflow boundary and the continuous modulus operation, the text encoding corresponding to different base values ​​can be performed on the binary data according to actual needs, so as to achieve a text encoding effect with strong flexibility and wide application range, and the encoding underflow boundary is reasonably determined based on the determined base value, so that the encoding efficiency of the text encoding method can approach the optimal encoding efficiency corresponding to the determined base value, so that it is possible to carry or transmit the encoding result with less resources in the subsequent use.

[0007] In one possible implementation, determining the first current coding state value and the first coding underflow boundary based on the first base value may include: determining the first current coding state value and the first coding underflow boundary based on the first base value, the first coding length and the first state value length, the first state value length indicating the length of the first current coding state value.

[0008] In a possible implementation, the method may further include: first, according to the second encoding length, the second base value and the second state value length, determining the second current encoding state value and the second encoding underflow boundary, the second encoding underflow boundary being the minimum value of the second current encoding state value allowed, and the second base value being determined from the plurality of base values; then, if the second current encoding state value is less than the second encoding underflow boundary, reading the second character string of the second encoding length to be encoded in the second binary data, and updating the second current encoding state value based on the second character string; if the second current encoding state value is greater than or equal to the second encoding underflow boundary, determining the second printable character based on the second current encoding state value and the second base value, and updating the second current encoding state value based on the second base value; and determining the encoding result of the second binary data based on the plurality of second printable characters. It can be seen that the text encoding method provided by the present application is introduced by taking the first base value and the second base value as examples, in order to illustrate that the text encoding method provided by the present application can be applied to any base value, that is, the present application can implement flexible text encoding.

[0009] In a possible implementation, updating the first current encoding state value based on the first character string may include: shifting the current first encoding state value to the left by the first encoding length and performing an OR operation with the first character string to obtain the updated first current encoding state value. In this way, when the first current encoding state value is subsequently subjected to text encoding, since the first current encoding state value includes the first character string in the first binary data, partial text encoding of the first binary data is implemented.

[0010] In one possible implementation, determining the first printable character based on the first current encoding state value and the first basis value may include: first, calculating the first current encoding state value divided by the first basis value to obtain a remainder; then, determining the first printable character according to a coding mapping table corresponding to the remainder and the first basis value, the coding mapping table including the first basis value correspondence between numerical values ​​and printable characters, the numerical values ​​being non-negative integers less than the first basis value.

[0011] In one possible implementation, updating the first current coding state value based on the first basis value may include: first, calculating the first current coding state value divided by the first basis value to obtain a quotient; then, based on the quotient, obtaining an updated first current coding state value, for example, the quotient may be rounded down to obtain an updated first current coding state value.

[0012] In a possible implementation, when there is no data to be encoded in the first binary data, in order to accurately decode the encoding result later, the method may also include processing the first current encoding state value. As an example, the processing of the first current encoding state value when there is no data to be encoded in the first binary data may include: if there is no data to be encoded in the first binary data to be encoded, determining the third printable character based on the first current encoding state value and the first base value, and updating the first current encoding state value based on the first base value. Wherein, the encoding result may also include a plurality of the third printable characters and the number of the third printable characters. For example, with the first base value as the dividend, the first current encoding state value is continuously divided and remaindered until the first current encoding state value is 0, and after each division and remainder operation, at least one third printable character is determined based on the remainder and the encoding mapping table corresponding to the first base value, and the quotient is used as the updated first current encoding state value, and the updated first current encoding state value is used as the divisor for the next division and remainder operation. In this way, the third printable character and the number of the third printable characters are added to the encoding result, which is convenient for subsequent effective decoding.

[0013] In a possible implementation, the printable characters in the encoding result of the text encoding can be stored in a storage form with the characteristics of "first in, last out", for example, a stack structure can be used to store the printable characters in the encoding result. In this way, the order of encoding and decoding can be reversed, ensuring that the binary data before encoding and after decoding are consistent, that is, accurate encoding and decoding is achieved.

[0014] In a possible implementation, the method may further include a decoding process for the encoding result, and the decoding process may include: determining a first current decoding state value based on the encoding result, and determining a first decoding overflow boundary based on the first encoding length, the first base value and the first state value length, the first decoding overflow boundary being the minimum value of the first current decoding state value allowed; reading the first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and the third character string corresponding to the first printable character; if the first current decoding state value is greater than or equal to the first decoding overflow boundary, taking the character of the first encoding length at the end of the first current decoding state value as the first decoding character, and updating the first current decoding state value based on the first encoding length; if the first current decoding state value is less than the first decoding overflow boundary, reading the next first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and the third character string corresponding to the first printable character; determining the first binary data according to multiple first decoding characters. In this way, based on the method, accurate and flexible encoding and decoding of binary data can be achieved, making the carrying and transmission of binary data more convenient and reliable. For a detailed description of the decoding process, please refer to the relevant description of the second aspect below.

[0015] In one implementation, the encoding result can be used for Quick Response (QR) codes, Lightning Network (LN) protocols, Internet Protocol version 6 (IPv6) addresses, and files in many formats (such as Portable Document Format (PDF)).

[0016] In a second aspect, the present application also provides a decoding method, which is applied to a communication device having functions corresponding to the decoding method provided by the present application. In the decoding method, the communication device can first determine the current decoding state value based on the printable character string to be decoded, and determine the decoding overflow boundary based on the encoding length, the base value and the state value length, wherein the base value is determined from multiple base values ​​during encoding, the state value length indicates the length of the current encoding state value during encoding, and the decoding overflow boundary is the minimum value of the current decoding state value allowed; then, the communication device reads the first printable character at the end of the printable character string, and updates the current decoding state value according to the base value and the first character string corresponding to the first printable character; then, if the current decoding state value is greater than or equal to the decoding overflow boundary, the communication device uses the character of the encoding length at the end of the current decoding state value as the decoding character, and updates the current decoding state value based on the encoding length; if the current decoding state value is less than the decoding overflow boundary, the communication device reads the next first printable character to be decoded in the printable character string, and updates the current decoding state value according to the base value and the first character string corresponding to the first printable character; finally, the communication device determines the binary data corresponding to the printable character string according to the multiple decoding characters. In this way, by designing a text decoding process corresponding to the text encoding method provided in this application, it is possible to accurately decode the text obtained by the text encoding in this application, making it possible to promote and apply the text encoding method provided in this application.

[0017] In a possible implementation, the determining of the current decoding state value based on the printable character string to be decoded may include: first, obtaining a second printable character from the printable character string, the second printable character is used to indicate the number of third printable characters in the printable character string, the third printable character is a printable character determined based on the current encoding state value and the base value when there is no data to be encoded in the binary data corresponding to the printable character string; then, obtaining a plurality of the third printable characters in the printable character string based on the second printable character; and then, determining the current decoding state value based on the second character string corresponding to the plurality of the third printable characters. In this way, by determining the current decoding state value from the printable character string to be decoded, preparations are made for accurately decoding the text based on the method provided by the present application.

[0018] In a possible implementation, updating the current decoding state value according to the base value and the first character string corresponding to the first printable character may include: calculating the product of the base value and the current decoding state value; calculating the sum of the product and the first character string to obtain the updated current decoding state value. In this way, the state value to be decoded in a decoding process is realized, making it possible to accurately decode the text obtained by the text encoding provided by the present application.

[0019] In a possible implementation, updating the current decoding state value based on the code length may include: shifting the current decoding state value rightward by the code length to obtain the updated current decoding state value. Thus, after each decoding operation in the decoding process is completed, the current decoding state value is updated in this implementation to prepare for the execution of the next decoding operation.

[0020] In a third aspect, the present application provides a communication device, which includes a processing unit, and the processing unit is used to implement methods corresponding to the first aspect, the second aspect and possible implementation methods thereof.

[0021] In a fourth aspect, the present application provides a communication device, comprising a processor and a memory; the processor is used to execute instructions stored in the memory so that the communication device implements methods corresponding to the first aspect, the second aspect and possible implementation methods thereof.

[0022] In a fifth aspect, the present application further provides a storage medium, wherein the storage medium stores instructions, and when the instructions are executed on a processor, methods corresponding to the first aspect, the second aspect and possible implementations thereof are implemented.

[0023] In a sixth aspect, the present application further provides a program product, which includes a program, and when the program runs on a processor, implements the methods corresponding to the first aspect, the second aspect and their possible implementation methods.

[0024] In the seventh aspect, the present application provides a chip including a memory and a processor, the memory being used to store instructions, and the processor being used to call and execute the instructions from the memory to implement the methods corresponding to the first aspect, the second aspect and their possible implementation methods.

[0025] In an eighth aspect, the present application further provides a communication system, the communication system comprising a first communication device and a second communication device. The first communication device is used to implement the method corresponding to the first aspect and its possible implementation; the second communication device is used to implement the method corresponding to the second aspect and its possible implementation. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0027] Figure 1 A flowchart of a text encoding method 100 in an embodiment of the present application;

[0028] Figure 2 A schematic diagram of an application of text encoding in an embodiment of the present application;

[0029] Figure 3 A flowchart of a text decoding method 200 in an embodiment of the present application;

[0030] Figure 4 This is a schematic diagram of the structure of a communication device 400 in an embodiment of the present application;

[0031] Figure 5 This is a schematic diagram of the structure of a communication device 500 in an embodiment of the present application;

[0032] Figure 6 This is a schematic diagram of the structure of a communication device 600 in an embodiment of the present application;

[0033] Figure 7 Schematic diagram of the structure of a communication system 700 in an embodiment of the present application. DETAILED DESCRIPTION

[0034] For Quick Response (QR) codes, Lightning Network (LN) protocols, Internet Protocol version 6 (IPv6) addresses, and files in many formats (such as Portable Document Format (PDF)), binary data cannot be carried or transmitted. The binary data must first be text-encoded to obtain text composed of printable characters, which can then be carried or transmitted.

[0035] At present, the basic principle of the text encoding scheme can be summarized as follows: after the binary data to be encoded is divided into blocks, each block is continuously divided and modulo operations are performed with a fixed base value as the divisor to obtain a number of remainders between 0 and the fixed base value, and each remainder is respectively mapped to one of the printable characters of the fixed base value as the output of the text encoding scheme of the block based on the fixed base value. For example, the base value of Base45 is 45, and the binary data 1 to be encoded can be represented as a1, a2 and a3 after being divided into blocks. A1, a2 and a3 are divided by 45 and modulo, and the remainders obtained are, for example, {27, 33}, {20, 33} and {40}, respectively. Based on the Base45 encoding mapping table 1, it can be determined that the printable characters corresponding to each remainder are {b1, b2}, {b3, b2} and {b4}, respectively. Then, the text obtained after the binary data 1 to be encoded is encoded based on Base45 can be represented as {b1, b2, b3, b2, b4}. The encoding mapping table 1 may include the correspondence between numbers between 0 and 44 and 45 printable characters. In the encoding mapping table 1, 27 corresponds to the printable character b1, 33 corresponds to the printable character b2, 20 corresponds to the printable character b3, and 40 corresponds to the printable character b4. For another example, the base value of Base58 is 58. The binary data 1 to be encoded can be represented as a4 and a5 after being divided into blocks. The remainders obtained by dividing a4 and a5 by 58 are, for example, {27, 33, 20} and {40, 60}. The encoding mapping table 2 based on Base58 can determine that the printable characters corresponding to each remainder are {c1, c2, c3} and {c4, c5}, respectively. Then, the text obtained after the binary data 1 to be encoded is encoded based on Base58 can be represented as {c1, c2, c3, c4, c5}. The encoding mapping table 2 may include the correspondence between numbers between 0 and 57 and 58 printable characters. In the encoding mapping table 2, 27 corresponds to printable character c1, 33 corresponds to printable character c2, 20 corresponds to printable character c3, 40 corresponds to printable character c4, and 60 corresponds to printable character c5. It can be seen that the current text encoding scheme has poor flexibility. Each text encoding scheme only designs an encoding process for a fixed base value. When there is a need for text encoding of other base values, the existing text encoding scheme cannot be directly applied, and a new text encoding scheme needs to be designed specifically.

[0036] In addition, the coding efficiency of a text coding scheme is also an important indicator for measuring text coding schemes. Coding efficiency refers to the ratio of the length of the binary data before encoding to the length of the encoded text. At present, the optimal coding efficiency of the text coding scheme corresponding to each basis value can be calculated. For example, the length of the binary data to be encoded is n bytes, and the binary data to be encoded has (2^8) n =256 nThe binary data to be encoded is encoded by a text encoding scheme with a base value of X. Assuming that the optimal length of the text is m bytes, then 256 n =X m , the best coding efficiency can be equal to (n / m). Taking Base45 (i.e. X=45)0 as an example, its best coding efficiency is determined to be 68.65% through calculation, but because 45 is not an integer power of 2, the actual coding efficiency of text encoding using Base45 can only reach 66.67% and cannot approach the best coding efficiency of 68.65%. It can be seen that the current coding scheme whose base value is not an integer power of 2 has a low coding efficiency and cannot achieve the theoretical best coding efficiency.

[0037] Based on this, the embodiment of the present application provides a text encoding method, which can be flexibly applied to text encoding under different base values, overcomes the shortcomings of designing corresponding text encoding schemes for different base values, and for each base value, the text encoding can approach the optimal encoding efficiency of the base value. The method provided by the embodiment of the present application, for example, may include: first, based on a first base value determined from a plurality of base values, determining a first current encoding state value and a first encoding underflow boundary, the first encoding underflow boundary being the minimum value of the first current encoding state value allowed; then, judging whether the first current encoding state value is less than the first encoding underflow boundary, if so, reading a first character string of a first encoding length to be encoded in the first binary data to be encoded, and updating the first current encoding state value based on the first character string, if not (that is, the first current encoding state value is greater than or equal to the first encoding underflow boundary), determining a first printable character based on the first current encoding state value and the first base value, and updating the first current encoding state value based on the first base value; then, determining the encoding result of the first binary data based on the plurality of first printable characters. In this way, by combining the coding underflow boundary and continuous modulo operation, text encoding corresponding to different base values ​​can be performed on binary data according to actual needs, thereby achieving a text encoding effect with strong flexibility and a wide range of applicability. Moreover, the coding underflow boundary is reasonably determined based on the determined base value, so that the coding efficiency of the text encoding method can approach the optimal coding efficiency corresponding to the determined base value, making it possible to carry or transmit the encoding results using fewer resources subsequently.

[0038] Correspondingly, an embodiment of the present application also provides a text decoding method, which may include, for example: first, determining a current decoding state value based on a printable character string to be decoded, and determining a decoding overflow boundary based on a coding length, a base value, and a state value length, wherein the base value is determined from a plurality of base values ​​during encoding, the state value length indicates the length of the current coding state value during encoding, and the decoding overflow boundary is the minimum value of the current decoding state value allowed; then, reading the first printable character at the end of the printable character string, and updating the current decoding state value according to the base value and the first character string corresponding to the first printable character; then, determining whether the current decoding state value is greater than or equal to the decoding overflow boundary, if so, taking the character of the last coding length in the current decoding state value as the decoding character, and updating the current decoding state value based on the coding length, if not (i.e., the current decoding state value is less than the decoding overflow boundary), reading the next first printable character to be decoded in the printable character string, and updating the current decoding state value according to the base value and the first character string corresponding to the first printable character; in this way, according to the obtained multiple decoding characters, determining the binary data corresponding to the printable character string to be decoded. In this way, by designing a text decoding process corresponding to the text encoding method provided in the embodiment of the present application, it is possible to accurately decode the text obtained by the text encoding in the embodiment of the present application, making it possible to promote and apply the text encoding method provided in the embodiment of the present application.

[0039] It should be noted that the communication device that implements the text encoding method or text decoding method provided in the embodiment of the present application may be any communication device with text encoding or text decoding requirements, for example, the communication device may be a network device, a controller, a server or a cloud. In one case, the communication device is integrated with a functional module corresponding to the text encoding method or text decoding method in the embodiment of the present application, and the network device may include but is not limited to a switch, a router or a firewall; in another case, a third-party device such as a controller, a cloud or a server has a program product corresponding to the text encoding method or text decoding method in the embodiment of the present application, and the communication device can download and use the program product corresponding to the text encoding method from the third-party device when there is a text encoding requirement, and the communication device can download and use the program product corresponding to the text decoding method from the third-party device when there is a text decoding requirement.

[0040] The text encoding method and text decoding method provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0041] Figure 1 1 shows a flow chart of a text encoding method 100 provided in an embodiment of the present application. In the method 100, the text encoding corresponding to the first base value of the first binary data is taken as an example to illustrate the text encoding method provided in the embodiment of the present application. Figure 1 As shown, the method 100 may include, for example, the following S101 to S105:

[0042] S101, determining a first current coding state value and a first coding underflow boundary according to a first base value, wherein the first base value is determined from a plurality of base values, and the first coding underflow boundary is a minimum value allowed for the first current coding state value.

[0043] The first base value can be understood as any one of the multiple base values ​​applicable to the text encoding method provided in the embodiment of the present application. The first base value can refer to the total number of different printable characters that may appear in the encoding result of the text encoding. For example, if the first base value is 45, then at most 45 different printable characters appear in the encoding result in S105; for another example, if the first base value is 100, then at most 100 different printable characters appear in the encoding result in S105.

[0044] Before S101 , the method 100 may further include: determining a first base value.

[0045] As an example, determining the first base value may include: determining the first base value in response to a user's selection operation from a plurality of base values. In this example, the communication device may provide the plurality of base values ​​to the user through an interactive interface, and the user obtains the first base value in S101 by selecting the first base value on the interactive interface.

[0046] As another example, determining the first base value may include: obtaining the first base value in response to an input operation of the user. In this example, the communication device may provide the user with an input box for the base value through an interactive interface, and the user obtains the first base value in S101 by inputting the first base value in the input box for the base value on the interactive interface.

[0047] As another example, determining the first base value may include: determining the first base value in response to the user's selection operation and input operation. In this example, the communication device may provide the user with multiple base values ​​and a "custom" option through an interactive interface. If the user does not find the base value of the next text encoding among the multiple base values ​​provided by the interactive interface, then "custom" may be selected on the interactive interface, and the interactive interface may jump to the page including the input box of the base value, so that the user can obtain the first base value in S101 by entering the first base value in the input box of the base value on the interactive interface. Among them, among the options of the base values ​​provided by the interactive interface, the name of the option that can trigger the jump to the page including the input box of the base value may be "custom", "other", etc., which is not limited in the embodiments of the present application.

[0048] It should be noted that if the user is not sure about the first base value, the communication device may also use a default base value as the first base value, or randomly determine the first base value.

[0049] In some implementations, S101 may include, for example: determining a first current coding state value and a first coding underflow boundary according to a first base value, a first coding length, and a first state value length, wherein the first current coding state value may be greater than or equal to the first coding underflow boundary. The first coding length may refer to the number of bits read at a time when encoding binary data to be encoded, for example, 1 byte (i.e., 8 bits) of binary data is read each time for encoding, and / or then, the first coding length may be equal to 8; for another example, 12 bits of binary data are read each time for encoding, then, the first coding length may be equal to 12. The first state value length indicates the length of the first current coding state value, for example, the first state value length may be equal to 32, then, the first state value length may indicate that the first current coding state value is 32 bits of data.

[0050] The method for determining the first code length and the first state value length can refer to the example of the above-mentioned method for determining the first base value. Alternatively, if the user is not sure about the first code length, the default value or random value can be used as the first code length. Similarly, if the user is not sure about the first state value length, the default value or random value can be used as the first state value length. For example, the default value of the first state value length can be 32, and the default value of the first code length can be 8.

[0051] As an example, S101 may include: S101a, determining a first current coding state value according to a first coding length and a first state value length, S101b, determining a first coding underflow boundary according to a first base value, a first coding length and a first state value length. Assuming that the first base value is b, the first coding length is d, and the first state value length is n, then S101a may include: determining the first current coding state value state based on the following formula (1):

[0052] state=2 (n-d) ...Formula (1)

[0053] Wherein, S101b may include: determining a first encoding underflow boundary enc_lower_bound based on the following formula (2):

[0054]

[0055] Wherein, floor() is a floor rounding function, for example, floor(1.8)=1.

[0056] It should be noted that there is no order limit for executing S101a and S101b. S101b may be executed first to determine the first coding underflow boundary, and then based on S101a, a first current coding state value greater than or equal to the first coding underflow boundary may be determined.

[0057] It should be noted that S101 can be understood as a step to be performed in the initialization phase of the method 100, and the first current encoding state value in S101 can be understood as an initial encoding state value.

[0058] As an example, S101 may be executed only once. After S101, the correspondence between the first base value, the first current encoding state value and the first encoding underflow boundary may be saved. In this way, each subsequent time the text is encoded with the first base value, the first current encoding state value and the first encoding underflow boundary may be obtained directly based on the saved correspondence between the first base value, the first current encoding state value and the first encoding underflow boundary. There is no need to execute S101 each time, thereby saving the computing resources required for the text encoding process. In this example, the execution timing of S101 may be: when the need to encode text with the first base value first appears, then the first current encoding state value and the first encoding underflow boundary corresponding to the first base value may be determined based on S101; or, the execution timing of S101 may be: when the need to encode text with the first base value has not yet appeared, then not only the first current encoding state value and the first encoding underflow boundary corresponding to the first base value may be determined based on S101, but also the current encoding state values ​​and encoding underflow boundaries corresponding to various possible base values ​​may be determined based on the same implementation method of S101, so as to prepare for text encoding needs corresponding to other base values.

[0059] As another example, S101 can be executed once each time the text is encoded with the first base value, so that there is no need to maintain the correspondence between the first base value, the first current encoding state value, and the first encoding underflow boundary in the communication device that executes method 100, thereby saving storage resources occupied during the text encoding process. In this example, the execution timing of S101 can be: each time there is a need to encode the text with the first base value, then, based on S101, the first current encoding state value and the first encoding underflow boundary corresponding to the first base value can be determined.

[0060] S102, determine whether the first current coding state value is less than the first coding underflow boundary, if yes, execute S103 to S104, otherwise, execute S104.

[0061] The first current coding state value is less than the first coding underflow boundary, which can be used as the reading condition for the first string of the first coding length to be coded in the first binary data in S103. Only when this reading condition is met, the first binary data will be read and coded sequentially. When this reading condition is not met, S104 can be directly executed to perform text coding on the first current coding state value corresponding to the first base value.

[0062] As an example, the initial coding state value (i.e., the first current coding state value determined by S101) is greater than or equal to the first coding underflow boundary, that is, when S102 is first executed, the judgment result is "no". Next, each time the first current coding state value is updated in S104, the judgment step in S102 must be executed until there is no data to be coded in the first binary data.

[0063] S103, read the first string of the first coding length to be coded in the first binary data, and update the first current coding state value based on the first string.

[0064] As an example, S103 can be understood as: when it is determined that the reading condition is met based on the first current coding state value and the first coding underflow boundary, read the first string of the first coding length from the first binary data, and supplement the first string to the first current coding state value to obtain the updated first current coding state value. Among them, updating the first current coding state value based on the first string in S103 can include, for example: shifting the current first coding state value to the left by the first coding length and then performing an OR operation with the first string to obtain the updated first current coding state value. Taking the first coding length as d, the first current coding state value as state, and the first string as S[i] as an example, then, in S103, the first current coding state value can be updated based on the following formula (3):

[0065] state = (state << d) | S[i]... formula (3)

[0066] In formula (3), state on the left side of the equal sign is the updated first current coding state value, state on the right side of the equal sign is the first current coding state value before update, << is the left shift operator in binary, state << d means shifting state to the left by d bits, | is the OR operator in binary, and (state << d) | S[i] means performing an OR operation on (state << d) and S[i].

[0067] In this way, when S104 is subsequently executed to perform text coding on the first current coding state value, since the first current coding state value includes the first string in the first binary data, partial text coding of the first binary data is realized.

[0068] For example, assuming that the first coding length is 8 bits, the first binary data can be represented by the following byte sequence: S[0], S[1], S[2], …, S[N-1], where N is an integer greater than 1. If the first string read in S103 is S[0], then the updated first current coding state value can be: state = (state<<8)|S[0], the lower 8 bits of the updated first current coding state value are S[0], and the other bits are the first current coding state value before the update.

[0069] S104, determining a first printable character based on a first current encoding state value and the first base value, and updating the first current encoding state value based on the first base value.

[0070] As an example, determining the first printable character based on the first current coding state value and the first base value in S104 may include, for example: first, dividing the first current coding state value by the first base value to obtain a remainder; then, determining the first printable character according to the remainder and the coding mapping table corresponding to the first base value, wherein the coding mapping table corresponding to the first base value includes the first base value correspondence between numerical values ​​and printable characters, and the numerical values ​​are non-negative integers less than the first base value. Updating the first current coding state value based on the first base value in S104 may include, for example: first, dividing the first current coding state value by the first base value to obtain a quotient; then, based on the quotient, obtaining the updated first current coding state value, for example, the quotient may be rounded down to obtain the updated first current coding state value.

[0071] For example, assume that the first binary data can be represented by the following byte sequence: S[0], S[1], S[2], ..., S[N-1], N is an integer greater than 1, the first base value is 45, the first encoding length is 8 bits, the first state value length is 32 bits, and the first current encoding state value calculated based on formula (1) is 2 (32-8) =16777216, the first code underflow boundary calculated based on formula (2) is After the judgment of S102, it is determined to execute S104. After S104, on the one hand, (first current encoding state value%45)=1 can be calculated. Assuming that the encoding mapping table with a base value of 45 includes the corresponding relationship between 1 and the printable character a, then the first printable character is determined to be a; on the other hand, floor(first current encoding state value / 45)=372827 can be calculated, that is, the first current encoding state value updated by S104 is 372827. Then, the judgment of S102 is continued to be executed, and it is determined that the first current encoding state value 372827 is less than the first encoding underflow boundary 16777215, and S103 is executed to read S[0], and update the first current encoding state value to: (372827<<8)|S[0]; then, S104 is executed on (372827<<8)|S[0] to obtain another printable character b, and the first current encoding state value is updated; and this is repeated until there is no byte to be encoded in the first binary data.

[0072] It should be noted that since the method 100 is applicable to text encodings corresponding to different base values, at least one encoding mapping table is maintained on the communication device implementing the method 100. The embodiment of the present application does not limit the number, format, etc. of the maintained encoding mapping tables, as long as the method 100 can be implemented.

[0073] In one case, if the correspondence between numerical values ​​and printable characters is not repeated or is less repeated for different base values, then the communication device can maintain a corresponding encoding mapping table for different base values, and when encoding text based on a certain base value, only the encoding mapping table corresponding to the base value can be checked. For example, the communication device can maintain the encoding mapping table shown in Table 1 below for base value 45, and the communication device can maintain the encoding mapping table shown in Table 2 below for base value 100:

[0074] Table 1 Coding mapping table corresponding to base value 45

[0075] Numeric Printable characters 1 a 2 b …… ……

[0076] Table 2 Coding mapping table corresponding to base value 100

[0077] Numeric Printable characters 1 c 2 d …… ……

[0078] In another case, if the correspondence between the numerical value and the printable character is repeated for a large number or even completely for different base values, then the communication device can maintain the correspondence between the numerical value and the printable character under different base values ​​in a large encoding mapping table, and when encoding text based on different base values, the encoding mapping table corresponding to the base value can be checked. For example, in each base value, the numerical value 1 corresponds to the printable character a, and the numerical value 2 corresponds to the printable character b, then the communication device can maintain the encoding mapping table shown in Table 3 below:

[0079] Table 3 Coding mapping table corresponding to different base values

[0080] Numeric Printable characters 1 a 2 b …… ……

[0081] S105: Determine an encoding result of the first binary data based on the plurality of first printable characters.

[0082] In some implementations, when there is no data to be encoded in the first binary data, S105 can be executed. For example, the multiple first printable characters can be arranged in the order in which the multiple first printable characters are obtained in the text encoding process to obtain the encoding result of the text encoding of the first binary data.

[0083] When there is no data to be encoded in the first binary data, in order to accurately decode the encoding result later, the method 100 may also include processing the first current encoding state value. As an example, the method 100 may include: taking the first base value as the dividend, performing continuous division and remainder operations on the first current encoding state value until the first current encoding state value is 0, and after each division and remainder operation, determining at least one third printable character based on the encoding mapping table corresponding to the remainder and the first base value, and using the quotient as the updated first current encoding state value, and the updated first current encoding state value as the divisor for the next division and remainder operation.

[0084] It should be noted that for subsequent accurate decoding, the third printable character needs to be saved. For example, the obtained third printable character can be added to the encoding result of the first binary data, so that the initial current decoding state value can be restored based on the third printable character in the encoding result during decoding. When restoring the initial current decoding state value during the decoding process, it is also necessary to obtain the number of third printable characters. The number of third printable characters can be carried in the encoding result, so the number of third printable characters can be obtained from the encoding result; or the number of third printable characters can also be calculated and determined based on the first state value length and the first base value. For example, the number of third printable characters can be The process of restoring the initial current decoding state value based on the third printable character during the decoding process can be seen in Figure 3 A description of the method 200 is shown.

[0085] For example, still taking the first base value as 45 and the first coding underflow boundary as 16777215 as an example, assuming that when there is no data to be coded in the first binary data, the first current coding state value is 372827, then, (372827%45)=2 is calculated, and the first current coding state value is updated to floor(372827 / 45)=8285; (8285%45)=5 is calculated, and the first current coding state value is updated to floor(8285 / 45)=184; (184%45)=4 is calculated, and the first current coding state value is updated to floor(184 / 45)=4; (4%45)=4 is calculated, and the first current coding state value is updated to floor(4 / 45)=0; (0%45)=0 is calculated. Assuming that the coding mapping table with a base value of 45 may include: 0 and printable characters! , 1 and printable character a, 2 and printable character b, 3 and printable character c, 4 and printable character d, and 5 and printable character e, then the third printable character may include {b, e, d, d,!}. In this example, the number of the third printable characters is 5, which is the same as the formula for calculating the number of the third printable characters. The calculation results are consistent.

[0086] In some implementations, the printable characters in the encoding result of the text encoding in the embodiments of the present application can be stored in a storage form with the characteristics of "first in, last out", for example, a stack structure can be used to store the printable characters in the encoding result. In this way, the order of encoding and decoding can be reversed, for example, S[0] is encoded first, and S[N-1] is encoded last, but decoding requires first decoding the encoding result of S[N-1] (for example, it can be recorded as E[N-1]), and finally decoding the encoding result of S[0] (for example, it can be recorded as E[0]), thereby ensuring that the binary data before and after encoding are consistent, that is, accurate encoding and decoding is achieved.

[0087] The encoding result obtained according to method 100 can be carried in a transmission protocol, for example, to achieve the purpose of carrying and transmitting the first binary data; or, the encoding result can also be used to generate a QR code, to achieve the purpose of carrying the first binary data in the QR code; or, the encoding result can also be included in a file such as PDF, to achieve the purpose of carrying the first binary data in the file.

[0088] For example, if Figure 2As shown, for binary data 1 including 0100010111011001..., encoding is performed according to method 100 and 45 is selected as the base value, and the obtained encoding result 2 may include "OCQ,R#j!..., and the encoding result 2 is processed to obtain a QR code 3, and the QR code 3 includes the content of the binary data 1. All symbols included in the above encoding result 2 are printable characters.

[0089] In some implementations, Figure 1 In the text encoding corresponding to the first base value, only the method 100 is applied to an example for description. The method 100 can also be used in text encoding corresponding to other base values ​​other than the first base value. For example, the method 100 can also include: determining the second current encoding state value and the second encoding underflow boundary according to the second encoding length, the second base value and the second state value length, the second encoding underflow boundary is the minimum value of the second current encoding state value allowed, and the second base value is determined from the multiple base values; if the second current encoding state value is less than the second encoding underflow boundary, then reading the second character string of the second encoding length to be encoded in the second binary data, and updating the second current encoding state value based on the second character string; if the second current encoding state value is greater than or equal to the second encoding underflow boundary, then determining the second printable character based on the second current encoding state value and the second base value, and updating the second current encoding state value based on the second base value; based on the multiple second printable characters, determining the encoding result of the second binary data. It can be seen that the encoding method provided in the embodiment of the present application can be applied to any base value to achieve flexible text encoding.

[0090] for Figure 1The encoding result obtained by the encoding method shown in the figure, the method 100 may also include a decoding process for the encoding result, and the decoding process may include: determining a first current decoding state value based on the encoding result, and determining a first decoding overflow boundary based on the first encoding length, the first base value and the first state value length, the first decoding overflow boundary being the minimum value of the first current decoding state value allowed; reading the first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and the third character string corresponding to the first printable character; if the first current decoding state value is greater than or equal to the first decoding overflow boundary, taking the character of the first encoding length at the end of the first current decoding state value as the first decoding character, and updating the first current decoding state value based on the first encoding length; if the first current decoding state value is less than the first decoding overflow boundary, reading the next first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and the third character string corresponding to the first printable character; determining the first binary data according to multiple first decoding characters. In this way, based on the method 100, accurate and flexible encoding and decoding of binary data can be achieved, making the carrying and transmission of binary data more convenient and reliable. It should be noted that the specific description of the decoding process can be found in the following Figure 3 The embodiment shown.

[0091] In the method 100 provided in the embodiment of the present application, since the designed encoding underflow boundary is very reasonable, the encoding efficiency can be close to the optimal encoding efficiency of the base value for any base value. Taking the base value of 45 as an example, the encoding efficiency of the current Base45 and the text encoding scheme provided by the method 100 are compared, and the comparison results are shown in Table 4 below:

[0092] Table 4 Coding efficiency comparison

[0093] Base value Best coding efficiency Method 100 Base45 Improved coding efficiency 45 68.65% 68.65% 66.67% 3%

[0094] As shown in Table 4, compared with Base45, the coding efficiency of method 100 is improved by 3%, and the deviation between it and the best coding efficiency with 45 as the base value is less than 10^(-4), which is close enough to the best coding efficiency.

[0095] It should be noted that, whether it is during the text encoding process, each time a binary string of the encoded length is read, or during the text decoding process, each time a printable character is read, from the perspective of the program implementation, it is necessary to determine whether there is any content to be processed that can be read. If so, the reading and subsequent operations of this step are executed. If not, the encoding or decoding process is terminated and each encoding and decoding process is sorted out (for example, executing S105 or the following S206).

[0096] It can be seen that in the method 100, by combining the coding underflow boundary and the continuous modulo operation, the text encoding corresponding to different base values ​​of the binary data can be performed according to actual needs, thereby achieving a text encoding effect with strong flexibility and a wide range of applications, and overcoming the current shortcomings of needing to design corresponding text encoding schemes for different base values. Moreover, the coding underflow boundary is reasonably determined based on the determined base value, so that the coding efficiency of the text encoding method can be close to the optimal coding efficiency corresponding to the determined base value, making it possible to carry or transmit the encoding results using fewer resources in the subsequent process.

[0097] Figure 3 2 shows a flow chart of a text decoding method 200 provided in an embodiment of the present application. In the method 200, the text decoding of a printable string to be decoded is taken as an example to illustrate the text decoding method provided in the embodiment of the present application. Figure 3 As shown, the method 200 may include, for example, the following S201 to S206:

[0098] S201, determine the current decoding state value based on the printable character string to be decoded, and determine the decoding overflow boundary based on the encoding length, the base value and the state value length, the base value is determined from multiple base values ​​during encoding, the state value length indicates the length of the current encoding state value during encoding, and the decoding overflow boundary is the minimum value allowed for the current decoding state value.

[0099] It can be understood that the base value in S201 is the base value used when encoding to obtain the printable string to be decoded. If the printable string to be decoded belongs to the encoding result obtained in S105 of the above method 100, the base value in method 200 can correspond to the first base value in method 100. Similarly, the encoding length in S201 is the encoding length used when encoding to obtain the printable string to be decoded. If the printable string to be decoded belongs to the encoding result obtained in S105 of the above method 100, the encoding length in method 200 can correspond to the first encoding length in method 100; the state value length in S201 is the state value length used when encoding to obtain the printable string to be decoded. If the printable string to be decoded belongs to the encoding result obtained in S105 of the above method 100, the state value length in method 200 can correspond to the first state value length in method 100.

[0100] As an example, S201 may include: S201a, determining the current decoding state value based on the printable character string to be decoded, S201b, determining the decoding overflow boundary based on the encoding length, the base value and the state value length. It should be noted that there is no order limit for the execution of S201a and S201b.

[0101] Among them, S201a is the step of restoring the initial current decoding state value in the decoding process mentioned in method 100. The printable character string to be decoded includes a third printable character, and the third printable character is a printable character determined based on the current encoding state value and the base value when there is no data to be encoded and the binary data corresponding to the printable character string. As an example, if the printable character string to be decoded also includes a second printable character for indicating the number of third printable characters in the printable character string, then S201a may include, for example: first, obtain the second printable character from the printable character string to be decoded; then, obtain a plurality of the third printable characters in the printable character string based on the second printable character; then, determine the current decoding state value based on the second character string corresponding to the plurality of the third printable characters. As another example, if the printable character string to be decoded does not include the second printable character, then S201a may, for example, include: first, determining the number of third printable characters based on the state value length and the base value calculation; then, obtaining a plurality of the third printable characters in the printable character string according to the determined number; and then, determining the current decoding state value based on the second character string corresponding to the plurality of the third printable characters.

[0102] For example, the base value is 45, and the printable character string A to be decoded may include, in sequence: printable character 1, printable character 2, ..., printable character k, where printable character k is used to indicate the number of third printable characters in the printable character string A. Assuming that the printable character k corresponds to the value 3 in the encoding mapping table corresponding to the base value 45, that is, the printable character A includes 3 third printable characters, namely: printable character (k-3), printable character (k-2) and printable character (k-1), and the first printable characters included in the printable character string A are: printable character 1, printable character 2, ..., printable character (k-4). In the implementation method of S201, "determining the current decoding state value based on the second character string corresponding to the multiple third printable characters" may include: first, respectively determining the corresponding values ​​of printable character (k-3), printable character (k-2) and printable character (k-1) in the encoding mapping table corresponding to the base value of 45, assuming that the corresponding values ​​of printable character (k-3), printable character (k-2) and printable character (k-1) in the encoding mapping table corresponding to the base value of 45 are 10, 41 and 13 respectively; then, based on the method for obtaining the third printable character in the text encoding method provided in an embodiment of the present application, reversely obtain the current encoding state value when there is no data to be encoded in the binary data, as the current decoding state value determined by S201. Taking the case where there is no data to be encoded in the binary data, the base value is used as the dividend, and the current encoding state value is continuously divided and the remainder is taken until the current encoding state value is 0 to obtain the third printable character as an example, the reverse process may include: (1) calculating 0*45+13=13, (2) calculating 13*45+41=626, (3) calculating 626*45+10=28180, so that the current decoding state value can be determined to be 28180. In this example, k is an integer greater than 4.

[0103] Assuming that the base value is b, the code length is d, and the state value length is n, then S201b may include, for example: determining a decoding overflow boundary dec_upper_bound based on the following formula (4):

[0104]

[0105] By determining the current decoding state value and the decoding overflow boundary in S201, preparation is made for subsequently determining the timing of reading the first printable character from the printable character string to be decoded, making it possible for method 200 to achieve accurate text decoding.

[0106] S202, reading a first printable character at the end of the printable character string, and updating the current decoding state value according to a base value and a first character string corresponding to the first printable character.

[0107] As an example, updating the current decoding state value according to the base value and the first character string corresponding to the first printable character in S202 may include: determining a numerical value corresponding to the read first printable character from a coding mapping table corresponding to the base value, recorded as the first character string; adding the product of the current decoding state value determined in S201 and the base value to the first character string to obtain an updated current decoding state value.

[0108] Taking the example in S201, the first printable character at the end of the printable string can refer to the printable character (k-4) in the printable string A. Assuming that the corresponding value of the printable character (k-4) in the encoding mapping table corresponding to the base value of 45 is X, then based on the processing of S202, the updated current decoding state value can be expressed as: 28180*45+X=1268100+X.

[0109] S203, determine whether the current decoding state value is greater than or equal to the decoding overflow boundary, if yes, execute S204 to S205, otherwise, execute S205.

[0110] The current decoding state value is less than the decoding overflow boundary, which can be used as a reading condition for reading the next first printable character to be decoded in the printable character string in S205. Only when the reading condition is met, the first printable character to be decoded in the printable character string will be read and decoded in sequence. If the reading condition is not met, S204 can be executed first to decode the current decoding state value and then S205 can be executed.

[0111] As an example, the current decoding state value (i.e., the current decoding state value after being updated in S202) is greater than or equal to the decoding overflow boundary, that is, when S203 is executed for the first time, the judgment result is "yes". Next, each time the decoding overflow boundary is updated in S205, the judgment step in S203 is executed until there is no first printable character to be decoded in the printable character string.

[0112] S204: Use the last character of the encoding length in the current decoding state value as a decoding character, and update the current decoding state value based on the encoding length.

[0113] When the current decoding state value is greater than or equal to the decoding overflow boundary, it can be considered that the length of the current decoding state value is suitable for direct decoding, so the current decoding state value is decoded once in S204 to obtain a decoded character.

[0114] As an example, decoding the current decoding state value once through S204 may include: reading the last (i.e., low-order) characters of the coding length in the current decoding state value as the decoding characters for this decoding. In S204, the current decoding state value is updated based on the coding length, and may include: shifting the current decoding state value right by the coding length to obtain the updated current decoding state value. For example, taking the coding length as d, the current decoding state value as state, and the character of the last coding length in the current decoding state value state as X, after processing in S204, the obtained decoding character is X. For example, the current decoding state value may be updated based on the following formula (5):

[0115] state=state>>d……Formula (5)

[0116] In formula (5), the state on the left side of the equal sign is the current decoding state value after the update, the state on the right side of the equal sign is the current decoding state value before the update, >> is the right shift operator in binary, and state>>d means that state is shifted right by d bits.

[0117] S205, reading the next first printable character to be decoded in the printable character string, and updating the current decoding state value according to the base value and the first character string corresponding to the first printable character.

[0118] If the first printable character read in S202 is the printable character (k-4) in the printable string A, then when S205 is executed for the i-th time, the first printable character read is the printable character (k-4-i) in the printable string A, where i is an integer from 1 to (k-5). When i=(k-5), that is, when S205 is executed for the (k-5)th time, the first printable character read is the printable character 1 in the printable string A (because (k-4-(k-5))=1), and printable character 1 is the last first printable character to be decoded in the printable string A.

[0119] As an example, in S205, when the next first printable character to be decoded is read, the current decoding state value is updated according to the base value and the first character string corresponding to the read first printable character, for example, may include: calculating the product of the base value and the current decoding state value; calculating the sum of the product and the first character string to obtain the updated current decoding state.

[0120] For example, still using the aforementioned example in method 200 for illustration, assuming that after the printable string A passes through S201 to S204, the current decoding state value is X1, and the next first printable character to be decoded in the printable string A is the printable character (k-5). Then, the corresponding value of the printable character (k-5) in the encoding mapping table corresponding to the base value of 45 is Y. Then, based on the processing of S205, the updated current decoding state value can be expressed as: X1*45+Y.

[0121] It should be noted that after each execution of S205, the execution of S203 may be returned.

[0122] It should be noted that the prerequisite for executing S205 is that the printable character string to be decoded includes the first printable character that has not been decoded and is waiting to be read. When S205 reads the last first printable character in the printable character string, after the execution of S205 is completed, S203 is returned to be executed. When S205 needs to be executed next time in the process of method 200, since the printable character string no longer includes the first printable character that has not been decoded and is waiting to be read, S205 is skipped and S206 is directly executed. For example, in the example of method 200, when S205 is executed for the (k-5)th time, the last printable character 1 to be decoded in the printable character string A is read, and after the current decoding state value is updated based on the base value 45 and the character string corresponding to the printable character 1 in the encoding mapping table corresponding to the base value 45, S203 and S204 are returned to be executed. Since there is no printable character to be decoded in the printable character string A, S205 is not executed and S206 is directly executed.

[0123] S206: Determine binary data corresponding to the printable character string according to the plurality of decoded characters.

[0124] As an example, the decoded characters obtained by executing S204 multiple times may be shifted left by the encoding length in the order in which they are obtained to obtain a decoding result of a printable character string, and the decoding result is expressed in binary data.

[0125] For example, assuming that in the decoding process of the printable string A, the decoding results obtained after executing S204 multiple times are: Z1, Z2, Z3 and Z4 respectively, the base value is 45, and the encoding length is 8 bits, then the binary data corresponding to the printable string A can be expressed as: (Z4<<(3*8))|(Z3<<(2*8))|(Z2<<8)|Z1.

[0126] In this way, in method 200, by designing a text decoding process corresponding to the above-mentioned text encoding method 100, it is possible to accurately decode the text obtained by the text encoding provided in the embodiment of the present application, making it possible to promote and apply the text encoding method provided in the embodiment of the present application.

[0127] Accordingly, the embodiment of the present application further provides a communication device 400, such as Figure 4 The communication device 400 may include: a first determining unit 401, a first reading unit 402, a first updating unit 403, a second determining unit 404, a second updating unit 405 and a third determining unit 406.

[0128] The first determining unit 401 is used to determine a first current coding state value and a first coding underflow boundary according to a first base value, wherein the first base value is determined from a plurality of base values, and the first coding underflow boundary is a minimum value of the first current coding state value allowed. The first determining unit 401 may be executed Figure 1 S101 shown.

[0129] The first reading unit 402 is configured to read a first character string of a first encoding length to be encoded in the first binary data if the first current encoding state value is less than the first encoding underflow boundary. The first reading unit 402 may be executed Figure 1 The relevant steps in S103 are shown.

[0130] The first updating unit 403 is configured to update the first current encoding state value based on the first character string if the first current encoding state value is less than the first encoding underflow boundary. The first updating unit 403 may be executed Figure 1 The relevant steps in S103 are shown.

[0131] The second determining unit 404 is configured to determine a first printable character based on the first current encoding state value and the first base value if the first current encoding state value is greater than or equal to the first encoding underflow boundary. The second determining unit 404 may be executed Figure 1 The relevant steps in S104 are shown.

[0132] The second updating unit 405 is configured to update the first current coding state value based on the first base value if the first current coding state value is greater than or equal to the first coding underflow boundary. The second updating unit 405 may be executed Figure 1 The relevant steps in S104 are shown.

[0133] The third determining unit 406 is configured to determine the encoding result of the first binary data based on the plurality of the first printable characters. The third determining unit 406 may be executed Figure 1 S105 shown.

[0134] Optionally, the first determination unit 401 is specifically used to determine the first current coding state value and the first coding underflow boundary based on the first base value, the first coding length and the first state value length, and the first state value length indicates the length of the first current coding state value.

[0135] Optionally, the apparatus 400 may further include: a fourth determining unit, a second reading unit, a third updating unit, a fifth determining unit, a fourth updating unit and a sixth determining unit. Among them, the fourth determining unit is used to determine the second current coding state value and the second coding underflow boundary according to the second coding length, the second base value and the second state value length, the second coding underflow boundary is the minimum value allowed for the second current coding state value, and the second base value is determined from the multiple base values; the second reading unit is used to read the second character string of the second coding length to be encoded in the second binary data if the second current coding state value is less than the second coding underflow boundary; the third updating unit is used to update the second current coding state value based on the second character string if the second current coding state value is less than the second coding underflow boundary; the fifth determining unit is used to determine the second printable character based on the second current coding state value and the second base value if the second current coding state value is greater than or equal to the second coding underflow boundary; the fourth updating unit is used to update the second current coding state value based on the second base value if the second current coding state value is greater than or equal to the second coding underflow boundary; the sixth determining unit is used to determine the encoding result of the second binary data based on the multiple second printable characters.

[0136] Optionally, the first updating unit 403 is specifically used to: shift the current first encoding state value left by the first encoding length and perform an OR operation with the first character string to obtain an updated first current encoding state value.

[0137] Optionally, the second determination unit 404 is specifically used to: calculate the first current encoding state value divided by the first basis value to obtain a remainder; determine the first printable character according to a coding mapping table corresponding to the remainder and the first basis value, the coding mapping table including the first basis value correspondence between numerical values ​​and printable characters, and the numerical value is a non-negative integer less than the first basis value.

[0138] Optionally, the second updating unit 405 is specifically used to: calculate the first current coding state value divided by the first basis value to obtain a quotient; and obtain an updated first current coding state value based on the quotient.

[0139] Optionally, the apparatus 400 may further include: a seventh determining unit and a fifth updating unit. The seventh determining unit is used to determine a third printable character based on the first current encoding state value and the first base value if there is no data to be encoded in the first binary data to be encoded; and the fifth updating unit is used to update the first current encoding state value based on the first base value if there is no data to be encoded in the first binary data to be encoded.

[0140] Optionally, the encoding result also includes a plurality of the third printable characters and the number of the third printable characters.

[0141] Optionally, the printable characters in the encoding result are stored in a stack structure.

[0142] Optionally, the device 400 may also include: an eighth determination unit, a third reading unit, a sixth updating unit, a ninth determination unit, a seventh updating unit, a fourth reading unit, an eighth updating unit and a tenth determination unit. The eighth determination unit is used to determine the first current decoding state value based on the encoding result, and determine the first decoding overflow boundary based on the first encoding length, the first base value and the first state value length, the first decoding overflow boundary being the minimum value of the first current decoding state value allowed; the third reading unit is used to read the first printable character to be decoded in the encoding result; the sixth updating unit is used to update the first current decoding state value according to the first base value and the third character string corresponding to the first printable character; the ninth determination unit is used to replace the first current decoding state value with the first encoding length at the end if the first current decoding state value is greater than or equal to the first decoding overflow boundary. as a first decoding character; a seventh updating unit, for updating the first current decoding state value based on the first encoding length if the first current decoding state value is greater than or equal to the first decoding overflow boundary; a fourth reading unit, for reading the next first printable character to be decoded in the encoding result if the first current decoding state value is less than the first decoding overflow boundary; an eighth updating unit, for updating the first current decoding state value according to the first base value and a third character string corresponding to the first printable character if the first current decoding state value is less than the first decoding overflow boundary; and a tenth determining unit, for determining the first binary data according to a plurality of the first decoding characters.

[0143] Optionally, the encoding result is used for a transmission protocol, a quick response QR code or a file.

[0144] It should be noted that various specific embodiments of the communication device 400 can be found in Figure 1 The corresponding introduction of method 100 will not be repeated in this embodiment.

[0145] Accordingly, the embodiment of the present application further provides a communication device 500, such as Figure 5 The communication device 500 may include: a first determining unit 501, a first reading unit 502, a first updating unit 503, a second determining unit 504, a second updating unit 505, a second reading unit 506, a third updating unit 507 and a third determining unit 508. Wherein:

[0146] The first determination unit 501 is used to determine the current decoding state value based on the printable character string to be decoded, and determine the decoding overflow boundary based on the encoding length, the base value and the state value length, wherein the base value is determined from multiple base values ​​during encoding, the state value length indicates the length of the current encoding state value during encoding, and the decoding overflow boundary is the minimum value of the current decoding state value allowed. The first determination unit 501 can be executed Figure 3 S201 shown.

[0147] The first reading unit 502 is used to read the first printable character at the end of the printable character string. The first reading unit 502 can execute Figure 3 The relevant steps of S202 are shown.

[0148] The first updating unit 503 is used to update the current decoding state value according to the base value and the first character string corresponding to the first printable character. The first updating unit 503 can be executed Figure 3 The relevant steps of S202 are shown.

[0149] The second determining unit 504 is configured to use the character of the last encoding length in the current decoding state value as the decoding character if the current decoding state value is greater than or equal to the decoding overflow boundary. The second determining unit 504 may be executed Figure 3 The relevant steps of S204 are shown.

[0150] The second updating unit 505 is configured to update the current decoding state value based on the encoding length if the current decoding state value is greater than or equal to the decoding overflow boundary. The second updating unit 505 may perform Figure 3 The relevant steps of S204 are shown.

[0151] The second reading unit 506 is configured to read the next first printable character to be decoded in the printable character string if the current decoding state value is less than the decoding overflow boundary. The second reading unit 506 may execute Figure 3 The relevant steps of S205 are shown.

[0152] The third updating unit 507 is configured to update the current decoding state value according to the base value and the first character string corresponding to the first printable character if the current decoding state value is less than the decoding overflow boundary. The third updating unit 507 may execute Figure 3 The relevant steps of S205 are shown.

[0153] The third determining unit 508 is used to determine the binary data corresponding to the printable character string according to the plurality of decoded characters. The third determining unit 508 can execute Figure 3 S206 shown.

[0154] Optionally, the first determination unit 501 is specifically used to: obtain a second printable character from the printable character string, the second printable character is used to indicate the number of third printable characters in the printable character string, the third printable character is a printable character determined based on the current encoding state value and the base value when there is no data to be encoded in the binary data corresponding to the printable character string; obtain a plurality of the third printable characters in the printable character string based on the second printable character; and determine the current decoding state value based on the second character string corresponding to the plurality of the third printable characters.

[0155] Optionally, the first updating unit 503 is specifically used to: calculate the product of the base value and the current decoding state value; calculate the sum of the product and the first character string to obtain the updated current decoding state value.

[0156] Optionally, the second updating unit 505 is specifically configured to: right-shift the current decoding state value by the coding length to obtain an updated current decoding state value.

[0157] It should be noted that various specific embodiments of the communication device 500 can be found in Figure 3 The corresponding introduction of method 200 will not be repeated in this embodiment.

[0158] See also Figure 6 , an embodiment of the present application provides a communication device 600. The communication device 600 may be an execution subject in any of the above embodiments. The communication device 600 may implement the functions of the above embodiments. The communication device 600 includes at least one processor 601, a bus system 602, a memory 603 and at least one communication interface 604.

[0159] The communication device 600 is a hardware structure device that can be used to implement Figure 4 The functional modules in the communication device 400 shown in FIG. Figure 4The first determining unit 401, the first reading unit 402, the first updating unit 403, the second determining unit 404, the second updating unit 405 and the third determining unit 406 in the communication device 400 shown in the figure can be implemented by the at least one processor 601 calling the code in the memory 603. For another example, those skilled in the art can imagine Figure 5 The first determination unit 501, the first reading unit 502, the first updating unit 503, the second determination unit 504, the second updating unit 505, the second reading unit 506, the third updating unit 507 and the third determination unit 508 in the communication device 500 shown can be implemented by calling the code in the memory 603 by the at least one processor 601.

[0160] Optionally, the communication device 600 may be a network device or a control entity implementing an embodiment of the present application.

[0161] Optionally, the processor 601 may be a general-purpose central processing unit (CPU), a network processor (NP), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.

[0162] The bus system 602 may include a path for transmitting information between the components.

[0163] The communication interface 604 is used to communicate with other devices or communication networks.

[0164] The memory 603 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a bus. The memory may also be integrated with the processor.

[0165] The memory 603 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 601. The processor 601 is used to execute the application code stored in the memory 603, so as to realize the functions in the method of the present application.

[0166] In a specific implementation, as an embodiment, the processor 601 may include one or more CPUs, such as Figure 6 CPU0 and CPU1 in.

[0167] In a specific implementation, as an embodiment, the communication device 600 may include multiple processors, such as Figure 6 601 and processor 607 in FIG. Each of these processors may be a single-CPU processor or a multi-CPU processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0168] It should be understood that the communication devices or communication devices in the above-mentioned various product forms respectively have any functions implemented by the execution subject in the above-mentioned method embodiment, which will not be repeated here.

[0169] The embodiment of the present application further provides a chip, including a processor and an interface circuit, the interface circuit is used to receive instructions and transmit them to the processor; the processor, for example, can be a specific implementation form of the message processing device in the embodiment of the present application, and can be used to execute the above method 100 or method 200. The processor is coupled to a memory, and the memory is used to store programs or instructions. When the program or instruction is executed by the processor, the chip system implements the method in any of the above method embodiments.

[0170] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.

[0171] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be separately provided with the processor, which is not limited in the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be provided on different chips. The present application does not specifically limit the type of memory and the arrangement of the memory and the processor.

[0172] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.

[0173] In addition, the embodiment of the present application also provides a communication system 700, such as Figure 7 As shown, the communication system 700 may include a first communication device 701 and a second communication device 702. The first communication device 701 is used to perform the above Figure 1The method in the embodiment shown; the second communication device 702 is used to execute the above Figure 3 The first communication device 701 may correspond to the above Figure 4 The communication device 400 shown in FIG. 4 , then the second communication device 702 corresponds to the above Figure 5 The communication device 500 is shown.

[0174] In addition, an embodiment of the present application further provides a storage medium, in which program code or instructions are stored. When the storage medium is run on a processor, the processor executes a method in any one of the implementation modes in the above embodiments.

[0175] In addition, an embodiment of the present application also provides a program product, which, when executed on a processor, enables the processor to execute a method of any one of the implementation modes of the aforementioned method 100 or method 200.

[0176] It should be understood that "determining B based on A" mentioned in the embodiments of the present application does not mean determining B only based on A, but B can also be determined based on A and / or other information.

[0177] It should be understood that the network architecture and business scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Ordinary technicians in this field can know that with the evolution of network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0178] In this application, ordinal numbers such as "1", "2", "3", "first", "second" and "third" are used to distinguish multiple objects but are not used to limit the order of multiple objects.

[0179] “A and / or B” mentioned in this application should be understood to include the following situations: only A, only B, or both A and B.

[0180] Through the description of the above implementation methods, it can be known that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment method can be implemented by means of software plus a general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a read-only memory (ROM) / RAM, a magnetic disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network communication device such as a router) to execute the methods described in each embodiment of the present application or some parts of the embodiments.

[0181] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for system embodiments and device embodiments, since they are basically similar to method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device and system embodiments described above are merely schematic, in which the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0182] The above is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. It should be noted that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the present application, and these improvements and modifications should also be regarded as the protection scope of the present application.

Claims

1. A text encoding method, characterized in that: include: Determining a first current coding state value and a first coding underflow boundary according to a first base value, wherein the first base value is determined from a plurality of base values, and the first coding underflow boundary is a minimum value of the first current coding state value allowed; If the first current encoding state value is less than the first encoding underflow boundary, reading a first character string of a first encoding length to be encoded in the first binary data, and updating the first current encoding state value based on the first character string; If the first current encoding state value is greater than or equal to the first encoding underflow boundary, determining a first printable character based on the first current encoding state value and the first basis value, and updating the first current encoding state value based on the first basis value; An encoding result of the first binary data is determined based on a plurality of the first printable characters.

2. The method according to claim 1, characterized in that The determining, according to the first base value, a first current coding state value and a first coding underflow boundary comprises: The first current encoding state value and the first encoding underflow boundary are determined according to the first base value, the first encoding length and a first state value length, wherein the first state value length indicates the length of the first current encoding state value.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: Determine a second current coding state value and a second coding underflow boundary according to a second coding length, a second basis value, and a second state value length, wherein the second coding underflow boundary is a minimum value allowed for the second current coding state value, and the second basis value is determined from the plurality of basis values; If the second current encoding state value is less than the second encoding underflow boundary, reading a second character string of the second encoding length to be encoded in the second binary data, and updating the second current encoding state value based on the second character string; If the second current encoding state value is greater than or equal to the second encoding underflow boundary, determining a second printable character based on the second current encoding state value and the second basis value, and updating the second current encoding state value based on the second basis value; Based on the plurality of second printable characters, an encoding result of the second binary data is determined.

4. The method according to any one of claims 1 to 3, characterized in that: The updating of the first current encoding state value based on the first character string includes: The current first encoding state value is shifted left by the first encoding length and then ORed with the first character string to obtain an updated first current encoding state value.

5. The method according to any one of claims 1 to 4, characterized in that: The determining of a first printable character based on the first current encoding state value and the first base value comprises: Calculate the first current encoding state value and divide it by the first basis value to obtain a remainder; The first printable character is determined according to a coding mapping table corresponding to the remainder and the first basis value, wherein the coding mapping table includes the first basis value correspondences between numerical values ​​and printable characters, and the numerical values ​​are non-negative integers less than the first basis value.

6. The method according to any one of claims 1 to 5, characterized in that: The updating the first current encoding state value based on the first base value includes: Calculate the first current encoding state value and divide it by the first basis value to obtain a quotient; Based on the quotient, an updated first current encoding state value is obtained.

7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: If there is no data to be encoded in the first binary data to be encoded, a third printable character is determined based on the first current encoding state value and the first base value, and the first current encoding state value is updated based on the first base value.

8. The method according to claim 7, characterized in that The encoding result also includes a plurality of the third printable characters and the number of the third printable characters.

9. The method according to any one of claims 1 to 8, characterized in that: The printable characters in the encoding result are stored in a stack structure.

10. The method according to any one of claims 1 to 9, characterized in that: The method further comprises: Determine a first current decoding state value based on the encoding result, and determine a first decoding overflow boundary based on the first encoding length, the first base value, and the first state value length, wherein the first decoding overflow boundary is a minimum value of the first current decoding state value allowed; Reading the first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and a third character string corresponding to the first printable character; If the first current decoding state value is greater than or equal to the first decoding overflow boundary, taking the last character of the first coding length in the first current decoding state value as the first decoding character, and updating the first current decoding state value based on the first coding length; If the first current decoding state value is less than the first decoding overflow boundary, reading the next first printable character to be decoded in the encoding result, and updating the first current decoding state value according to the first base value and a third character string corresponding to the first printable character; The first binary data is determined according to a plurality of the first decoded characters.

11. The method according to any one of claims 1 to 10, characterized in that: The encoding result is used for transmission protocol, quick response QR code or file.

12. A text decoding method, characterized in that: include: Determine a current decoding state value based on a printable character string to be decoded, and determine a decoding overflow boundary based on an encoding length, a base value, and a state value length, wherein the base value is determined from a plurality of base values ​​during encoding, the state value length indicates the length of the current encoding state value during encoding, and the decoding overflow boundary is a minimum value of the current decoding state value allowed; Reading a first printable character at the end of the printable character string, and updating the current decoding state value according to the base value and a first character string corresponding to the first printable character; If the current decoding state value is greater than or equal to the decoding overflow boundary, the character of the last encoding length in the current decoding state value is used as the decoding character, and the current decoding state value is updated based on the encoding length; If the current decoding state value is less than the decoding overflow boundary, reading the next first printable character to be decoded in the printable character string, and updating the current decoding state value according to the base value and the first character string corresponding to the first printable character; According to the plurality of decoded characters, binary data corresponding to the printable character string is determined.

13. The method according to claim 12, characterized in that The step of determining a current decoding state value based on a printable character string to be decoded includes: Obtaining a second printable character from the printable character string, the second printable character being used to indicate the number of third printable characters in the printable character string, the third printable character being a printable character determined based on a current encoding state value and the base value when there is no data to be encoded corresponding to the binary data of the printable character string; Obtaining a plurality of third printable characters in the printable string based on the second printable character; The current decoding state value is determined based on a second character string corresponding to a plurality of the third printable characters.

14. The method according to claim 12 or 13, characterized in that The updating of the current decoding state value according to the base value and the first character string corresponding to the first printable character comprises: Calculating the product of the base value and the current decoding state value; The sum of the product and the first character string is calculated to obtain the updated current decoding state value.

15. The method according to any one of claims 12 to 14, characterized in that: The updating of the current decoding state value based on the encoding length comprises: After the current decoding state value is right-shifted by the coding length, the updated current decoding state value is obtained.

16. A communication device, characterized in that: The communication device includes a memory and a processor; The memory is used to store instructions; The processor is used to execute the instructions in the memory and perform the method according to any one of claims 1 to 11.

17. A communication device, characterized in that: The communication device includes a memory and a processor; The memory is used to store instructions; The processor is used to execute the instructions in the memory and perform the method according to any one of claims 12 to 15.

18. A communication system, characterized in that: The communication system comprises a first communication device and a second communication device; The first communication device is used to execute the method according to any one of claims 1 to 11; The second communication device is used to execute the method according to any one of claims 12 to 15.

19. A storage medium, characterized in that: The method comprises instructions, which, when executed on a processor, cause the processor to execute the method according to any one of claims 1 to 15.