make_outgoing_tables.py (1473B)
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 """/* 11 * THIS FILE IS AUTO-GENERATED. DO NOT EDIT! 12 */ 13 #ifndef mozilla__net__Http2HuffmanOutgoing_h 14 #define mozilla__net__Http2HuffmanOutgoing_h 15 16 namespace mozilla { 17 namespace net { 18 19 struct HuffmanOutgoingEntry { 20 uint32_t mValue; 21 uint8_t mLength; 22 }; 23 24 static const HuffmanOutgoingEntry HuffmanOutgoing[] = { 25 """ 26 ) 27 28 entries = [] 29 for line in sys.stdin: 30 line = line.strip() 31 obracket = line.rfind("[") 32 nbits = int(line[obracket + 1 : -1]) 33 34 lastbar = line.rfind("|") 35 space = line.find(" ", lastbar) 36 encend = line.rfind(" ", 0, obracket) 37 38 enc = line[space:encend].strip() 39 val = int(enc, 16) 40 41 entries.append({"length": nbits, "value": val}) 42 43 line = [] 44 for i, e in enumerate(entries): 45 sys.stdout.write(" { 0x%08x, %s }" % (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 53 } // namespace net 54 } // namespace mozilla 55 56 #endif // mozilla__net__Http2HuffmanOutgoing_h 57 """ 58 )