Hello everyone,
I try to read bytes from a file without knowing the number of bytes I have to read at compile time. I explain, the length of the bytes to be read is calculated dynamically. I tried many ways but I do not found any solution. Here is my code, I have an error, "non-constant value".
fn read(mut file : File) -> io::Result<()> {
let mut flag : u8 = 0;
while ((flag >> 7) & 1) != 1 {
let mut buffer = [0;1];
let _ = file.read_exact(&mut buffer)?;
flag = buffer[0];
let block_type = flag & 0x7F;
println!("block_type : {:?}", block_type);
let mut buffer = [0;3];
let _ = file.read_exact(&mut buffer)?;
let length = usize::from(buffer[0]) << 16 | usize::from(buffer[1]) << 8 | usize::from(buffer[2]);
println!("length : {:?}", length);
let mut buffer = [0;length];
let _ = file.read_exact(&mut buffer)?;
}
Ok(())
}
Thank you for your help. Vincent