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

Add support for including slices of binary files #192

Merged
merged 1 commit into from
Dec 29, 2023

Conversation

MineRobber9000
Copy link
Contributor

Adds 2 new forms of incbin:

  • incbin(relative_filename, start): includes relative_filename starting from offset start
  • incbin(relative_filename, start, size): includes size bytes from relative_filename starting from offset start

I'd also like to make incbinstr and inchexstr work similarly, but I'm not sure how to make it work (extra clarification for PR message that wasn't in the commit message: incbinstr and inchexstr go straight from a bitvec to a bigint with no intervening Vec<u8> step, so I can't slice it as easily as I can incbin).

When #191 gets merged, ensure_inc_args can be replaced with a call to query.ensure_min_max_arg_number(1,3)?;. Since I don't have that merged locally, I just wrote a quick and dirty function to do it.

@MineRobber9000
Copy link
Contributor Author

In the process of writing the implementations for incbinstr and inchexstr, I've come to the realization that I'm not exactly sure what start and size ought to entail when used. For incbin, the obvious answer was "start and size are counted in bytes", but with incbinstr and inchexstr being able to include values that aren't a round number of bytes, what should start and size be measured in? Bits?

@hlorenzi
Copy link
Owner

Hmmm, I think going by the logic, incbinstr and inchexstr should be measured in characters (which, in the set we allow, are also just bytes). But there's the issue of having ignorable characters inside these files (like whitespace and underscores).

So they should probably be measured by the multiple of bits each character is converted into, 1 and 4 respectively. I think it can be done by directly slicing the final output bitvec.to_bigint().

@MineRobber9000 MineRobber9000 changed the title WIP: Add support for including slices of binary files Add support for including slices of binary files Dec 28, 2023
@MineRobber9000
Copy link
Contributor Author

I'd say I'm proud of this PR. Ready for merge!

@hlorenzi hlorenzi merged commit 4c543f5 into hlorenzi:main Dec 29, 2023
1 check passed
@MineRobber9000 MineRobber9000 deleted the incbin-slice branch December 30, 2023 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants