fix(types): uint64_t -> size_t

This commit is contained in:
2024-09-30 12:35:59 +03:00
parent be4f2ae036
commit 1d6b086bfa
14 changed files with 60 additions and 60 deletions

View File

@ -26,7 +26,7 @@ namespace hex
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
//
};
bool isValid(const char *str, uint64_t str_size) noexcept
bool isValid(const char *str, size_t str_size) noexcept
{
return baseN::isValid(str, str_size, map);
}
@ -34,25 +34,25 @@ namespace hex
{
return baseN::isValid(str, map);
}
uint64_t sizeEncoded(std::span<const uint8_t> data)
size_t sizeEncoded(std::span<const uint8_t> data)
{
if (data.size() > std::numeric_limits<uint64_t>::max() / 2)
if (data.size() > std::numeric_limits<size_t>::max() / 2)
{
throw std::overflow_error("hex::sizeEncoded: overflow");
}
return data.size() * 2;
}
uint64_t sizeDecoded(std::string_view str) noexcept
size_t sizeDecoded(std::string_view str) noexcept
{
return str.size() / 2;
}
void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size)
void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size)
{
if (str_size < hex::sizeEncoded(std::span<const uint8_t>(data, data_size)))
{
throw std::length_error("hex::encode: not enough allocated length");
}
for (uint64_t i = 0; i < data_size; i++)
for (size_t i = 0; i < data_size; i++)
{
str[i * 2] = digits[data[i] >> 4];
str[i * 2 + 1] = digits[data[i] & 0x0F];
@ -64,7 +64,7 @@ namespace hex
hex::encode(data.data(), data.size(), str.data(), str.size());
return str;
}
void decode(const char *str, uint64_t str_size, uint8_t *data, uint64_t data_size)
void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size)
{
if (str_size % 2 != 0)
{
@ -78,7 +78,7 @@ namespace hex
{
throw std::logic_error("hex::decode: out of digits map");
}
for (uint64_t i = 0; i * 2 < str_size; i++)
for (size_t i = 0; i * 2 < str_size; i++)
{
data[i] = map[(int8_t)str[i * 2]] << 4 | map[(int8_t)str[i * 2 + 1]];
}