Closed ckrenslehner closed 3 months ago
I think this might solve my use case as well. I have a struct that has a header_size
in the middle of the struct. I was to add an assert
on my struct that verifies that the total amount of bytes read equals the defined header_size.
e.g.,
#[binrw]
#[br(assert(header_size == relative_stream_position()))]
struct Header {
...
header_size: u32,
...
}
Unless there is already a way to do this and I missed it.
Is there a way to get a stream position which is not absolute to the stream? I want to parse multiple elements within a stream where I need a relative stream position, because otherwise the calculations are off. See the test code below.
Outer
parses the total length ofInner
andInner
parses two fixed fields before parsing the rest into a vec. Now I solved this via making a custom stream which provides a relative position. Is there any other, more elegant way?Greetings and thanks, Christian