libfly
6.2.2
C++20 utility library for Linux, macOS, and Windows
|
#include <bit_stream.hpp>
Public Member Functions | |
virtual | ~BitStream () |
Protected Member Functions | |
BitStream (std::streambuf *stream_buffer, byte_type starting_position) noexcept | |
template<detail::BitStreamInteger DataType> | |
DataType | bit_mask (const DataType bits) |
Protected Attributes | |
std::streambuf * | m_stream_buffer |
buffer_type | m_buffer {0} |
byte_type | m_position {0} |
Base class for writing to and reading from a binary stream. The first byte of the binary stream is reserved as a header for internal use.
The BitStream implementations allow reading and writing content bit-by-bit. Of course, files cannot contain partial bytes. If a BitStream is closed with a partial byte remaining to be written, that byte is zero-filled, and the number of extra bits written is encoded into the header.
The format of the header byte is then:
| 5 bits | 3 bits | --------------------------------------------- | Magic number | Number of zero-filled bits |
Each BitStream implementation essentially serves as a wrapper around an already existing std::istream or std::ostream. It is expected that the pre-existing stream outlive the wrapper BitStream instance.
|
virtualdefault |
Destructor.
|
protectednoexcept |
Protected constructor to prevent instantiating this class directly.
stream_buffer | Pointer to the stream's underlying stream buffer. |
starting_position | Initial cursor position. |
|
inlineprotected |
Create a bit-mask with the least-significant bits set. The size of the mask is determined by the template DataType parameter.
DataType | The data type storing the number of bits to set. |
starting_position | The number of bits to set. |