feat: add streams
All checks were successful
Linux arm64 / Build (push) Successful in 16s

This commit is contained in:
2025-06-26 19:17:52 +02:00
parent 59bedd6482
commit 0d26879152
25 changed files with 385 additions and 778 deletions

View File

@@ -29,24 +29,29 @@ DataBuffer& operator<<(DataBuffer& out, const VarInt& var) {
}
DataBuffer& operator>>(DataBuffer& in, VarInt& var) {
var.m_Value = 0;
var.Read([&in](std::uint8_t& data){
in.ReadSome(&data, 1);
});
return in;
}
void VarInt::Read(const ReadFunc& read) {
m_Value = 0;
unsigned int position = 0;
std::uint8_t currentByte;
while (true) {
in.ReadSome(&currentByte, 1);
var.m_Value |= static_cast<std::uint64_t>(currentByte & SEGMENT_BITS) << position;
read(currentByte);
m_Value |= static_cast<std::uint64_t>(currentByte & SEGMENT_BITS) << position;
if ((currentByte & CONTINUE_BIT) == 0)
break;
position += 7;
if (position >= 8 * sizeof(var.m_Value))
if (position >= 8 * sizeof(m_Value))
throw std::runtime_error("VarInt is too big");
}
return in;
}
} // namespace sp