You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I get the pos of an item inside a loop of blocks that have different sizes?
I've tried doing
seq:
- id: skip_initsize: 280060
- id: run_datatype: datarepeat: expr repeat-expr: 2# just to testinstances:
names:
io: run_data[_index]._iopos: _io.possize: run_data[_index].name_size
I have tried to add instances with a similar logic inside of the run_data block, but it would always point to the same block of data.
I'm doing this because I've a structure that looks something like this.
name[name_size]
zeroes[2] (that will only appear if (name_size / 2) % 2 == 1) + data[8]
name2[name_size]
zeroes[Value also based on the string size]
data[400]
name_size[2]
data[16]
so I have to pass through the "name" variable first, then I'm able to get its value (name_size).
Still I've managed to parse each block using another logic, that doesn't allow me to filter the "name" , that's why I was using instances for "post-processing"
What I would like to do is something like this.
seq:
- id: skip_initsize: 280060
- id: run_datatype: datarepeat: expr repeat-expr: 2# just to testinstances:
names:
pos: Start of the block at each indexsize: name_size variable of each index
Am I taking the best approach for this? I've read the documentation, but I was not able to get an answer for this specific case.
The text was updated successfully, but these errors were encountered:
jeansanch
changed the title
How to use instances: in a loop, where each iteration has a dynamic size?
How to use instances: in a loop, where each iteration has a different size?
Jan 12, 2024
I would like to add that the code referenced at https://doc.kaitai.io/user_guide.html#_relative_positioning is not possible to do here, because I don't have a fixed size as in "some_block.size" in the code on the example "Good (w/substream)" and I'm only able to get the block size, at the end of the block.
How can I get the
pos
of an item inside a loop of blocks that have different sizes?I've tried doing
I have tried to add instances with a similar logic inside of the run_data block, but it would always point to the same block of data.
I'm doing this because I've a structure that looks something like this.
name[name_size]
zeroes[2] (that will only appear if (name_size / 2) % 2 == 1) + data[8]
name2[name_size]
zeroes[Value also based on the string size]
data[400]
name_size[2]
data[16]
so I have to pass through the "name" variable first, then I'm able to get its value (name_size).
Still I've managed to parse each block using another logic, that doesn't allow me to filter the "name" , that's why I was using instances for "post-processing"
What I would like to do is something like this.
Am I taking the best approach for this? I've read the documentation, but I was not able to get an answer for this specific case.
The text was updated successfully, but these errors were encountered: