netwerk/protocol/http/make_outgoing_tables.py

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 # This script exists to auto-generate Http2HuffmanOutgoing.h from the table
michael@0 2 # contained in the HPACK spec. It's pretty simple to run:
michael@0 3 # python make_outgoing_tables.py < http2_huffman_table.txt > Http2HuffmanOutgoing.h
michael@0 4 # where huff_outgoing.txt is copy/pasted text from the latest version of the
michael@0 5 # HPACK spec, with all non-relevant lines removed (the most recent version
michael@0 6 # of huff_outgoing.txt also lives in this directory as an example).
michael@0 7 import sys
michael@0 8
michael@0 9 sys.stdout.write('''/*
michael@0 10 * THIS FILE IS AUTO-GENERATED. DO NOT EDIT!
michael@0 11 */
michael@0 12 #ifndef mozilla__net__Http2HuffmanOutgoing_h
michael@0 13 #define mozilla__net__Http2HuffmanOutgoing_h
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace net {
michael@0 17
michael@0 18 struct HuffmanOutgoingEntry {
michael@0 19 uint32_t mValue;
michael@0 20 uint8_t mLength;
michael@0 21 };
michael@0 22
michael@0 23 static HuffmanOutgoingEntry HuffmanOutgoing[] = {
michael@0 24 ''')
michael@0 25
michael@0 26 entries = []
michael@0 27 for line in sys.stdin:
michael@0 28 line = line.strip()
michael@0 29 obracket = line.rfind('[')
michael@0 30 nbits = int(line[obracket + 1:-1])
michael@0 31
michael@0 32 encend = obracket - 1
michael@0 33 hexits = nbits / 4
michael@0 34 if hexits * 4 != nbits:
michael@0 35 hexits += 1
michael@0 36
michael@0 37 enc = line[encend - hexits:encend]
michael@0 38 val = int(enc, 16)
michael@0 39
michael@0 40 entries.append({'length': nbits, 'value': val})
michael@0 41
michael@0 42 line = []
michael@0 43 for i, e in enumerate(entries):
michael@0 44 sys.stdout.write(' { 0x%08x, %s }' %
michael@0 45 (e['value'], e['length']))
michael@0 46 if i < (len(entries) - 1):
michael@0 47 sys.stdout.write(',')
michael@0 48 sys.stdout.write('\n')
michael@0 49
michael@0 50 sys.stdout.write('''};
michael@0 51
michael@0 52 } // namespace net
michael@0 53 } // namespace mozilla
michael@0 54
michael@0 55 #endif // mozilla__net__Http2HuffmanOutgoing_h
michael@0 56 ''')

mercurial