Skip to content

Any API to achieve pair of headers and contents layout? #165

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

You must be logged in to vote

Hi,

Probably you will want to write and use a helper function that creates the programs field from an iterator of Header values:

#[derive(BinRead, Clone, Copy)]
pub struct Header {
    code_size: u32,
    data_size: u32,
}

#[derive(BinRead)]
#[br(import_raw(header: Header))]
struct Program {
  #[br(count = header.code_size)]
  code: Vec<u8>,
  #[br(count = header.data_size)]
  data: Vec<u8>,
}

#[derive(BinRead)]
struct Metadata {
  count: u64,
  #[br(count = count)]
  headers: Vec<Header>,
  #[br(parse_with = from_iterator_args(headers.iter()))]
  programs: Vec<Program>,
}

fn from_iterator_args<'it, R, T, Arg, Ret, It>(it: It) -> impl FnOnce(&mut R, &ReadOptions, ()) -> BinResult<Ret>
w…

Replies: 1 comment 5 replies

Comment options

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

csnover Nov 10, 2022
Collaborator

@ileixe
Comment options

@csnover
Comment options

csnover Nov 10, 2022
Collaborator

@ileixe
Comment options

@ileixe
Comment options

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