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

define a container for reading bytes from a file #117

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oliverlee
Copy link
Collaborator

Define a byte_container class template for use in tests. It provides
std::byte-oriented access (as opposed to char) to the bytes in a
file or string.

Change-Id: I364fcb0efaae9ac79bb78198912b885b3d9f54c5

Define a default constructor for `bit_span`. Update `consume` to return
a reference.

Change-Id: I08edcc3e240a44a04b09a8ba787030665134f3a8
Change-Id: I5dca691416482ae27ab31bc176fd5217b8e3fd8f
Define a `byte_container` class template for use in tests. It provides
`std::byte`-oriented access (as opposed to `char`) to the bytes in a
file or string.

Change-Id: I364fcb0efaae9ac79bb78198912b885b3d9f54c5
@oliverlee oliverlee force-pushed the I364fcb0efaae9ac79bb78198912b885b3d9f54c5 branch from f67d366 to 4786297 Compare November 22, 2023 18:41
Copy link
Owner

@garymm garymm left a comment

Choose a reason for hiding this comment

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

I guess this is more type safe because of static_cast rather than reinterpret_cast?
But it is a lot of code, and I think has an extra copy (vs the reinterpet_cast).
If that's right I'm inclined to stick with reinterpret_cast, or just switch everything from byte to uint8_t. I know byte is conceptually what we want, but it seems like it interacts with the file I/O library badly and I don't really see any downside to using uint8_t.

Thoughts?

@oliverlee
Copy link
Collaborator Author

I guess this is more type safe because of static_cast rather than reinterpret_cast? But it is a lot of code, and I think has an extra copy (vs the reinterpet_cast). If that's right I'm inclined to stick with reinterpret_cast, or just switch everything from byte to uint8_t. I know byte is conceptually what we want, but it seems like it interacts with the file I/O library badly and I don't really see any downside to using uint8_t.

Thoughts?

I don't think static_cast vs reinterpret_cast is a big deal but more that it's useful to have a type that provides byte traversal and owns the data. The internal storage can be changed from std::byte to char and then reinterpret_cast moved to the begin and end functions.

There's an extra copy for the in_place constructor overload, as we need to copy all the chars into the container, but I don't think that's a huge problem since this is currently test only.

std::byte is not an arithmetic type and cannot be implicitly be promoted to int. Outside of reading input files and constant strings we use in test cases, I think this should make of the interface that uses char so poor ergonomics with iostreams should be handled going forward.

@oliverlee oliverlee force-pushed the I5dca691416482ae27ab31bc176fd5217b8e3fd8f branch from b15303a to 0803a3a Compare November 23, 2023 01:28
Base automatically changed from I5dca691416482ae27ab31bc176fd5217b8e3fd8f to master November 23, 2023 01:32
@oliverlee oliverlee marked this pull request as draft January 6, 2024 18:10
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