Skip to content

Get stream position relative to object start #284

Answered by csnover
ckrenslehner asked this question in Q&A
Discussion options

You must be logged in to vote

For this use case you should be able to use map_stream, TakeSeekExt, and until_eof:

use binrw::io::TakeSeekExt;

#[binrw::binrw]
struct Outer {
    len: u8,
    #[br(map_stream(|s| s.take_seek(len.into())))]
    inner: Inner,
}

#[binrw::binrw]
struct Inner {
    pre_1: u8,
    pre_2: u16,

    #[br(parse_with = binrw::helpers::until_eof)]
    data: Vec<u8>,
}

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@ismell
Comment options

@csnover
Comment options

csnover Aug 7, 2024
Collaborator

@ckrenslehner
Comment options

@ismell
Comment options

@v1gnesh
Comment options

Answer selected by ckrenslehner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #283 on August 07, 2024 16:35.