This commit is contained in:
@@ -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(¤tByte, 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
|
||||
|
||||
Reference in New Issue
Block a user