#include <bit_stream_reader.hpp>
|
| BitStream (std::streambuf *stream_buffer, byte_type starting_position) noexcept |
|
template<detail::BitStreamInteger DataType> |
DataType | bit_mask (const DataType bits) |
|
std::streambuf * | m_stream_buffer |
|
buffer_type | m_buffer {0} |
|
byte_type | m_position {0} |
|
Implementation of the BitStream interface for reading from a binary stream.
The stream is read in a lazy manner; bytes are not read from the stream until they are needed. The number of bytes read from the stream at once is defined by the size of buffer_type. That buffer is stored in-memory until it has been entirely consumed by the caller, at which point it is refilled.
- Author
- Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
- Version
- July 7, 2019
◆ BitStreamReader()
fly::BitStreamReader::BitStreamReader |
( |
std::istream & |
stream | ) |
|
|
explicitnoexcept |
Constructor. Decode the header byte from the stream. If the header byte is invalid, the stream's fail bit is set.
- Parameters
-
stream | The stream to read binary data from. |
◆ discard_bits()
void fly::BitStreamReader::discard_bits |
( |
byte_type |
size | ) |
|
|
inline |
Discard a number of bits from the byte buffer. Should only be used after a successful call to peek_bits.
- Parameters
-
size | The number of bits to discard. |
◆ fully_consumed()
bool fly::BitStreamReader::fully_consumed |
( |
| ) |
const |
Check if the stream has reached end-of-file and the byte buffer has been fully consumed.
- Returns
- True if the stream has been fully consumed.
◆ header()
byte_type fly::BitStreamReader::header |
( |
| ) |
const |
- Returns
- The header byte decoded from the stream.
◆ peek_bits()
template<detail::BitStreamInteger DataType>
byte_type fly::BitStreamReader::peek_bits |
( |
DataType & |
bits, |
|
|
byte_type |
size |
|
) |
| |
Read a number of bits from the byte buffer without discarding those bits. There is no guarantee that the requested number of bits will actually be peeked, as there may be less than that number available between the byte buffer and stream. If any bits were peeked, the least-significant bits in the provided data type will be filled, starting from the position pointed to by the requested number of bits.
Fill the buffer from the stream if the number of bits to peek exceeds the number of bits available.
- Parameters
-
bits | The location to store the peeked bits. |
size | The number of bits to peek. |
- Returns
- The number of bits successfully peeked.
◆ read_bits()
template<detail::BitStreamInteger DataType>
byte_type fly::BitStreamReader::read_bits |
( |
DataType & |
bits, |
|
|
byte_type |
size |
|
) |
| |
Read a number of bits from the byte buffer. There is no guarantee that the requested number of bits will actually be read, as there may be less than that number available between the byte buffer and stream. If any bits were read, the least-significant bits in the provided data type will be filled, starting from the position pointed to by the requested number of bits.
Fill the buffer from the stream if the number of bits to read exceeds the number of bits available.
- Template Parameters
-
DataType | The data type of the location to store the read bits. |
- Parameters
-
bits | The location to store the read bits. |
size | The number of bits to read. |
- Returns
- The number of bits successfully read.
◆ read_byte()
bool fly::BitStreamReader::read_byte |
( |
byte_type & |
byte | ) |
|
Read a full byte from the byte buffer.
Fill the buffer from the stream if the number of bits to read exceeds the number of bits available.
- Parameters
-
byte | The location to store the read byte. |
- Returns
- True if the byte was successfully read and filling the byte buffer was successful (if needed).
◆ read_word()
bool fly::BitStreamReader::read_word |
( |
word_type & |
word | ) |
|
Read a multibyte word from the byte buffer.
Fill the buffer from the stream if the number of bits to read exceeds the number of bits available.
- Parameters
-
word | The location to store the read word. |
- Returns
- True if the word was successfully read and filling the byte buffer was successful (if needed).
The documentation for this class was generated from the following files: