From ec83c6d11ff3487e13dc83aacd6032ffe587ac85 Mon Sep 17 00:00:00 2001 From: "Tim \"S.D.Eagle\" Zeitz" Date: Wed, 17 Oct 2018 09:58:52 +0200 Subject: [PATCH] implement decode vector --- src/bin/decode_vector.rs | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/bin/decode_vector.rs 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); + } +} -- 2.34.1