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).
7import sys
8
9sys.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
15namespace mozilla {
16namespace net {
17
18struct HuffmanOutgoingEntry {
19  uint32_t mValue;
20  uint8_t mLength;
21};
22
23static const HuffmanOutgoingEntry HuffmanOutgoing[] = {
24''')
25
26entries = []
27for line in sys.stdin:
28    line = line.strip()
29    obracket = line.rfind('[')
30    nbits = int(line[obracket + 1:-1])
31
32    lastbar = line.rfind('|')
33    space = line.find(' ', lastbar)
34    encend = line.rfind(' ', 0, obracket)
35
36    enc = line[space:encend].strip()
37    val = int(enc, 16)
38
39    entries.append({'length': nbits, 'value': val})
40
41line = []
42for i, e in enumerate(entries):
43    sys.stdout.write('  { 0x%08x, %s }' %
44                     (e['value'], e['length']))
45    if i < (len(entries) - 1):
46        sys.stdout.write(',')
47    sys.stdout.write('\n')
48
49sys.stdout.write('''};
50
51} // namespace net
52} // namespace mozilla
53
54#endif // mozilla__net__Http2HuffmanOutgoing_h
55''')
56