1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/make_outgoing_tables.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +# This script exists to auto-generate Http2HuffmanOutgoing.h from the table 1.5 +# contained in the HPACK spec. It's pretty simple to run: 1.6 +# python make_outgoing_tables.py < http2_huffman_table.txt > Http2HuffmanOutgoing.h 1.7 +# where huff_outgoing.txt is copy/pasted text from the latest version of the 1.8 +# HPACK spec, with all non-relevant lines removed (the most recent version 1.9 +# of huff_outgoing.txt also lives in this directory as an example). 1.10 +import sys 1.11 + 1.12 +sys.stdout.write('''/* 1.13 + * THIS FILE IS AUTO-GENERATED. DO NOT EDIT! 1.14 + */ 1.15 +#ifndef mozilla__net__Http2HuffmanOutgoing_h 1.16 +#define mozilla__net__Http2HuffmanOutgoing_h 1.17 + 1.18 +namespace mozilla { 1.19 +namespace net { 1.20 + 1.21 +struct HuffmanOutgoingEntry { 1.22 + uint32_t mValue; 1.23 + uint8_t mLength; 1.24 +}; 1.25 + 1.26 +static HuffmanOutgoingEntry HuffmanOutgoing[] = { 1.27 +''') 1.28 + 1.29 +entries = [] 1.30 +for line in sys.stdin: 1.31 + line = line.strip() 1.32 + obracket = line.rfind('[') 1.33 + nbits = int(line[obracket + 1:-1]) 1.34 + 1.35 + encend = obracket - 1 1.36 + hexits = nbits / 4 1.37 + if hexits * 4 != nbits: 1.38 + hexits += 1 1.39 + 1.40 + enc = line[encend - hexits:encend] 1.41 + val = int(enc, 16) 1.42 + 1.43 + entries.append({'length': nbits, 'value': val}) 1.44 + 1.45 +line = [] 1.46 +for i, e in enumerate(entries): 1.47 + sys.stdout.write(' { 0x%08x, %s }' % 1.48 + (e['value'], e['length'])) 1.49 + if i < (len(entries) - 1): 1.50 + sys.stdout.write(',') 1.51 + sys.stdout.write('\n') 1.52 + 1.53 +sys.stdout.write('''}; 1.54 + 1.55 +} // namespace net 1.56 +} // namespace mozilla 1.57 + 1.58 +#endif // mozilla__net__Http2HuffmanOutgoing_h 1.59 +''')