| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use XML::LibXML; |
| 7 |
|
| 8 |
sub usage { |
| 9 |
"Usage: $0 draft-ietf-httpbis-header-compression.xml\n"; |
| 10 |
} |
| 11 |
|
| 12 |
my $file = $ARGV[0] or die usage; |
| 13 |
die usage unless -f $file; |
| 14 |
|
| 15 |
open my $fh, '<', $file or die $!; |
| 16 |
my $doc = XML::LibXML->load_xml( IO => $fh ); |
| 17 |
my $hufftable = |
| 18 |
XML::LibXML::XPathExpression->new( |
| 19 |
'//section[@title="Huffman Code"]//artwork'); |
| 20 |
my $value = $doc->findvalue($hufftable); |
| 21 |
die "cant find Huffman Codes section" unless $value; |
| 22 |
|
| 23 |
print << 'EOF'; |
| 24 |
package Protocol::HTTP2::HuffmanCodes; |
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
require Exporter; |
| 28 |
our @ISA = qw(Exporter); |
| 29 |
our ( %hcodes, %rhcodes, $hre ); |
| 30 |
our @EXPORT = qw(%hcodes %rhcodes $hre); |
| 31 |
|
| 32 |
%hcodes = ( |
| 33 |
EOF |
| 34 |
|
| 35 |
for ( split /\n/, $value ) { |
| 36 |
my ( $code, $hex, $bit ) = (/\((.{3})\).+\s([0-9a-f]+)\s+\[\s*(\d+)\]/) |
| 37 |
or next; |
| 38 |
printf " %3d => '%0${bit}b',\n", $code, hex($hex); |
| 39 |
} |
| 40 |
|
| 41 |
print << 'EOF'; |
| 42 |
); |
| 43 |
|
| 44 |
%rhcodes = reverse %hcodes; |
| 45 |
|
| 46 |
{ |
| 47 |
local $" = '|'; |
| 48 |
$hre = qr/(?:^|\G)(@{[ keys %rhcodes ]})/; |
| 49 |
} |
| 50 |
|
| 51 |
1; |
| 52 |
EOF |
| 53 |
|