Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document order of operations for attributes #68

Open
jam1garner opened this issue Sep 30, 2021 · 2 comments
Open

Document order of operations for attributes #68

jam1garner opened this issue Sep 30, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation has instructions The given issue contains instructions on how to fix it or otherwise contribute

Comments

@jam1garner
Copy link
Owner

Implementation notes:

  • Add a section at the bottom of the corresponding attributes page
  • Link to it from a sentence at the bottom of the attribute overview tables
@jam1garner jam1garner added documentation Improvements or additions to documentation has instructions The given issue contains instructions on how to fix it or otherwise contribute labels Jan 9, 2022
@stevecheckoway
Copy link

I spent a while reading through the code and this is the order in which the attributes for binread are acted on. Any corrections appreciated.

I didn't look at how byte order is determined in any detail, but I assume you can just treat each of the "Byte order determination" below to mean big, little, is_big, and is_little.

This took longer than I expected and I didn't have time to do binwrite.


Reading unit structs

  1. import, import_tuple
  2. Byte order determination
  3. magic
  4. pre_assert

Reading structs

  1. import, import_tuple
  2. Byte order determination
  3. magic
  4. pre_assert
  5. Read each field
  6. Calls BinRead::after_parse()
  7. assert

Reading a field

  1. If temp and either default or ignore, then no other attributes are consulted and the field is not read
  2. offset
  3. import, import_tuple
  4. Byte order determination
  5. magic
  6. restore_position's position is computed here
  7. if (if the condition is not satisfied skip to the assert step)
  8. seek_before
  9. pad_before
  10. align_before
  11. pad_size_to's position is computed here
  12. default, ignore (which acts like default), or calc actions are taken; otherwise the field is read via parse_with or normally, passing args, args_raw, or count
  13. If none of default, ignore, and calc, then try or err_context
  14. map or try_map
  15. postprocess_now or deref_now cause BinRead::after_parse() to be called
  16. pad_size_to
  17. pad_after
  18. align_after
  19. assert
  20. restore_position

Reading unit enums

  1. import, import_tuple
  2. Byte order determination
  3. magic
  4. pre_assert
  5. repr or fields' magic and pre_assert

Reading data enums

  1. import, import_tuple
  2. Byte order determination
  3. magic
  4. pre_assert
  5. return_all_errors, return_unexpected_error
  6. If a unit variant, read according to Reading unit structs, otherwise read according to Reading structs

@octylFractal
Copy link
Contributor

Maybe a separate issue, but IMO for a more intuitive order, magic and loading restore_position should be swapped for fields, so that the position is before the magic is read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation has instructions The given issue contains instructions on how to fix it or otherwise contribute
Projects
None yet
Development

No branches or pull requests

3 participants