I wanna read/parse a data file mixed binary/text. This file isn't utf_8 format and can't be converted.
The structure of the header of my data file is :
#[derive(Debug)]
Struct DataParse{
file_num : u16{2},
file_name: char{16},
file_size: u32{4},
file_off: u32{4},
file_dum: u8{1}
}
I use io::Cursor with the memory buffer and the crate byteorder to operate on my file :
use std::io;
use std::io::prelude::*;
use std::fs::File;
use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt};
use std::io::Cursor;
fn read_parse_file(path_of_file: &str) -> io::Result<()> {
let path = Path::new(&path_of_file);
let display = path.display();
println!("xxx : {}", &display);
let mut f = File::open(&path)?;
let mut buffer = vec![0; 27];
f.read_exact(&mut buffer).unwrap();
let mut vec_pointer = Cursor::new(buffer);
let filenum = vec_pointer.read_u16::<LittleEndian>().unwrap();
let filename = // ?????????
let filesize = vec_pointer.read_u32::<LittleEndian>().unwrap();
let fileoff = vec_pointer.read_u32::<LittleEndian>().unwrap();
let filendum = vec_pointer.read_u8().unwrap();
let dat_binary = DataParse {file_num: filenum, file_name: filename, file_size: filesize, file_off: fileoff, file_dum: filendum };
println!("{:?}", dat_binary);
Ok(())
}
My question is, how get "Struct file_name" of char type in a mixed binary/text in my case?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…