#C++ Library for Binary Data

27 messages · Page 1 of 1 (latest)

dusk bramble
#

It's very early days for this project of mine, and so it's lacking a lot of features, but I wanted to get feedback on how I'm doing so far with the library design.

The GitHub README should hopefully explain everything, although if something is unclear, please lmk and I'll clarify.
https://github.com/KojoBailey/binary-cpp-library

GitHub

A C++ library for parsing the binary data of files and whatnot both easily and cleanly. - KojoBailey/binary-cpp-library

#

Here be the header file for those too lazy to go through GitHub (it's only a single file)

#

You'll notice it's very short since I'm yet to add many features like writing, hashing, etc.

coarse grove
#

Why char though and not unsigned char or std::byte?

cinder crag
#

wow

dusk bramble
#

std::byte seems useful though

#

will switch, thanks

coarse grove
#

it's basically the recommended type for arbitrary binary data

dusk bramble
#

but why does the signage matter

#

it's only 1-byte anyway

craggy yoke
#

it's easier to reason about the decimal values of a byte going from 0 to 255 (range of unsigned char) rather than from -128 to 127 (range of signed char), so why risk it if char happens to be signed on your platform

#

anyway that's how the rationale goes

#

std::byte clears that up by being unambiguous about it: you're dealing with a bunch of bits which do not hold any meaning beyond their bit values
what this means is that you're pretty restricted about what you can do with a std::byte, it boils down to bitwise operations, and most notably that does not include arithmetic operations

#

(it's also a C++20 feature)

dusk bramble
dusk bramble
#

have to cast to unsigned char a lot

#

so yeah, like you said

rancid fjord
rancid fjord
#

well, some of it is unintentional; there are cases where std::byte is artificially inconvenient, like initialization

dusk bramble