Source file commited
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d5f8a7bbbc
commit
27243ee449
|
@ -0,0 +1,25 @@
|
|||
use std::io::{self, BufRead, stdout, Write};
|
||||
|
||||
fn dump_to_bin(line: String) {
|
||||
let words: Vec<&str> = line.split(" ").collect();
|
||||
|
||||
if words.len() == 2 {
|
||||
let iter = words[0].split_whitespace();
|
||||
let data: Vec<&str> = iter.skip(1).collect();
|
||||
let hex: String = data.join("");
|
||||
|
||||
let bytes = hex::decode(hex).unwrap();
|
||||
let u8_values: Vec<u8> = bytes.iter().map(|b| *b).collect();
|
||||
stdout().write_all(&u8_values).expect("Failed to write to stdout");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn revert_hexdump(reader: Box<dyn io::BufRead>) {
|
||||
for buf in reader.lines() {
|
||||
match buf {
|
||||
Ok(line) => { dump_to_bin(line) }
|
||||
Err(_) => { eprintln!("Cannot read input file") }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue