michael@0: # This script exists to auto-generate Http2HuffmanOutgoing.h from the table michael@0: # contained in the HPACK spec. It's pretty simple to run: michael@0: # python make_outgoing_tables.py < http2_huffman_table.txt > Http2HuffmanOutgoing.h michael@0: # where huff_outgoing.txt is copy/pasted text from the latest version of the michael@0: # HPACK spec, with all non-relevant lines removed (the most recent version michael@0: # of huff_outgoing.txt also lives in this directory as an example). michael@0: import sys michael@0: michael@0: sys.stdout.write('''/* michael@0: * THIS FILE IS AUTO-GENERATED. DO NOT EDIT! michael@0: */ michael@0: #ifndef mozilla__net__Http2HuffmanOutgoing_h michael@0: #define mozilla__net__Http2HuffmanOutgoing_h michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: struct HuffmanOutgoingEntry { michael@0: uint32_t mValue; michael@0: uint8_t mLength; michael@0: }; michael@0: michael@0: static HuffmanOutgoingEntry HuffmanOutgoing[] = { michael@0: ''') michael@0: michael@0: entries = [] michael@0: for line in sys.stdin: michael@0: line = line.strip() michael@0: obracket = line.rfind('[') michael@0: nbits = int(line[obracket + 1:-1]) michael@0: michael@0: encend = obracket - 1 michael@0: hexits = nbits / 4 michael@0: if hexits * 4 != nbits: michael@0: hexits += 1 michael@0: michael@0: enc = line[encend - hexits:encend] michael@0: val = int(enc, 16) michael@0: michael@0: entries.append({'length': nbits, 'value': val}) michael@0: michael@0: line = [] michael@0: for i, e in enumerate(entries): michael@0: sys.stdout.write(' { 0x%08x, %s }' % michael@0: (e['value'], e['length'])) michael@0: if i < (len(entries) - 1): michael@0: sys.stdout.write(',') michael@0: sys.stdout.write('\n') michael@0: michael@0: sys.stdout.write('''}; michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla__net__Http2HuffmanOutgoing_h michael@0: ''')