3.1.8.1.4.2 Length-of-Match Tables
The length, in bits, for each of the 0 to 31 Huffman-encoded LengthOfMatch codes are listed in the following table (HuffLengthL).
LengthOfMatch Code |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
---|---|---|---|---|---|---|---|---|
0 |
0x4 |
0x2 |
0x3 |
0x4 |
0x3 |
0x4 |
0x4 |
0x5 |
8 |
0x4 |
0x5 |
0x5 |
0x6 |
0x6 |
0x7 |
0x7 |
0x8 |
16 |
0x7 |
0x8 |
0x8 |
0x9 |
0x9 |
0x8 |
0x9 |
0x9 |
24 |
0x9 |
0x9 |
0x9 |
0x9 |
0x9 |
0x9 |
0x9 |
0x9 |
Table 4: Bit lengths for the 32 Huffman-encoded LengthOfMatch codes
For example, it can be determined from the previous table that the 0th Huffman-encoded LengthOfMatch code has a length of 4 bits while the 21st Huffman-encoded LengthOfMatch code has a length of 8 bits.
Using the canonical Huffman algorithm ([SAYOOD] section 4.2.4), the Huffman codebook table shown in the following table (HuffCodeL) can be obtained. The bit lengths in the previous table MUST be used to mask out the appropriate bits.
Code index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
---|---|---|---|---|---|---|---|---|
0 |
0x0001 |
0x0000 |
0x0002 |
0x0009 |
0x0006 |
0x0005 |
0x000d |
0x000b |
8 |
0x0003 |
0x001b |
0x0007 |
0x0017 |
0x0037 |
0x000f |
0x004f |
0x006f |
16 |
0x002f |
0x00ef |
0x001f |
0x005f |
0x015f |
0x009f |
0x00df |
0x01df |
24 |
0x003f |
0x013f |
0x00bf |
0x01bf |
0x007f |
0x017f |
0x00ff |
0x01ff |
Table 5: Huffman codebook for the 32 Huffman-encoded LengthOfMatch codes
For example, it can be determined from the HuffCodeL table that the 0th Huffman-encoded LengthOfMatch code has a value of 0x0001. Applying the bit-length information from the HuffLengthL table, it can be determined that the Huffman code MUST be 4 bits in length. Hence the final code in binary MUST be 0001.
As another example, it can be determined from the HuffCodeL table that the 21st Huffman-encoded LengthOfMatch code has a value of 0x009f. Applying the bit-length information from the HuffLengthL table, it can be determined that the Huffman code MUST be 8 bits in length. Hence the final code in binary MUST be 10011111.
The two lookup tables in the following table (LoMBitsLUT and LoMBaseLUT) are used during encoding and decoding of the length-of-match for a given copy-tuple to determine the extra bits that will follow the LengthOfMatch code. Note that the minimum match length that can be encoded is 2, as opposed to RDP 4.0 and 5.0 bulk data compression where the minimum is 3 (see [MS-RDPBCGR] sections 3.1.8.2 and 3.1.8.4.1.2.2).
Index |
LoMBitsLUT |
LoMBaseLUT |
---|---|---|
0 |
0 |
2 |
1 |
0 |
3 |
2 |
0 |
4 |
3 |
0 |
5 |
4 |
0 |
6 |
5 |
0 |
7 |
6 |
0 |
8 |
7 |
0 |
9 |
8 |
1 |
10 |
9 |
1 |
12 |
10 |
1 |
14 |
11 |
1 |
16 |
12 |
2 |
18 |
13 |
2 |
22 |
14 |
2 |
26 |
15 |
2 |
30 |
16 |
3 |
34 |
17 |
3 |
42 |
18 |
3 |
50 |
19 |
3 |
58 |
20 |
4 |
66 |
21 |
4 |
82 |
22 |
4 |
98 |
23 |
4 |
114 |
24 |
6 |
130 |
25 |
6 |
194 |
26 |
8 |
258 |
27 |
8 |
514 |
28 |
14 |
2 |
29 |
14 |
2 |
Table 6: Bit count and base value lookup tables to encode and decode length-of-match values