|
1 # This script exists to auto-generate Http2HuffmanOutgoing.h from the table |
|
2 # contained in the HPACK spec. It's pretty simple to run: |
|
3 # python make_outgoing_tables.py < http2_huffman_table.txt > Http2HuffmanOutgoing.h |
|
4 # where huff_outgoing.txt is copy/pasted text from the latest version of the |
|
5 # HPACK spec, with all non-relevant lines removed (the most recent version |
|
6 # of huff_outgoing.txt also lives in this directory as an example). |
|
7 import sys |
|
8 |
|
9 sys.stdout.write('''/* |
|
10 * THIS FILE IS AUTO-GENERATED. DO NOT EDIT! |
|
11 */ |
|
12 #ifndef mozilla__net__Http2HuffmanOutgoing_h |
|
13 #define mozilla__net__Http2HuffmanOutgoing_h |
|
14 |
|
15 namespace mozilla { |
|
16 namespace net { |
|
17 |
|
18 struct HuffmanOutgoingEntry { |
|
19 uint32_t mValue; |
|
20 uint8_t mLength; |
|
21 }; |
|
22 |
|
23 static HuffmanOutgoingEntry HuffmanOutgoing[] = { |
|
24 ''') |
|
25 |
|
26 entries = [] |
|
27 for line in sys.stdin: |
|
28 line = line.strip() |
|
29 obracket = line.rfind('[') |
|
30 nbits = int(line[obracket + 1:-1]) |
|
31 |
|
32 encend = obracket - 1 |
|
33 hexits = nbits / 4 |
|
34 if hexits * 4 != nbits: |
|
35 hexits += 1 |
|
36 |
|
37 enc = line[encend - hexits:encend] |
|
38 val = int(enc, 16) |
|
39 |
|
40 entries.append({'length': nbits, 'value': val}) |
|
41 |
|
42 line = [] |
|
43 for i, e in enumerate(entries): |
|
44 sys.stdout.write(' { 0x%08x, %s }' % |
|
45 (e['value'], e['length'])) |
|
46 if i < (len(entries) - 1): |
|
47 sys.stdout.write(',') |
|
48 sys.stdout.write('\n') |
|
49 |
|
50 sys.stdout.write('''}; |
|
51 |
|
52 } // namespace net |
|
53 } // namespace mozilla |
|
54 |
|
55 #endif // mozilla__net__Http2HuffmanOutgoing_h |
|
56 ''') |