parse/
parse.rs

1//! The example will print out the source code for the ENCODE_TABLE constant
2//! which is provided by this crate through the `encode::table` module.
3
4extern crate httlib_huffman;
5
6use std::fs;
7use std::path::Path;
8use httlib_huffman::parser::parse;
9
10fn main() {
11    let path = Path::new("assets/hpack-huffman.txt");
12    let data = fs::read_to_string(path).expect("Can't read file.");
13    let codings = parse(&data);
14
15    println!("");
16    println!("/// This is a static Huffman table built from the codes found in the official");
17    println!("/// HPACK specification (Appendix B).");
18    println!("pub const ENCODE_TABLE: [(u8, u32); 257] = [ // (length, msb)");
19    for (i, coding) in codings.iter().enumerate() {
20        if i > 0 {
21            println!(",")
22        }
23        print!("  ({}, 0x{:02x})", coding.0, coding.1);
24    }
25    println!("");
26    println!("];");
27    println!("");
28}