make_outgoing_tables.py 1.4 KB

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