Problem
There is a file that has multiple headers inside it, but to me, it only matters one and the data after it. This header repeats itself multiple times through the file.
Its magic number is: A3046 in ASCII, or 0x65 0x51 0x48 0x54 0x52 in HEX.
After finding the first byte, the parser has to take all bytes until 0xff and then repeat for the remainder headers until the EOF.
My solution
First I loaded the file:
let mut file = OpenOptions::new()
.read(true)
.open("../assets/sample")
.unwrap();
let mut full_file: Vec<u8> = Vec::new();
file.read_to_end(&mut full_file);
I declare the magic numbers with: pub static QT_MAGIC: &[u8; 5] = b"A3046";
And as a test, I wrote the following function just to try if it could find the first header.
fn parse_block(input: &[u8]) -> IResult<&[u8], &[u8]> {
tag(QT_MAGIC)(input)
}
However when the test runs, Ok has None value. It definitely should have found something. What I am doing wrong?
I found no examples of bytes parsing using nom5, and also being a rust newbie is not helping. How can I parse all the blocks with these rules?