Struct BitReader#

Struct Documentation#

struct BitReader#

Public Functions

explicit constexpr BitReader(std::span<const u8> data)#

Constructor. BitReader reads byte data bit by bit.

Parameters:

data – Data to read in bytes.

consteval BitReader(const BitReader&) = delete#

Copy constructor.

consteval BitReader &operator=(const BitReader&) = delete#

Copy assignment operator.

constexpr BitReader(BitReader&&) noexcept = default#

Move constructor.

constexpr BitReader &operator=(BitReader&&) noexcept = default#

Move assignment operator,.

constexpr ~BitReader() = default#

Destructor.

constexpr void EnsureBits9()#

Ensure the reader can at least read 9 bits in one or more ReadBits calls, safely even if not enough bits are available.

constexpr void EnsureBits17()#

Ensure the reader can at least read 17 bits in one or more ReadBits calls, safely even if not enough bits are available.

constexpr void EnsureBits25()#

Ensure the reader can at least read 25 bits in one or more ReadBits calls, safely even if not enough bits are available.

constexpr void EnsureBits32()#

Ensure the reader can at least read 32 bits in one or more ReadBits calls, safely even if not enough bits are available.

constexpr u32 ReadBits(usize nBits)#

Read n amount of bits.

Note

Must have enough bits available with EnsureBits.

Parameters:

nBits – How many bits.

Returns:

N bits read.

constexpr u32 PeekBits(usize nBits) const noexcept#

Get bits without advancing the bit pointer.

Note

Must have enough bits available with EnsureBits.

Parameters:

nBits – How many bits up to 31.

Returns:

N bits read.

void constexpr AdvanceBits(usize nBits) noexcept#

Advance n amount of bits in the reader.

Note

Must have enough bits available with EnsureBits.

Parameters:

nBits – How many bits.

Public Members

std::span<const u8> Data#
usize BitSize = {}#
usize BP = {}#
u32 Buffer = {}#
bool Error = false#

Public Static Functions

static constexpr bool GreaterOverflow(usize a, usize b, usize c)#

Safely check if a + b > c, even if overflow could happen.

Returns:

True if no overflow will happen, false otherwise.