unflutter/dart/Leb128Int.cpp
Selim Mustafaev 5ec1117337 Fix building on macOS.
Adding LEB128 reader class.
2022-11-28 20:46:19 +03:00

37 lines
680 B
C++

//
// Created by Selim Mustafaev on 28.11.2022.
//
#include "Leb128Int.h"
namespace Dart {
Leb128Int::Leb128Int(): _value(0), _size(0) {
}
Dart::Leb128Int::Leb128Int(const std::byte* ptr): _value(0), _size(0) {
size_t bitShift = 0;
auto data = reinterpret_cast<const uint8_t*>(ptr);
while (*data < 0x80) {
_value |= (*data << bitShift);
bitShift += 7;
data++;
_size++;
}
_value |= ((*data & 0x7f) << bitShift);
_size++;
}
uint64_t Leb128Int::value() const {
return _value;
}
size_t Leb128Int::size() const {
return _size;
}
}