2 Star 1 Fork 0

abulo/nghttp2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mkstatichdtbl.py 958 Bytes
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This scripts reads static table entries [1] and generates
# nghttp2_hd_static_entry table. This table is used in
# lib/nghttp2_hd.c.
#
# [1] http://http2.github.io/http2-spec/compression.html
from __future__ import unicode_literals
import re, sys
def hd_map_hash(name):
h = 2166136261
# FNV hash variant: http://isthe.com/chongo/tech/comp/fnv/
for c in name:
h ^= ord(c)
h *= 16777619
h &= 0xffffffff
return h
entries = []
for line in sys.stdin:
m = re.match(r'(\d+)\s+(\S+)\s+(\S.*)?', line)
val = m.group(3).strip() if m.group(3) else ''
entries.append((int(m.group(1)), m.group(2), val))
print 'static nghttp2_hd_entry static_table[] = {'
idx = 0
for i, ent in enumerate(entries):
if entries[idx][1] != ent[1]:
idx = i
print 'MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\
.format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1]))
print '};'
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/abulo_hoo/nghttp2.git
[email protected]:abulo_hoo/nghttp2.git
abulo_hoo
nghttp2
nghttp2
master

搜索帮助