Loading...
Searching...
No Matches
Data Structures
huffman.h File Reference

Huffman tables (QPACK only) (headers) More...

#include <stdint.h>
#include <glib.h>
Include dependency graph for huffman.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  imquic_huffman_table
 Ascii symbol and its length in bits as Huffman code, relatively to the current level. More...
 
struct  imquic_huffman_bits
 Huffman code and its length in bits as Huffman code, mapped to the related ascii code. More...
 

Huffman decoding

typedef struct imquic_huffman_table imquic_huffman_table
 Ascii symbol and its length in bits as Huffman code, relatively to the current level.
 
imquic_huffman_table level0_root [256]
 Root level of parsing (first byte)
 
imquic_huffman_table level0_11111110 [256]
 Second level of parsing (second byte), if the first byte was 11111110.
 
imquic_huffman_table level0_11111111 [256]
 Second level of parsing (second byte), if the first byte was 11111111.
 
imquic_huffman_table level0_11111111_11111110 [256]
 Third level of parsing (third byte), if the second byte was 11111110.
 
imquic_huffman_table level0_11111111_11111111 [256]
 Third level of parsing (third byte), if the second byte was 11111111.
 
imquic_huffman_table level0_11111111_11111111_11110110 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11110110.
 
imquic_huffman_table level0_11111111_11111111_11110111 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11110111.
 
imquic_huffman_table level0_11111111_11111111_11111000 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111000.
 
imquic_huffman_table level0_11111111_11111111_11111001 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111001.
 
imquic_huffman_table level0_11111111_11111111_11111010 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111010.
 
imquic_huffman_table level0_11111111_11111111_11111011 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111011.
 
imquic_huffman_table level0_11111111_11111111_11111100 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111100.
 
imquic_huffman_table level0_11111111_11111111_11111101 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111101.
 
imquic_huffman_table level0_11111111_11111111_11111110 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111110.
 
imquic_huffman_table level0_11111111_11111111_11111111 [256]
 Fourth level of parsing (fourth byte), if the third byte was 11111111.
 
imquic_huffman_tableimquic_huffman_transitions [16]
 Map of transitions, to allow moving from one table to another at different levels.
 

Huffman encoding

typedef struct imquic_huffman_bits imquic_huffman_bits
 Huffman code and its length in bits as Huffman code, mapped to the related ascii code.
 
imquic_huffman_bits table []
 Table mapping each ascii code to its Huffman code representation.
 

Detailed Description

Huffman tables (QPACK only) (headers)

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Naive implementation of Huffman tables, used for quick encoding and decoding by the QPACK part of our basic HTTP/3 stack.

The decoder works by processing the incoming bitstream 8 bits at a time, and so in bytes. This is inspired by different blog posts, most importantly this one explaining the reasoning behind LWAN's decoder implementation. Using a bitstream reader, we can peek 8 bits at a time, and then look for the related imquic_huffman_table instance in the root table: if we get a symbol right away, we return that and consume its size in bits from the bitstream: if we're redirected to another table, because the Huffman code uses more than 8 bits, we read 8 more bits and try to find a match in the related table; and so on and so forth. Redirecting to a different table is done by using negative values in the num_bits property, which removing the sign act as keys to our transitions map in imquic_huffman_transitions.

Encoding uses a single table, instead, where we look for the imquic_huffman_bits instance mapped to the ascii symbol we want to encode. That instance contains both a hex representation of the Huffman code, and how many bits we should actually write, which we can then pass to a bitstream writer for the purpose. The last byte is padded with a sequence of up to 7 1 to act as an EOS.

Typedef Documentation

◆ imquic_huffman_bits

typedef struct imquic_huffman_bits imquic_huffman_bits

Huffman code and its length in bits as Huffman code, mapped to the related ascii code.

◆ imquic_huffman_table

typedef struct imquic_huffman_table imquic_huffman_table

Ascii symbol and its length in bits as Huffman code, relatively to the current level.

Variable Documentation

◆ imquic_huffman_transitions

imquic_huffman_table* imquic_huffman_transitions[16]

Map of transitions, to allow moving from one table to another at different levels.

◆ level0_11111110

imquic_huffman_table level0_11111110[256]
Initial value:
= {
[0 ... 63] = { 33, 2},
[64 ... 127] = { 34, 2},
[128 ... 191] = { 40, 2},
[192 ... 255] = { 41, 2},
}

Second level of parsing (second byte), if the first byte was 11111110.

◆ level0_11111111

imquic_huffman_table level0_11111111[256]
Initial value:
= {
[0 ... 63] = { 63, 2},
[64 ... 95] = { 39, 3},
[96 ... 127] = { 43, 3},
[128 ... 159] = { 124, 3},
[160 ... 175] = { 35, 4},
[176 ... 191] = { 62, 4},
[192 ... 199] = { 0, 5},
[200 ... 207] = { 36, 5},
[208 ... 215] = { 64, 5},
[216 ... 223] = { 91, 5},
[224 ... 231] = { 93, 5},
[232 ... 239] = { 126, 5},
[240 ... 243] = { 94, 6},
[244 ... 247] = { 125, 6},
[248 ... 249] = { 60, 7},
[250 ... 251] = { 96, 7},
[252 ... 253] = { 123, 7},
[254] = { 0, -3},
[255] = { 0, -4},
}

Second level of parsing (second byte), if the first byte was 11111111.

◆ level0_11111111_11111110

imquic_huffman_table level0_11111111_11111110[256]
Initial value:
= {
[0 ... 31] = { 92, 3},
[32 ... 63] = { 195, 3},
[64 ... 95] = { 208, 3},
[96 ... 111] = { 128, 4},
[112 ... 127] = { 130, 4},
[128 ... 143] = { 131, 4},
[144 ... 159] = { 162, 4},
[160 ... 175] = { 184, 4},
[176 ... 191] = { 194, 4},
[192 ... 207] = { 224, 4},
[208 ... 223] = { 226, 4},
[224 ... 231] = { 153, 5},
[232 ... 239] = { 161, 5},
[240 ... 247] = { 167, 5},
[248 ... 255] = { 172, 5},
}

Third level of parsing (third byte), if the second byte was 11111110.

◆ level0_11111111_11111111

imquic_huffman_table level0_11111111_11111111[256]

Third level of parsing (third byte), if the second byte was 11111111.

◆ level0_11111111_11111111_11110110

imquic_huffman_table level0_11111111_11111111_11110110[256]
Initial value:
= {
[0 ... 127] = { 199, 1},
[128 ... 255] = { 207, 1},
}

Fourth level of parsing (fourth byte), if the third byte was 11110110.

◆ level0_11111111_11111111_11110111

imquic_huffman_table level0_11111111_11111111_11110111[256]
Initial value:
= {
[0 ... 127] = { 234, 1},
[128 ... 255] = { 235, 1},
}

Fourth level of parsing (fourth byte), if the third byte was 11110111.

◆ level0_11111111_11111111_11111000

imquic_huffman_table level0_11111111_11111111_11111000[256]
Initial value:
= {
[0 ... 63] = { 192, 2},
[64 ... 127] = { 193, 2},
[128 ... 191] = { 200, 2},
[192 ... 255] = { 201, 2},
}

Fourth level of parsing (fourth byte), if the third byte was 11111000.

◆ level0_11111111_11111111_11111001

imquic_huffman_table level0_11111111_11111111_11111001[256]
Initial value:
= {
[0 ... 63] = { 202, 2},
[64 ... 127] = { 205, 2},
[128 ... 191] = { 210, 2},
[192 ... 255] = { 213, 2},
}

Fourth level of parsing (fourth byte), if the third byte was 11111001.

◆ level0_11111111_11111111_11111010

imquic_huffman_table level0_11111111_11111111_11111010[256]
Initial value:
= {
[0 ... 63] = { 218, 2},
[64 ... 127] = { 219, 2},
[128 ... 191] = { 238, 2},
[192 ... 255] = { 240, 2},
}

Fourth level of parsing (fourth byte), if the third byte was 11111010.

◆ level0_11111111_11111111_11111011

imquic_huffman_table level0_11111111_11111111_11111011[256]
Initial value:
= {
[0 ... 63] = { 242, 2},
[64 ... 127] = { 243, 2},
[128 ... 191] = { 255, 2},
[192 ... 223] = { 203, 3},
[224 ... 255] = { 204, 3},
}

Fourth level of parsing (fourth byte), if the third byte was 11111011.

◆ level0_11111111_11111111_11111100

imquic_huffman_table level0_11111111_11111111_11111100[256]
Initial value:
= {
[0 ... 31] = { 211, 3},
[32 ... 63] = { 212, 3},
[64 ... 95] = { 214, 3},
[96 ... 127] = { 221, 3},
[128 ... 159] = { 222, 3},
[160 ... 191] = { 223, 3},
[192 ... 223] = { 241, 3},
[224 ... 255] = { 244, 3},
}

Fourth level of parsing (fourth byte), if the third byte was 11111100.

◆ level0_11111111_11111111_11111101

imquic_huffman_table level0_11111111_11111111_11111101[256]
Initial value:
= {
[0 ... 31] = { 245, 3},
[32 ... 63] = { 246, 3},
[64 ... 95] = { 247, 3},
[96 ... 127] = { 248, 3},
[128 ... 159] = { 250, 3},
[160 ... 191] = { 251, 3},
[192 ... 223] = { 252, 3},
[224 ... 255] = { 253, 3},
}

Fourth level of parsing (fourth byte), if the third byte was 11111101.

◆ level0_11111111_11111111_11111110

imquic_huffman_table level0_11111111_11111111_11111110[256]
Initial value:
= {
[0 ... 31] = { 254, 3},
[32 ... 47] = { 2, 4},
[48 ... 63] = { 3, 4},
[64 ... 79] = { 4, 4},
[80 ... 95] = { 5, 4},
[96 ... 111] = { 6, 4},
[112 ... 127] = { 7, 4},
[128 ... 143] = { 8, 4},
[144 ... 159] = { 11, 4},
[160 ... 175] = { 12, 4},
[176 ... 191] = { 14, 4},
[192 ... 207] = { 15, 4},
[208 ... 223] = { 16, 4},
[224 ... 239] = { 17, 4},
[240 ... 255] = { 18, 4},
}

Fourth level of parsing (fourth byte), if the third byte was 11111110.

◆ level0_11111111_11111111_11111111

imquic_huffman_table level0_11111111_11111111_11111111[256]
Initial value:
= {
[0 ... 15] = { 19, 4},
[16 ... 31] = { 20, 4},
[32 ... 47] = { 21, 4},
[48 ... 63] = { 23, 4},
[64 ... 79] = { 24, 4},
[80 ... 95] = { 25, 4},
[96 ... 111] = { 26, 4},
[112 ... 127] = { 27, 4},
[128 ... 143] = { 28, 4},
[144 ... 159] = { 29, 4},
[160 ... 175] = { 30, 4},
[176 ... 191] = { 31, 4},
[192 ... 207] = { 127, 4},
[208 ... 223] = { 220, 4},
[224 ... 239] = { 249, 4},
[240 ... 243] = { 10, 6},
[244 ... 247] = { 13, 6},
[248 ... 251] = { 22, 6},
[252 ... 255] = { 0, -15},
}

Fourth level of parsing (fourth byte), if the third byte was 11111111.

◆ level0_root

imquic_huffman_table level0_root[256]

Root level of parsing (first byte)

◆ table

Table mapping each ascii code to its Huffman code representation.