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.)

     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
     9 sys.stdout.write('''/*
    10  * THIS FILE IS AUTO-GENERATED. DO NOT EDIT!
    11  */
    12 #ifndef mozilla__net__Http2HuffmanOutgoing_h
    13 #define mozilla__net__Http2HuffmanOutgoing_h
    15 namespace mozilla {
    16 namespace net {
    18 struct HuffmanOutgoingEntry {
    19   uint32_t mValue;
    20   uint8_t mLength;
    21 };
    23 static HuffmanOutgoingEntry HuffmanOutgoing[] = {
    24 ''')
    26 entries = []
    27 for line in sys.stdin:
    28     line = line.strip()
    29     obracket = line.rfind('[')
    30     nbits = int(line[obracket + 1:-1])
    32     encend = obracket - 1
    33     hexits = nbits / 4
    34     if hexits * 4 != nbits:
    35         hexits += 1
    37     enc = line[encend - hexits:encend]
    38     val = int(enc, 16)
    40     entries.append({'length': nbits, 'value': val})
    42 line = []
    43 for i, e in enumerate(entries):
    44     sys.stdout.write('  { 0x%08x, %s }' %
    45                      (e['value'], e['length']))
    46     if i < (len(entries) - 1):
    47         sys.stdout.write(',')
    48     sys.stdout.write('\n')
    50 sys.stdout.write('''};
    52 } // namespace net
    53 } // namespace mozilla
    55 #endif // mozilla__net__Http2HuffmanOutgoing_h
    56 ''')

mercurial