nghttp2/mkstatichdtbl.py

21 lines
530 B
Python
Raw Normal View History

2013-10-15 18:23:10 +02:00
#!/usr/bin/env python
import re, sys
def hash(s):
h = 0
for c in s:
h = h * 31 + ord(c)
return h & ((1 << 32) - 1)
2014-01-07 15:41:09 +01:00
entries = []
2013-10-15 18:23:10 +02:00
for line in sys.stdin:
2014-06-14 15:24:47 +02:00
m = re.match(r'(\d+)\s+(\S+)\s+(\S.*)?', line)
val = m.group(3).strip() if m.group(3) else ''
2014-01-07 15:41:09 +01:00
entries.append((hash(m.group(2)), int(m.group(1)), m.group(2), val))
2014-07-20 12:13:56 +02:00
print 'static nghttp2_hd_entry static_table[] = {'
2014-01-07 15:41:09 +01:00
for ent in entries:
2014-07-20 12:13:56 +02:00
print 'MAKE_ENT("{}", "{}", {}u, {}u),'\
.format(ent[2], ent[3], ent[0], hash(ent[3]))
2014-01-07 15:41:09 +01:00
print '};'