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