aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a54a3bdf2e8375a4a0545a59ba5a438794526a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::env;
// use std::fs;
use std::io;
use std::io::Read;
use std::io::Write;

pub mod tree;
pub mod bits;
pub mod conversion;

use tree::Tree;

fn main() {
    if let Some(s) = env::args().nth(1) {
        if s != "d" {
            return
        }
        // let data: Vec<u8> = io::stdin().bytes().map(|x| x.unwrap()).collect();
        // deserialize

    } else {
        // let f = fs::File::open(file_path).unwrap();

        let data: Vec<u8> = io::stdin().bytes().map(|x| x.unwrap()).collect();

        let tree = Tree::from_data(&data);
        // print!("{:?}", tree);

        let table = conversion::Table::from_tree(&tree);
        // print!("{:?}", table);

        let converted_data = table.convert(data);
        // println!("{:?}", converted_data);

        let header = table.serialize();

        io::stdout().write_all(&header).unwrap();
        io::stdout().write_all(&converted_data).unwrap();
    }
}