Core lib building

This commit is contained in:
jmsgrogan 2024-01-02 16:14:23 +00:00
parent 3ed195d7dd
commit 94fcc42aed
73 changed files with 625 additions and 661 deletions

View file

@ -1,6 +1,6 @@
#include "BitStream.h"
#include "ByteUtils.h"
#include "Bits.h"
BitStream::~BitStream()
{
@ -20,7 +20,7 @@ void BitStream::write(DWord data)
{
for(size_t idx=0; idx<sizeof(DWord); idx++)
{
writeByte(ByteUtils::getByteN(data, idx));
writeByte(Bits::getByteN(data, idx));
}
}
@ -45,23 +45,23 @@ size_t BitStream::getCurrentBitOffset() const
String BitStream::logLocation()
{
String ret;
ret << "Byte offset " << mByteOffset<< " | Bit offset " << mBitOffset;
ret << " | Working byte " << ByteUtils::toString(getCurrentByte()) << '\n';
ret << _s("Byte offset ") << mByteOffset<< _s(" | Bit offset ") << mBitOffset;
ret << _s(" | Working byte ") << Bits::toString(getCurrentByte()) << _s('\n');
return ret;
}
String BitStream::logNextNBytes(size_t n) const
{
Stringstream sstr;
String sstr;
size_t count{0};
VecBytes bytes;
peekNextNBytes(n, bytes);
for(auto byte : bytes)
{
sstr << mByteOffset + count << " | " << ByteUtils::toString(byte) + '\n';
sstr << mByteOffset + count << _s(" | ") << Bits::toString(byte) + _s('\n');
count++;
}
return sstr.str();
return sstr;
}
void BitStream::writeNBits(DWord data, size_t length)
@ -71,7 +71,7 @@ void BitStream::writeNBits(DWord data, size_t length)
if (overshoot > 0)
{
Byte lower_bits = ByteUtils::getLowerNBits(data, num_left);
Byte lower_bits = Bits::getLowerNBits(data, num_left);
mCurrentByte |= lower_bits << mBitOffset;
writeByte(mCurrentByte, false);
@ -79,13 +79,13 @@ void BitStream::writeNBits(DWord data, size_t length)
size_t num_bytes = overshoot / 8;
for (size_t idx=0; idx< num_bytes; idx++)
{
mCurrentByte = ByteUtils::getMBitsAtN(static_cast<Byte>(data), overshoot, idx*8 + num_left);
mCurrentByte = Bits::getMBitsAtN(static_cast<Byte>(data), overshoot, idx*8 + num_left);
writeByte(mCurrentByte, false);
}
if (const auto remainder = overshoot % 8; remainder > 0)
{
mCurrentByte = ByteUtils::getMBitsAtN(static_cast<Byte>(data), remainder, num_bytes*8 + num_left);
mCurrentByte = Bits::getMBitsAtN(static_cast<Byte>(data), remainder, num_bytes*8 + num_left);
mBitOffset = remainder;
}
else
@ -127,8 +127,8 @@ bool BitStream::readNextNBits(size_t n, Byte& buffer)
}
auto num_lower = 8 - mBitOffset;
const auto lower_bits = ByteUtils::getHigherNBits(last_byte, num_lower);
const auto higher_bits = ByteUtils::getLowerNBits(mCurrentByte, overshoot);
const auto lower_bits = Bits::getHigherNBits(last_byte, num_lower);
const auto higher_bits = Bits::getLowerNBits(mCurrentByte, overshoot);
buffer = (higher_bits << num_lower) | lower_bits;
@ -137,7 +137,7 @@ bool BitStream::readNextNBits(size_t n, Byte& buffer)
}
else
{
buffer = ByteUtils::getMBitsAtN(mCurrentByte, n, mBitOffset);
buffer = Bits::getMBitsAtN(mCurrentByte, n, mBitOffset);
mBitOffset += n;
return true;
}
@ -169,7 +169,7 @@ void BitStream::flushRemainingBits()
}
}
std::pair<Byte, size_t> BitStream::getRemainingBits() const
Pair<Byte, size_t> BitStream::getRemainingBits() const
{
return {mEndByte, mEndBitOffset};
}