Add a position_of!
macro to reference earlier fields position
#161
Labels
enhancement
New feature or request
position_of!
macro to reference earlier fields position
#161
This issue is a feature proposal for adding a
position_of!
macro in the generated code for reading/writing.Main features
BinRead::read
/BinWrite::write
function, so it is not visible from outsideposition_of!(x)
gives the stream position at which the fieldx
has been readAdditional ideas
position_of
attribute such as:#[br(position_of)]
means we add it with it's default name#[br(position_of = my_name)]
means we add it and name itmy_name
Concerns
if
attribute for example), should it be:Option<u64>
which isNone
when the field is not read andSome
when it is (preferred)u64
that gives the position of the stream where the field could've been read (introduce concerns with conditionally appliedseek
/align
directives)calc
, should it be:u64
that gives the position of the stream at the time the field is calculatedImplementation proposals
The main difficulty is that we need to define a macro that allows us to reference earlier fields only:
a
is known, and as soon as the position ofb
is known, redefine it this way:The text was updated successfully, but these errors were encountered: