# This script exists to auto-generate Http2HuffmanIncoming.h from the table # contained in the HPACK spec. It's pretty simple to run: # python make_incoming_tables.py < http2_huffman_table.txt > Http2HuffmanIncoming.h # where huff_incoming.txt is copy/pasted text from the latest version of the # HPACK spec, with all non-relevant lines removed (the most recent version # of huff_incoming.txt also lives in this directory as an example). import sys
def output_table(table, name_suffix=""):
max_prefix_len = 0 for i, t in enumerate(table): if isinstance(t, dict): if t["prefix_len"] > max_prefix_len:
max_prefix_len = t["prefix_len"] elif t isnotNone:
output_table(t, "%s_%s" % (name_suffix, i))
tablename = "HuffmanIncoming%s" % (name_suffix if name_suffix else"Root",)
entriestable = tablename.replace("HuffmanIncoming", "HuffmanIncomingEntries")
nexttable = tablename.replace("HuffmanIncoming", "HuffmanIncomingNextTables")
sys.stdout.write("static const HuffmanIncomingEntry %s[] = {\n" % (entriestable,))
prefix_len = 0
value = 0
i = 0 while i < 256:
t = table[i] if isinstance(t, dict):
value = t["value"]
prefix_len = t["prefix_len"] elif t isnotNone: break
sys.stdout.write( """/*
* THIS FILE IS AUTO-GENERATED. DO NOT EDIT!
*/ #ifndef mozilla__net__Http2HuffmanIncoming_h #define mozilla__net__Http2HuffmanIncoming_h
namespace mozilla {
namespace net {
struct HuffmanIncomingTable;
struct HuffmanIncomingEntry {
uint16_t mValue:9; // 9 bits so it can hold 0..256
uint16_t mPrefixLen:7; // only holds 1..8
};
// The data members are public only so they can be statically constructed. All
// accesses should be done through the functions.
struct HuffmanIncomingTable {
// The normal entries, for indices in the range 0..(mNumEntries-1).
const HuffmanIncomingEntry* const mEntries;
// The next tables, for indices in the range mNumEntries..255. Must be
// |nullptr| if mIndexOfFirstNextTable is 256.
const HuffmanIncomingTable** const mNextTables;
// The index of the first next table (equal to the number of entries in
// mEntries). This cannot be a uint8_t because it can have the value 256,
// in which case there are no next tables and mNextTables must be |nullptr|.
const uint16_t mIndexOfFirstNextTable;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.