binrw icon indicating copy to clipboard operation
binrw copied to clipboard

Add `br(map_reader)` attribute

Open jam1garner opened this issue 2 years ago • 1 comments

Motivation

Being able to utilize reader adapters easily would greatly improve multiple areas of binrw that could use a bit of improvement:

  • Parsing from decompressed or encrypted content
  • Ensuring a field doesn't read past a specific size
  • Easier "parse until end of section" ability (something akin to the .take(...) io::Read adapter[^1])

[^1]: io::Take does not support seeking so this functionality would also be needed (likely 2 variants, one for "seeks relative to current position" and one for "seeks relative to start of inner reader")

Syntax

#[br(map_reader = $map_fn:expr)]

jam1garner avatar May 12 '22 22:05 jam1garner

I feel like this, or something very similar, would also be the correct solution for issues like #102.

Also, regarding footnote 1, I already have a TakeSeek type that can be used.

csnover avatar Aug 19 '22 06:08 csnover