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

Make dependency on file location in Block explicit #3570

Conversation

eivindjahren
Copy link
Contributor

@eivindjahren eivindjahren commented Jun 24, 2022

A small refactoring to make dependency of the Block::write_data() byte offset explicit.

The Block::write_data() function depended on being called with the data_stream being at the location
it should write, which was unlike any of the other write_* functions. The write_header() function would
guarantee that this was the case. This ment the order of operations in write was very much significant although
it may not look like it.

The write_* functions follow a general pattern which is not uncommon. They fseek() in the stream to where they should write and afterwords stream is at the end of where we wrote. Another common pattern is to not enforce the location, and simply write wherever the stream is currently pointing, but the current design makes that infeasible for all of the functions, yet write_data() followed that convention. Instead of having this surprising inconsistency, the write_header() function now supplies the data offset which is passed to write_data(), making the dependency explicit.

All the write_* functions now have the following behavior

  1. move to some predetermined location in the stream
  2. Write your thing there
  3. After finishing the stream location is after where it wrote.

Points 2. and 3. is the same behavior as fwrite. Point 1. is a reasonable convention.

Pre review checklist

  • Added appropriate release note label
  • PR title captures the intent of the changes, and is fitting for release notes.
  • Commit history is consistent and clean, in line with the contribution guidelines.

Adding labels helps the maintainers when writing release notes. This is the list of release note labels.

@eivindjahren eivindjahren marked this pull request as ready for review June 24, 2022 10:35
@eivindjahren eivindjahren self-assigned this Jun 24, 2022
@eivindjahren eivindjahren added the maintenance Not a bug now but could be one day, repaying technical debt label Jun 24, 2022
@eivindjahren eivindjahren requested a review from dafeda June 24, 2022 10:47
Copy link
Contributor

@dafeda dafeda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@eivindjahren eivindjahren merged commit e344c3c into equinor:main Jun 24, 2022
@eivindjahren eivindjahren deleted the propose_explicit_dependency_in_block_fs branch June 24, 2022 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Not a bug now but could be one day, repaying technical debt
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants