From: Tim "S.D.Eagle" Zeitz Date: Wed, 17 Oct 2018 07:58:52 +0000 (+0200) Subject: implement decode vector X-Git-Url: https://i11git.iti.kit.edu/anon-gitweb/?p=Mitarbeiter%2FTim-Zeitz%2Fstud-rust-base.git;a=commitdiff_plain;h=ec83c6d11ff3487e13dc83aacd6032ffe587ac85;hp=e561b67a4f184a29efae1cf290e6f9ace3151248;ds=sidebyside implement decode vector --- diff --git a/src/bin/decode_vector.rs b/src/bin/decode_vector.rs new file mode 100644 index 0000000..180804b --- /dev/null +++ b/src/bin/decode_vector.rs @@ -0,0 +1,71 @@ +extern crate stud_rust_base; +use stud_rust_base::io::*; +use std::env; + +fn main() { + let mut args = env::args(); + args.next(); + + match &args.collect::>()[..] { + [data_type, input] => { + match data_type.as_ref() { + "i8" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "u8" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "i16" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "u16" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "i32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "u32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "i64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "u64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "f32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "f64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "int8" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "uint8" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "int16" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "uint16" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "int32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "uint32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "int64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "uint64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "float32" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + "float64" => print_values(Vec::::load_from(input).expect("Failed to read from input")), + _ => { + print_usage(); + panic!("Unknown data_type {}", data_type); + } + }; + }, + _ => { + print_usage(); + panic!("Invalid input") + }, + } +} + +fn print_usage() { + eprintln!("Usage: decode_vector data_type input_vector_file + +Reads binary data from input_vector_file and writes the data to the standard output. data_type can be one of +* i8 +* u8 +* i16 +* u16 +* i32 +* u32 +* i64 +* u64 +* f32 +* f64 + +"); +} + +use std::fmt::Display; + +fn print_values(values: Vec) where + T: Display +{ + for v in values { + println!("{}", v); + } +}