fix(baseN): basen::Exception

This commit is contained in:
2024-09-30 17:23:23 +03:00
parent 4eaf5b53c0
commit 227579d1e2
4 changed files with 43 additions and 14 deletions

View File

@ -11,7 +11,7 @@ namespace baseN
* @param digits char[base] array of digits
* @param digits_size size of digits array. Equals to base
* @param map [out] uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
* @throw std::logic_error if alphabet contain same chars
* @throw basen::Exception(ALPH_COLLISION) if alphabet contain same chars
*/
void digitsMap(const char *digits, uint8_t digits_size, uint8_t *map);
/**
@ -32,6 +32,7 @@ namespace baseN
* @param data vector or span of data which you want to encode
* @param base from 1 to 255
* @return estimated size after encoding
* @throw basen::Exception(BASE) if base < 2 || base > 254
*/
size_t sizeEncoded(std::span<const uint8_t> data, uint8_t base);
/**
@ -39,9 +40,10 @@ namespace baseN
* @param base from 1 to 255
* @param digits char[base] array of digits
* @return estimated size after decoding
* @throw std::overflow_error if if there is an overflow
* @throw basen::Exception(BASE) if base < 2 || base > 254
* @throw basen::Exception(OVERFLOW) if if there is an overflow
*/
size_t sizeDecoded(std::string_view str, uint8_t base, const char *digits) noexcept;
size_t sizeDecoded(std::string_view str, uint8_t base, const char *digits);
/**
* @param data [in] pointer to data which you want encode
@ -59,6 +61,7 @@ namespace baseN
* str.erase(str.begin(), str.begin() + offset);
* @endcode
* @return number of leading chars, which should be trimmed
* @throw basen::Exception(BASE) if base < 2 || base > 254
* @warning contain leading zeros, returns count of them
*/
size_t encode(const uint8_t *data, size_t data_size, char *str, size_t str_size, uint8_t base, const char *digits);
@ -72,7 +75,7 @@ namespace baseN
* @endcode
* @return encoded string
*/
std::string encode(std::span<const uint8_t> data, uint8_t base, const char *digits) noexcept;
std::string encode(std::span<const uint8_t> data, uint8_t base, const char *digits);
/**
* @param str [in] pointer to string which you want decode
@ -91,6 +94,8 @@ namespace baseN
* data.erase(data.begin(), data.begin() + offset);
* @endcode
* @return number of leading chars, which should be trimmed
* @throw basen::Exception(BASE) if base < 2 || base > 254
* @throw basen::Exception(OUT_OF_ALPH) if out of alphabet
* @warning contain leading zeros, returns count of them
*/
size_t decode(const char *str, size_t str_size, uint8_t *data, size_t data_size, uint8_t base, const char *digits, const uint8_t *map);
@ -105,5 +110,5 @@ namespace baseN
* @endcode
* @return decoded data
*/
std::vector<uint8_t> decode(std::string_view str, uint8_t base, const char *digits, const uint8_t *map) noexcept;
std::vector<uint8_t> decode(std::string_view str, uint8_t base, const char *digits, const uint8_t *map);
}