2 # -*- coding: utf-8 -*-
4 # This scripts reads static table entries [1] and generates
5 # nghttp2_hd_static_entry table. This table is used in
8 # [1] http://http2.github.io/http2-spec/compression.html
10 from __future__ import unicode_literals
17 return h & ((1 << 32) - 1)
20 for line in sys.stdin:
21 m = re.match(r'(\d+)\s+(\S+)\s+(\S.*)?', line)
22 val = m.group(3).strip() if m.group(3) else ''
23 entries.append((hash(m.group(2)), int(m.group(1)), m.group(2), val))
27 print '/* Sorted by hash(name) and its table index */'
28 print 'static nghttp2_hd_static_entry static_table[] = {'
30 print 'MAKE_STATIC_ENT({}, "{}", "{}", {}u, {}u),'\
31 .format(ent[1] - 1, ent[2], ent[3], ent[0], hash(ent[3]))
36 print '/* Index to the position in static_table */'
37 print 'const size_t static_table_index[] = {'
38 for i in range(len(entries)):
39 for j, ent in enumerate(entries):
41 sys.stdout.write('{: <2d},'.format(j))
44 sys.stdout.write('\n')