The purpose of the method of the present invention is to provide a method for implementing TLV encoding and decoding in a WiMAX system (base station, terminal), which is used to construct a simple, efficient, easy-to-implement, and easy-to-expandable module, so as to meet the requirements of development based on 802.16e Its follow-up agreement software requirements.
 The basic principle of the method of the present invention is as follows:
 For a message that requires TLV encoding, since it is described by C language, and the encoding and decoding rules are not limited to any programming language (that is, the encoding and decoding rules only conform to the TLV specification), so before encoding, the encoding program must first try The data structure described by the C language is transformed into a data structure that conforms to the TLV syntax (mainly to determine the one-to-one correspondence between the data types in the two environments), and then use specific coding rules to start coding. On the contrary, for the decoding process, the decoding program first obtains a data structure described by TLV syntax through analysis, and then the program assigns values to the data structure in the application program by comparing the message data structure in a specific programming language to complete the decoding process.
 The method of the present invention will be described in detail below with reference to the drawings. As shown in Figure 1, the functional modules for implementing the method of the present invention are as follows:
 The data structure conversion module realizes the automatic conversion from the original data structure to the data structure described by the TLV mapping table, and constructs a static TLV mapping table library conforming to the WiMAX protocol.
 The interface module is used to establish the function mapping table of all WiMAX messages to be coded and decoded, and in each function, establish the assignment mapping relationship between the data structure described by the TLV mapping table and the original data structure.
 The encoding module completes the specific encoding process, traverses the data structure described by the TLV mapping table of the encoded message, and completes the conversion from each TLV mapping table to the code stream. Using the interface module, it also completes the original data structure to the code stream. Conversion between.
 The decoding module completes the specific decoding process, searches for the data structure described by the TLV mapping table of the decoded message, and completes the conversion from the code stream to the TLV mapping table. The interface module is used to complete the code stream to the original data structure. Conversion.
 The core content of the method of the present invention is to use a specific data structure (we call it TLV mapping table) to describe the various factors required for encoding and decoding (including the TYPE/LENGTH/VALUE specified by the protocol and the name of the encoding and decoding field) , TLV encoding and decoding attributes, user intervention interface, etc.), the data structure abstracted by the user according to the protocol (we call it the original data structure) is re-described with the TLV mapping table to form a generalized table, and the original The correspondence between the data structures can then be used to indirectly complete the operations on each member variable in the original data structure through operations such as indexing, querying, and traversing the generalized table. In addition, in the TLV mapping table, user intervention callback functions can be set for each member variable in the original data structure, and user-specified processing procedures can be inserted to complete specific functions during the encoding and decoding process.
 As shown in Figures 2, 3, and 4, a method for TLV encoding and decoding in a WiMAX system (base station, terminal) according to the present invention includes the steps:
 Step 1: Define the TLV mapping table, that is, define a generalized table, which contains various information fields required for TLV encoding and decoding, such as necessary fields such as type, length, value, and other auxiliary fields. Through this table, we can traverse various data structures of different forms and lengths to achieve the purpose of generalization of the TLV coding and decoding process;
 Step 2: Construct the original data structure according to the protocol specification, and construct the content of each message that needs to be coded and decoded in the WiMAX protocol into the original data structure used by the upper-layer application according to a certain writing specification;
Step 3: Automatically convert the above-mentioned original data structure to generate the data structure described by the TLV mapping table, define the corresponding static variables, generate the codec function corresponding to each management message in the WiMAX system, and the TLV mapping table and original data structure within these functions Assignment mapping relationship between;
 Step 4: Set up a user intervention callback interface where the user needs to intervene in the codec, to insert the codec process to do some special processing required by the user;
 Step 5. For the encoding process, first calculate the total length of the encoded message and apply for storage space. For the decoding process, it is necessary to decode the LENGTH field first and determine the total length of the message to be decoded;
 Step six, implement TLV encoding and decoding by calling the encoding and decoding module. The codec completes the coding and decoding of the entire message by traversing the TLV mapping table, and judging the type, length and other elements therein.
 According to the above method of the present invention, in step one, BITMASK is set for each field in the original data structure in the TLV mapping table to mark whether the field exists and whether it should be coded or decoded.
 According to the above method of the present invention, the definition of the original data structure in step 2 can be freely processed by the user. There is no order requirement for the fields specified in the agreement. The user can freely change the combination of fields and the nested data structure according to the needs of their own design. Form (except for the COMPOUND TLV combination specified in the agreement).
 According to the above method of the present invention, for the TLV decoding situation, in step 5, the received TLV code stream can be decoded in any order, and can be accurately queried and assigned to the corresponding field in the user-defined original data structure. The BITMASK corresponding to the field is set.
 According to the above method of the present invention, in the case of TLV encoding, space can be requested for the entire encoded message in step 5, and the upper layer is responsible for deleting the space after the call processing is completed.
 According to the above method of the present invention, in the case of TLV decoding, the upper layer call in step 6 is responsible for allocating space for the decoded message, and the decoding module automatically assigns the decoded message to the above space according to the original data structure.
 According to the above method of the present invention, the encoding and decoding module in step 6 encodes and decodes the entire upper-layer application message, and the encoding and decoding module will automatically identify the non-encoding field (including the type field, reserved field, transaction ID field, etc.) at the beginning of the message. Copy these fields as they are.
 It should be noted that any improved method that does not depart from the idea of the present invention belongs to the protection scope of the present invention, and the specific protection scope of the present invention is defined by the claims.