21702 {
21703 constexpr idx_t max_shift = sizeof(T) * 8;
21704 static_assert(std::is_integral<T>::value, "Must be integral");
21705 static_assert(std::is_signed<T>::value, "Must be signed");
21706 static_assert(
sizeof(T) <=
sizeof(
int64_t),
"Must be int64_t or smaller");
21707
21708
21709 using unsigned_type = typename std::make_unsigned<T>::type;
21710
21711 result = 0;
21712 idx_t shift = 0;
21713 idx_t offset = 0;
21714
21716 do {
21717 byte = source[offset++];
21718 if (shift >= max_shift) {
21719 throw IOException("Failed to decode LEB128 integer: data may be corrupt");
21720 }
21721 result |= static_cast<unsigned_type>(byte & 0x7F) << shift;
21722 shift += 7;
21723 } while (byte & 0x80);
21724
21725
21726 if (shift < sizeof(T) * 8 && (byte & 0x40)) {
21727 result |= -(static_cast<unsigned_type>(1) << shift);
21728 }
21729 return offset;
21730 }