How about offset into some data?
r4v3n6101 opened this issue · 3 comments
Hello. First of all, my thanks for this crate.
So, I'm working on binary data parser, but I have some problems about offsets. Structure looks like this:
begin
header (16 bytes)
offsets point to data from beginning (count of N i32 which is acquired from header)
...
data somewhere in block of input
...
more data
...
and so on
...
end
How can I solve the problem of offset access using combine
crate? Header and data by offsets should be stored in custom struct. Thanks in advance!
I think you would use something like then
https://docs.rs/combine/4.6.3/combine/trait.Parser.html#method.then .
header()
.then(|header| {
parse(|input| {
// Do a separate parse at the offset(s)
let (output, _input) = my_parser().parse_state(&input[header.offset..])?;
// Then return the original input to continue parsing there (or return the input where you want to continue parsing)
Ok((output, input))
})
})
That's exact functionality that I need. Thanks!
Let me ask a question, what do you think about new in-crate parser called offset
. It's kind of look_ahead + skip: we go to our offset as the current base index, but when we're out of this parser it uses previous index. I can provide test implementation of my idea, just let me know what you think about it.
Sure, that seems generally useful.