3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """This script builds a table that has to be manully inserted into
8 net/spdy/hpack_constants.cc. It also contains data that potentially
9 has to be updated if the http hpack algorithm changes its
15 # http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08
16 # It may include dummy rows as long as those don't look too much like real
18 SPEC_DATA_DRAFT_08
= r
"""
20 code as bits as hex len
21 sym aligned to MSB aligned in
23 ( 0) |11111111|11000 1ff8 [13]
24 ( 1) |11111111|11111111|1011000 7fffd8 [23]
25 ( 2) |11111111|11111111|11111110|0010 fffffe2 [28]
26 ( 3) |11111111|11111111|11111110|0011 fffffe3 [28]
27 ( 4) |11111111|11111111|11111110|0100 fffffe4 [28]
28 ( 5) |11111111|11111111|11111110|0101 fffffe5 [28]
29 ( 6) |11111111|11111111|11111110|0110 fffffe6 [28]
30 ( 7) |11111111|11111111|11111110|0111 fffffe7 [28]
31 ( 8) |11111111|11111111|11111110|1000 fffffe8 [28]
32 ( 9) |11111111|11111111|11101010 ffffea [24]
33 ( 10) |11111111|11111111|11111111|111100 3ffffffc [30]
34 ( 11) |11111111|11111111|11111110|1001 fffffe9 [28]
35 ( 12) |11111111|11111111|11111110|1010 fffffea [28]
36 ( 13) |11111111|11111111|11111111|111101 3ffffffd [30]
37 ( 14) |11111111|11111111|11111110|1011 fffffeb [28]
38 ( 15) |11111111|11111111|11111110|1100 fffffec [28]
39 ( 16) |11111111|11111111|11111110|1101 fffffed [28]
40 ( 17) |11111111|11111111|11111110|1110 fffffee [28]
41 ( 18) |11111111|11111111|11111110|1111 fffffef [28]
42 ( 19) |11111111|11111111|11111111|0000 ffffff0 [28]
43 ( 20) |11111111|11111111|11111111|0001 ffffff1 [28]
44 ( 21) |11111111|11111111|11111111|0010 ffffff2 [28]
45 ( 22) |11111111|11111111|11111111|111110 3ffffffe [30]
46 ( 23) |11111111|11111111|11111111|0011 ffffff3 [28]
47 ( 24) |11111111|11111111|11111111|0100 ffffff4 [28]
48 ( 25) |11111111|11111111|11111111|0101 ffffff5 [28]
49 ( 26) |11111111|11111111|11111111|0110 ffffff6 [28]
50 ( 27) |11111111|11111111|11111111|0111 ffffff7 [28]
51 ( 28) |11111111|11111111|11111111|1000 ffffff8 [28]
52 ( 29) |11111111|11111111|11111111|1001 ffffff9 [28]
53 ( 30) |11111111|11111111|11111111|1010 ffffffa [28]
54 ( 31) |11111111|11111111|11111111|1011 ffffffb [28]
55 ' ' ( 32) |010100 14 [ 6]
56 '!' ( 33) |11111110|00 3f8 [10]
57 '"' ( 34) |11111110|01 3f9 [10]
58 '#' ( 35) |11111111|1010 ffa [12]
59 '$' ( 36) |11111111|11001 1ff9 [13]
60 '%' ( 37) |010101 15 [ 6]
61 '&' ( 38) |11111000 f8 [ 8]
62 ''' ( 39) |11111111|010 7fa [11]
63 '(' ( 40) |11111110|10 3fa [10]
64 ')' ( 41) |11111110|11 3fb [10]
65 '*' ( 42) |11111001 f9 [ 8]
66 '+' ( 43) |11111111|011 7fb [11]
67 ',' ( 44) |11111010 fa [ 8]
68 '-' ( 45) |010110 16 [ 6]
69 '.' ( 46) |010111 17 [ 6]
70 '/' ( 47) |011000 18 [ 6]
71 '0' ( 48) |00000 0 [ 5]
72 '1' ( 49) |00001 1 [ 5]
73 '2' ( 50) |00010 2 [ 5]
74 '3' ( 51) |011001 19 [ 6]
75 '4' ( 52) |011010 1a [ 6]
76 '5' ( 53) |011011 1b [ 6]
77 '6' ( 54) |011100 1c [ 6]
78 '7' ( 55) |011101 1d [ 6]
79 '8' ( 56) |011110 1e [ 6]
80 '9' ( 57) |011111 1f [ 6]
81 ':' ( 58) |1011100 5c [ 7]
82 ';' ( 59) |11111011 fb [ 8]
83 '<' ( 60) |11111111|1111100 7ffc [15]
84 '=' ( 61) |100000 20 [ 6]
85 '>' ( 62) |11111111|1011 ffb [12]
86 '?' ( 63) |11111111|00 3fc [10]
87 '@' ( 64) |11111111|11010 1ffa [13]
88 'A' ( 65) |100001 21 [ 6]
89 'B' ( 66) |1011101 5d [ 7]
90 'C' ( 67) |1011110 5e [ 7]
91 'D' ( 68) |1011111 5f [ 7]
92 'E' ( 69) |1100000 60 [ 7]
93 'F' ( 70) |1100001 61 [ 7]
94 'G' ( 71) |1100010 62 [ 7]
95 'H' ( 72) |1100011 63 [ 7]
96 'I' ( 73) |1100100 64 [ 7]
97 'J' ( 74) |1100101 65 [ 7]
98 'K' ( 75) |1100110 66 [ 7]
99 'L' ( 76) |1100111 67 [ 7]
100 'M' ( 77) |1101000 68 [ 7]
101 'N' ( 78) |1101001 69 [ 7]
102 'O' ( 79) |1101010 6a [ 7]
103 'P' ( 80) |1101011 6b [ 7]
104 'Q' ( 81) |1101100 6c [ 7]
105 'R' ( 82) |1101101 6d [ 7]
106 'S' ( 83) |1101110 6e [ 7]
107 'T' ( 84) |1101111 6f [ 7]
108 'U' ( 85) |1110000 70 [ 7]
109 'V' ( 86) |1110001 71 [ 7]
110 'W' ( 87) |1110010 72 [ 7]
111 'X' ( 88) |11111100 fc [ 8]
112 'Y' ( 89) |1110011 73 [ 7]
113 'Z' ( 90) |11111101 fd [ 8]
114 '[' ( 91) |11111111|11011 1ffb [13]
115 '\' ( 92) |11111111|11111110|000 7fff0 [19]
116 ']' ( 93) |11111111|11100 1ffc [13]
117 '^' ( 94) |11111111|111100 3ffc [14]
118 '_' ( 95) |100010 22 [ 6]
119 '`' ( 96) |11111111|1111101 7ffd [15]
120 'a' ( 97) |00011 3 [ 5]
121 'b' ( 98) |100011 23 [ 6]
122 'c' ( 99) |00100 4 [ 5]
123 'd' (100) |100100 24 [ 6]
124 'e' (101) |00101 5 [ 5]
125 'f' (102) |100101 25 [ 6]
126 'g' (103) |100110 26 [ 6]
127 'h' (104) |100111 27 [ 6]
128 'i' (105) |00110 6 [ 5]
129 'j' (106) |1110100 74 [ 7]
130 'k' (107) |1110101 75 [ 7]
131 'l' (108) |101000 28 [ 6]
132 'm' (109) |101001 29 [ 6]
133 'n' (110) |101010 2a [ 6]
134 'o' (111) |00111 7 [ 5]
135 'p' (112) |101011 2b [ 6]
136 'q' (113) |1110110 76 [ 7]
137 'r' (114) |101100 2c [ 6]
138 's' (115) |01000 8 [ 5]
139 't' (116) |01001 9 [ 5]
140 'u' (117) |101101 2d [ 6]
141 'v' (118) |1110111 77 [ 7]
142 'w' (119) |1111000 78 [ 7]
143 'x' (120) |1111001 79 [ 7]
144 'y' (121) |1111010 7a [ 7]
145 'z' (122) |1111011 7b [ 7]
146 '{' (123) |11111111|1111110 7ffe [15]
147 '|' (124) |11111111|100 7fc [11]
148 '}' (125) |11111111|111101 3ffd [14]
149 '~' (126) |11111111|11101 1ffd [13]
150 (127) |11111111|11111111|11111111|1100 ffffffc [28]
151 (128) |11111111|11111110|0110 fffe6 [20]
152 (129) |11111111|11111111|010010 3fffd2 [22]
153 (130) |11111111|11111110|0111 fffe7 [20]
154 (131) |11111111|11111110|1000 fffe8 [20]
155 (132) |11111111|11111111|010011 3fffd3 [22]
156 (133) |11111111|11111111|010100 3fffd4 [22]
157 (134) |11111111|11111111|010101 3fffd5 [22]
158 (135) |11111111|11111111|1011001 7fffd9 [23]
159 (136) |11111111|11111111|010110 3fffd6 [22]
160 (137) |11111111|11111111|1011010 7fffda [23]
161 (138) |11111111|11111111|1011011 7fffdb [23]
162 (139) |11111111|11111111|1011100 7fffdc [23]
163 (140) |11111111|11111111|1011101 7fffdd [23]
164 (141) |11111111|11111111|1011110 7fffde [23]
165 (142) |11111111|11111111|11101011 ffffeb [24]
166 (143) |11111111|11111111|1011111 7fffdf [23]
167 (144) |11111111|11111111|11101100 ffffec [24]
168 (145) |11111111|11111111|11101101 ffffed [24]
169 (146) |11111111|11111111|010111 3fffd7 [22]
170 (147) |11111111|11111111|1100000 7fffe0 [23]
171 (148) |11111111|11111111|11101110 ffffee [24]
172 (149) |11111111|11111111|1100001 7fffe1 [23]
173 (150) |11111111|11111111|1100010 7fffe2 [23]
174 (151) |11111111|11111111|1100011 7fffe3 [23]
175 (152) |11111111|11111111|1100100 7fffe4 [23]
176 (153) |11111111|11111110|11100 1fffdc [21]
177 (154) |11111111|11111111|011000 3fffd8 [22]
178 (155) |11111111|11111111|1100101 7fffe5 [23]
179 (156) |11111111|11111111|011001 3fffd9 [22]
180 (157) |11111111|11111111|1100110 7fffe6 [23]
181 (158) |11111111|11111111|1100111 7fffe7 [23]
182 (159) |11111111|11111111|11101111 ffffef [24]
183 (160) |11111111|11111111|011010 3fffda [22]
184 (161) |11111111|11111110|11101 1fffdd [21]
185 (162) |11111111|11111110|1001 fffe9 [20]
186 (163) |11111111|11111111|011011 3fffdb [22]
187 (164) |11111111|11111111|011100 3fffdc [22]
188 (165) |11111111|11111111|1101000 7fffe8 [23]
189 (166) |11111111|11111111|1101001 7fffe9 [23]
190 (167) |11111111|11111110|11110 1fffde [21]
191 (168) |11111111|11111111|1101010 7fffea [23]
192 (169) |11111111|11111111|011101 3fffdd [22]
193 (170) |11111111|11111111|011110 3fffde [22]
194 (171) |11111111|11111111|11110000 fffff0 [24]
195 (172) |11111111|11111110|11111 1fffdf [21]
196 (173) |11111111|11111111|011111 3fffdf [22]
197 (174) |11111111|11111111|1101011 7fffeb [23]
198 (175) |11111111|11111111|1101100 7fffec [23]
199 (176) |11111111|11111111|00000 1fffe0 [21]
200 (177) |11111111|11111111|00001 1fffe1 [21]
201 (178) |11111111|11111111|100000 3fffe0 [22]
202 (179) |11111111|11111111|00010 1fffe2 [21]
203 (180) |11111111|11111111|1101101 7fffed [23]
204 (181) |11111111|11111111|100001 3fffe1 [22]
205 (182) |11111111|11111111|1101110 7fffee [23]
206 (183) |11111111|11111111|1101111 7fffef [23]
207 (184) |11111111|11111110|1010 fffea [20]
208 (185) |11111111|11111111|100010 3fffe2 [22]
209 (186) |11111111|11111111|100011 3fffe3 [22]
210 (187) |11111111|11111111|100100 3fffe4 [22]
211 (188) |11111111|11111111|1110000 7ffff0 [23]
212 (189) |11111111|11111111|100101 3fffe5 [22]
213 (190) |11111111|11111111|100110 3fffe6 [22]
214 (191) |11111111|11111111|1110001 7ffff1 [23]
215 (192) |11111111|11111111|11111000|00 3ffffe0 [26]
216 (193) |11111111|11111111|11111000|01 3ffffe1 [26]
217 (194) |11111111|11111110|1011 fffeb [20]
218 (195) |11111111|11111110|001 7fff1 [19]
219 (196) |11111111|11111111|100111 3fffe7 [22]
220 (197) |11111111|11111111|1110010 7ffff2 [23]
221 (198) |11111111|11111111|101000 3fffe8 [22]
222 (199) |11111111|11111111|11110110|0 1ffffec [25]
223 (200) |11111111|11111111|11111000|10 3ffffe2 [26]
224 (201) |11111111|11111111|11111000|11 3ffffe3 [26]
225 (202) |11111111|11111111|11111001|00 3ffffe4 [26]
226 (203) |11111111|11111111|11111011|110 7ffffde [27]
227 (204) |11111111|11111111|11111011|111 7ffffdf [27]
228 (205) |11111111|11111111|11111001|01 3ffffe5 [26]
229 (206) |11111111|11111111|11110001 fffff1 [24]
230 (207) |11111111|11111111|11110110|1 1ffffed [25]
231 (208) |11111111|11111110|010 7fff2 [19]
232 (209) |11111111|11111111|00011 1fffe3 [21]
233 (210) |11111111|11111111|11111001|10 3ffffe6 [26]
234 (211) |11111111|11111111|11111100|000 7ffffe0 [27]
235 (212) |11111111|11111111|11111100|001 7ffffe1 [27]
236 (213) |11111111|11111111|11111001|11 3ffffe7 [26]
237 (214) |11111111|11111111|11111100|010 7ffffe2 [27]
238 (215) |11111111|11111111|11110010 fffff2 [24]
239 (216) |11111111|11111111|00100 1fffe4 [21]
240 (217) |11111111|11111111|00101 1fffe5 [21]
241 (218) |11111111|11111111|11111010|00 3ffffe8 [26]
242 (219) |11111111|11111111|11111010|01 3ffffe9 [26]
243 (220) |11111111|11111111|11111111|1101 ffffffd [28]
244 (221) |11111111|11111111|11111100|011 7ffffe3 [27]
245 (222) |11111111|11111111|11111100|100 7ffffe4 [27]
246 (223) |11111111|11111111|11111100|101 7ffffe5 [27]
247 (224) |11111111|11111110|1100 fffec [20]
248 (225) |11111111|11111111|11110011 fffff3 [24]
249 (226) |11111111|11111110|1101 fffed [20]
250 (227) |11111111|11111111|00110 1fffe6 [21]
251 (228) |11111111|11111111|101001 3fffe9 [22]
252 (229) |11111111|11111111|00111 1fffe7 [21]
253 (230) |11111111|11111111|01000 1fffe8 [21]
254 (231) |11111111|11111111|1110011 7ffff3 [23]
255 (232) |11111111|11111111|101010 3fffea [22]
256 (233) |11111111|11111111|101011 3fffeb [22]
257 (234) |11111111|11111111|11110111|0 1ffffee [25]
258 (235) |11111111|11111111|11110111|1 1ffffef [25]
259 (236) |11111111|11111111|11110100 fffff4 [24]
260 (237) |11111111|11111111|11110101 fffff5 [24]
261 (238) |11111111|11111111|11111010|10 3ffffea [26]
262 (239) |11111111|11111111|1110100 7ffff4 [23]
263 (240) |11111111|11111111|11111010|11 3ffffeb [26]
264 (241) |11111111|11111111|11111100|110 7ffffe6 [27]
265 (242) |11111111|11111111|11111011|00 3ffffec [26]
266 (243) |11111111|11111111|11111011|01 3ffffed [26]
267 (244) |11111111|11111111|11111100|111 7ffffe7 [27]
268 (245) |11111111|11111111|11111101|000 7ffffe8 [27]
269 (246) |11111111|11111111|11111101|001 7ffffe9 [27]
270 (247) |11111111|11111111|11111101|010 7ffffea [27]
271 (248) |11111111|11111111|11111101|011 7ffffeb [27]
272 (249) |11111111|11111111|11111111|1110 ffffffe [28]
273 (250) |11111111|11111111|11111101|100 7ffffec [27]
274 (251) |11111111|11111111|11111101|101 7ffffed [27]
275 (252) |11111111|11111111|11111101|110 7ffffee [27]
276 (253) |11111111|11111111|11111101|111 7ffffef [27]
277 (254) |11111111|11111111|11111110|000 7fffff0 [27]
278 (255) |11111111|11111111|11111011|10 3ffffee [26]
279 EOS (256) |11111111|11111111|11111111|111111 3fffffff [30]
283 spec_lines
= SPEC_DATA_DRAFT_08
.splitlines()
286 r
"^\s*('.+'|EOS)? \( *(\d+)\) \|([10\|]+) +\w+ \[ ?(\d+)\]", l
)
290 spec_bitstring
= g
[2]
291 bitstring
= spec_bitstring
.replace('|','').ljust(32,'0')
292 bitvalue
= int(bitstring
, 2)
295 comment
= ' // %s' % spec_bitstring
297 comment
= ' // %3s %s' % (spec_comment
, spec_bitstring
)
299 comment
= ' // %s' % spec_bitstring
300 print(' {0x%08xul, %02s, %03s},%s' % (
301 bitvalue
, bitcount
, valueid
, comment
))
302 assert int(valueid
) == count
, "Expected data for %s, got %s." % (count
,
305 print("Total: %s" % count
)
306 assert count
== 257, "Expected 257 values, got %d." % count