API Documentation
Public Member Functions | List of all members
nkMemory::BitStream Class Reference

Offers capabilities to read data bit per bit. More...

Public Member Functions

 BitStream (BufferView<> data) noexcept
 
BufferView getData () const
 
unsigned char getCurrentByte () const
 
unsigned int getByteCounter () const
 
unsigned int getBitCounter () const
 
bool isAtEos () const
 
unsigned int peekMsb (unsigned int count)
 
unsigned int peekLsb (unsigned int count)
 
unsigned int readMsb (unsigned int count)
 
unsigned int readLsb (unsigned int count)
 
void moveForward (unsigned int count)
 
void moveToNextByte ()
 
void moveTo (unsigned int byteCount, unsigned int bitCount)
 
void rewind ()
 

Detailed Description

Offers capabilities to read data bit per bit.

Constructor & Destructor Documentation

◆ BitStream()

nkMemory::BitStream::BitStream ( BufferView<>  data)
noexcept

Constructor.

Parameters
dataThe data buffer to work on.

Member Function Documentation

◆ getData()

BufferView nkMemory::BitStream::getData ( ) const
Returns
The data used by the stream.

◆ getCurrentByte()

unsigned char nkMemory::BitStream::getCurrentByte ( ) const
Returns
The current byte within the buffer. Shorthand for indexing the data using the current byte counter.

◆ getByteCounter()

unsigned int nkMemory::BitStream::getByteCounter ( ) const
Returns
The current byte counter, which corresponds to the byte index the stream is currently on.

◆ getBitCounter()

unsigned int nkMemory::BitStream::getBitCounter ( ) const
Returns
The current bit counter, which corresponds to the bit index, within the current byte, the stream is currently on.
Remarks
This index can ultimately point to a different position depending on the stream's endianness.

◆ isAtEos()

bool nkMemory::BitStream::isAtEos ( ) const

Checks whether the stream is at the end of the available data.

Returns
Whether the stream is fully read (true) or not (false).

◆ peekMsb()

unsigned int nkMemory::BitStream::peekMsb ( unsigned int  count)

Peeks bits from the position the stream is currently on, for a Most-Significant-Byte first layout. The stream does not moves forward during this operation.

Parameters
countThe number of bits to read.
Returns
The result of the reading.
Remarks
Both the bytes, and bits, are considered MSB (as a result, read from left to right).

◆ peekLsb()

unsigned int nkMemory::BitStream::peekLsb ( unsigned int  count)

Peeks bits from the position the stream is currently on, for a Least-Significant-Byte first layout. The stream does not moves forward during this operation.

Parameters
countThe number of bits to read.
Returns
The result of the reading.
Remarks
Both the bytes, and bits, are considered LSB (as a result, read from right to left).

◆ readMsb()

unsigned int nkMemory::BitStream::readMsb ( unsigned int  count)

Read bits, moving the stream forward, for a Most-Significant-Byte first layout.

Parameters
countThe number of bits to read.
Returns
The result of the reading.

◆ readLsb()

unsigned int nkMemory::BitStream::readLsb ( unsigned int  count)

Read bits, moving the stream forward, for a Least-Significant-Byte first layout.

Parameters
countThe number of bits to read.
Returns
The result of the reading.

◆ moveForward()

void nkMemory::BitStream::moveForward ( unsigned int  count)

Move the stream forward.

Parameters
countThe number of bits to move forward.

◆ moveToNextByte()

void nkMemory::BitStream::moveToNextByte ( )

Moves the stream at the next byte's boundary. Useful to skip bits used for padding within a byte, for instance.

◆ moveTo()

void nkMemory::BitStream::moveTo ( unsigned int  byteCount,
unsigned int  bitCount 
)

Moves the stream to a given position.

Parameters
byteCountThe byte index to move to, within [0, streamByteSize].
bitCountThe bit index within the byte to move to, within [0, 7].

◆ rewind()

void nkMemory::BitStream::rewind ( )

Rewinds the stream fully, restarting its reading from the beginning.


The documentation for this class was generated from the following file: