mal-packet-weaver
C++20 packet serialization/deserialization library.
|
Contains a collection of tools and utilities provided by the MAL Toolkit library. More...
Namespaces | |
namespace | _template_detail |
namespace | endianness |
namespace | uuid |
Classes | |
struct | ByteArray |
A dynamically resizable array of bytes. More... | |
struct | ByteView |
A lightweight view over a sequence of bytes. More... | |
class | CallbackSystem |
A system for managing and invoking callback functions. More... | |
class | enableable |
A class that can be enabled or disabled. More... | |
class | ExponentialBackoff |
A utility class for implementing exponential backoff strategies. More... | |
class | LinearBackoff |
A utility class for implementing linear backoff strategies. More... | |
struct | Measurer |
A class for measuring and logging the execution time of functions. More... | |
class | namable |
A class that contains a name and can be named and unnamed. More... | |
class | namable_once |
A class that contains a name and can be named only once at construction. More... | |
class | namable_protected |
A class that contains a name and can be named and unnamed, but you cant set the name from outside. More... | |
class | non_copyable |
A class that can't be copied. More... | |
class | non_copyable_non_movable |
A class that can't be copied neither moved. More... | |
class | non_movable |
A class that can't be moved. More... | |
struct | parameter_pack_info |
Provides information about a parameter pack. More... | |
struct | return_type |
Extracts the return type of a function or function pointer. More... | |
struct | return_type< R(*)(Args...)> |
struct | return_type< R(Args...)> |
struct | return_type< R(C::*)(Args...) & > |
struct | return_type< R(C::*)(Args...) && > |
struct | return_type< R(C::*)(Args...) const & > |
struct | return_type< R(C::*)(Args...) const && > |
struct | return_type< R(C::*)(Args...) const > |
struct | return_type< R(C::*)(Args...) const volatile & > |
struct | return_type< R(C::*)(Args...) const volatile && > |
struct | return_type< R(C::*)(Args...) const volatile > |
struct | return_type< R(C::*)(Args...) volatile & > |
struct | return_type< R(C::*)(Args...) volatile && > |
struct | return_type< R(C::*)(Args...) volatile > |
struct | return_type< R(C::*)(Args...)> |
class | Timer |
A simple timer class for measuring elapsed time using various clock types. More... | |
Concepts | |
concept | EnumClassConcept |
Concept to check if a type is an enumeration class. | |
Typedefs | |
using | ExponentialBackoffNs = ExponentialBackoff<std::chrono::nanoseconds> |
using | ExponentialBackoffUs = ExponentialBackoff<std::chrono::microseconds> |
using | ExponentialBackoffMs = ExponentialBackoff<std::chrono::milliseconds> |
using | ExponentialBackoffSec = ExponentialBackoff<std::chrono::seconds> |
using | LinearBackoffNs = LinearBackoff<std::chrono::nanoseconds> |
using | LinearBackoffUs = LinearBackoff<std::chrono::microseconds> |
using | LinearBackoffMs = LinearBackoff<std::chrono::milliseconds> |
using | LinearBackoffSec = LinearBackoff<std::chrono::seconds> |
template<typename T > | |
using | return_type_t = typename return_type<T>::type |
using | SteadyTimer = Timer<std::chrono::steady_clock> |
Alias for Timer using std::chrono::steady_clock as the clock type. | |
using | HighResolutionTimer = Timer<std::chrono::high_resolution_clock> |
Alias for Timer using std::chrono::high_resolution_clock as the clock type. | |
Functions | |
uint16_t | bytes_to_uint16 (const ByteView byte_view) |
Convert a byte array to a uint16_t value using little-endian byte order. | |
ByteArray | uint16_to_bytes (const uint16_t value) |
Convert a uint16_t value to a ByteArray using little-endian byte order. | |
uint32_t | bytes_to_uint32 (const ByteView byte_view) |
Convert a byte array to a uint32_t value using little-endian byte order. | |
ByteArray | uint32_to_bytes (const uint32_t value) |
Convert a uint32_t value to a ByteArray using little-endian byte order. | |
uint64_t | bytes_to_uint64 (const ByteView byte_view) |
Convert a byte array to a uint64_t value using little-endian byte order. | |
ByteArray | uint64_to_bytes (const uint64_t value) |
Convert a uint64_t value to a ByteArray using little-endian byte order. | |
int16_t | bytes_to_int16 (const ByteView byte_view) |
Convert a byte array to an int16_t value using little-endian byte order. | |
ByteArray | int16_to_bytes (const int16_t value) |
Convert an int16_t value to a ByteArray using little-endian byte order. | |
int32_t | bytes_to_int32 (const ByteView byte_view) |
Convert a byte array to an int32_t value using little-endian byte order. | |
ByteArray | int32_to_bytes (const int32_t value) |
Convert an int32_t value to a ByteArray using little-endian byte order. | |
int64_t | bytes_to_int64 (const ByteView byte_view) |
Convert a byte array to an int64_t value using little-endian byte order. | |
ByteArray | int64_to_bytes (const int64_t value) |
Convert an int64_t value to a ByteArray using little-endian byte order. | |
template<typename T , typename... U> | |
size_t | GetFunctionAddress (std::function< T(U...)> f) |
Get the address of a callable function. | |
std::optional< int64_t > | to_int64 (std::string_view str) |
Convert a string_view to an optional int64_t. | |
std::optional< uint64_t > | to_uint64 (std::string_view str) |
Convert a string_view to an optional uint64_t. | |
std::optional< long double > | to_long_double (std::string_view str) |
Convert a string_view to an optional long double. | |
std::string | CurrentSourceLocation (std::source_location location=std::source_location::current()) |
Generates a string representation of the current source location. | |
void | Assert (bool value, std::string_view message="Assert failed", std::source_location location=std::source_location::current()) |
Asserts a condition with customizable behavior based on debug mode. | |
void | AlwaysAssert (bool value, std::string_view message="Assert failed", std::source_location location=std::source_location::current()) |
Always asserts a condition with customizable behavior. | |
std::string | CurrentSourceLocation () |
Returns an empty string representing the current source location. | |
void | Assert (bool value, std::string_view message="Assert failed") |
Asserts a condition with customizable behavior based on debug mode. | |
void | AlwaysAssert (bool value, std::string_view message="Assert failed") |
Always asserts a condition with customizable behavior. | |
template<typename T > | |
void | SortedInsert (std::vector< T > &range, T &&value) |
Inserts a value into a sorted vector while maintaining the sorted order. | |
template<typename T > | |
void | SortedInsert (std::vector< T > &range, T &&value, std::function< bool(T const &, T const &)> const &comparator) |
Inserts a value into a sorted vector while maintaining the sorted order using a custom comparator. | |
template<typename T > | |
void | SortedErase (std::vector< T > &range, T &&value) |
Efficiently erases elements equal to a given value from a sorted vector. | |
template<typename T > | |
void | SortedErase (std::vector< T > &range, T &&value, std::function< bool(T const &, T const &)> const &comparator) |
Efficiently erases elements equal to a given value from a sorted vector using a custom comparator. | |
template<typename T > | |
void | hash_combine (size_t &seed, T const &hash) |
Combines a hash value into an existing hash using bitwise operations. | |
std::string | as_lowercase (std::string_view const s) noexcept |
Converts a string to lowercase. | |
std::string | as_uppercase (std::string_view const s) noexcept |
Converts a string to uppercase. | |
constexpr std::string_view | ltrimview (std::string_view const s) noexcept |
Trims leading whitespace from a string view. | |
constexpr std::string_view | rtrimview (std::string_view const s) noexcept |
Trims trailing whitespace from a string view. | |
constexpr std::string_view | trimview (std::string_view const s) noexcept |
Trims leading and trailing whitespace from a string view. | |
std::string | ltrim (std::string const &s) noexcept |
Trims leading whitespace from a string. | |
std::string | rtrim (std::string const &s) noexcept |
Trims trailing whitespace from a string. | |
std::string | trim (std::string const &s) noexcept |
Trims leading and trailing whitespace from a string. | |
template<typename T , typename... Types> | |
consteval size_t | index_of_type () |
Function to find the index of a type in a parameter pack. | |
template<typename T , typename Func > | |
consteval std::size_t | index_of_function_arg (Func const &func={}) |
Function to find the index of a type within a function's argument list. | |
template<auto begin, auto end, auto inc, class F > | |
constexpr void | constexpr_for (F &&f) |
A constexpr loop for compile-time iteration. | |
template<auto begin, auto end, auto inc, class F > | |
constexpr void | constexpr_for_break (F &&f) |
template<class iterator , class F > | |
constexpr bool | for_each_true (iterator begin, iterator const &end, F &&f) |
Applies a function to each element in a range and returns true if all return true. | |
template<EnumClassConcept Enumeration> | |
constexpr auto | as_integer (Enumeration const value) -> typename std::underlying_type< Enumeration >::type |
Converts an enumeration class value to its underlying integer value. | |
std::string | wstring_to_string (std::wstring_view const wstr) |
Converts a wide string (UTF16) to a UTF-8 string. | |
std::wstring | string_to_wstring (std::string_view const str) |
Converts a UTF-8 string to a wide string (UTF16). | |
std::string | FormatErrorAsString (DWORD errorMessageID) |
Formats a Win32 error code as a string. | |
Contains a collection of tools and utilities provided by the MAL Toolkit library.
using mal_toolkit::ExponentialBackoffMs = ExponentialBackoff<std::chrono::milliseconds> |
Definition at line 166 of file backoffs.hpp.
using mal_toolkit::ExponentialBackoffNs = ExponentialBackoff<std::chrono::nanoseconds> |
Definition at line 164 of file backoffs.hpp.
using mal_toolkit::ExponentialBackoffSec = ExponentialBackoff<std::chrono::seconds> |
Definition at line 167 of file backoffs.hpp.
using mal_toolkit::ExponentialBackoffUs = ExponentialBackoff<std::chrono::microseconds> |
Definition at line 165 of file backoffs.hpp.
using mal_toolkit::HighResolutionTimer = Timer<std::chrono::high_resolution_clock> |
using mal_toolkit::LinearBackoffMs = LinearBackoff<std::chrono::milliseconds> |
Definition at line 171 of file backoffs.hpp.
using mal_toolkit::LinearBackoffNs = LinearBackoff<std::chrono::nanoseconds> |
Definition at line 169 of file backoffs.hpp.
using mal_toolkit::LinearBackoffSec = LinearBackoff<std::chrono::seconds> |
Definition at line 172 of file backoffs.hpp.
using mal_toolkit::LinearBackoffUs = LinearBackoff<std::chrono::microseconds> |
Definition at line 170 of file backoffs.hpp.
using mal_toolkit::return_type_t = typename return_type<T>::type |
Definition at line 351 of file template.hpp.
using mal_toolkit::SteadyTimer = Timer<std::chrono::steady_clock> |
|
inline |
Always asserts a condition with customizable behavior.
This function is used to assert a given condition, irrespective of the current debugging mode. If the condition evaluates to true, the function has no effect. However, if the condition is false, the behavior of the assertion depends on the configuration settings.
If logging is enabled (MAL_TOOLKIT_ASSERT_LOGS is set to true), the function generates a critical log message using the SPDLog library to indicate the assertion failure. Additionally, the assertion behavior in different contexts (debug or release mode) is determined by the following macros:
It is important to configure these macros according to the desired behavior for your application's debugging and error-handling strategy.
value | The condition to assert. |
message | An optional message to include in the log and assertion. |
Definition at line 94 of file debug_without_source_location.hpp.
|
inline |
Always asserts a condition with customizable behavior.
This function is used to assert a given condition, irrespective of the current debugging mode. If the condition evaluates to true, the function has no effect. However, if the condition is false, the behavior of the assertion depends on the configuration settings.
If logging is enabled (MAL_TOOLKIT_ASSERT_LOGS is set to true), the function generates a critical log message using the SPDLog library to indicate the assertion failure. Additionally, the assertion behavior in different contexts (debug or release mode) is determined by the following macros:
It is important to configure these macros according to the desired behavior for your application's debugging and error-handling strategy.
value | The condition to assert. |
message | An optional message to include in the log and assertion. |
location | The source location where the assertion occurred. |
Definition at line 116 of file debug_with_source_location.hpp.
|
constexpr |
Converts an enumeration class value to its underlying integer value.
Definition at line 255 of file template.hpp.
|
inlinenoexcept |
Converts a string to lowercase.
s | The input string view. |
Definition at line 14 of file string.hpp.
|
inlinenoexcept |
Converts a string to uppercase.
s | The input string view. |
Definition at line 27 of file string.hpp.
|
inline |
Asserts a condition with customizable behavior based on debug mode.
This function is used to assert a given condition in debug mode. If the condition is true, the function has no effect. If the condition is false, the assertion behavior depends on the configuration settings and the current debug mode.
In debug mode (MAL_TOOLKIT_DEBUG_ENABLED set to true), an assertion is triggered using the assert macro. The program halts, and debugging tools can be used to inspect the error.
In release mode, the behavior of the assertion is determined by the following macros:
It is important to configure these macros according to the desired behavior for your application's debugging and error-handling strategy.
value | The condition to assert. |
message | An optional message to include in the log and assertion. |
Definition at line 46 of file debug_without_source_location.hpp.
|
inline |
Asserts a condition with customizable behavior based on debug mode.
This function is used to assert a given condition in debug mode. If the condition is true, the function has no effect. If the condition is false, the assertion behavior depends on the configuration settings and the current debug mode.
In debug mode (MAL_TOOLKIT_DEBUG_ENABLED set to true), an assertion is triggered using the assert macro. The program halts, and debugging tools can be used to inspect the error.
In release mode, the behavior of the assertion is determined by the following macros:
It is important to configure these macros according to the desired behavior for your application's debugging and error-handling strategy.
value | The condition to assert. |
message | An optional message to include in the log and assertion. |
location | The source location where the assertion occurred. |
Definition at line 53 of file debug_with_source_location.hpp.
|
inlinenodiscard |
Convert a byte array to an int16_t value using little-endian byte order.
This function converts a byte array to an int16_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the int16_t value. |
Definition at line 480 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a byte array to an int32_t value using little-endian byte order.
This function converts a byte array to an int32_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the int32_t value. |
Definition at line 504 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a byte array to an int64_t value using little-endian byte order.
This function converts a byte array to an int64_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the int64_t value. |
Definition at line 528 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a byte array to a uint16_t value using little-endian byte order.
This function converts a byte array to a uint16_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the uint16_t value. |
Definition at line 408 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a byte array to a uint32_t value using little-endian byte order.
This function converts a byte array to a uint32_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the uint32_t value. |
Definition at line 432 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a byte array to a uint64_t value using little-endian byte order.
This function converts a byte array to a uint64_t value, assuming little-endian byte order.
byte_view | The ByteView containing the byte representation of the uint64_t value. |
Definition at line 456 of file byte-helper.hpp.
|
constexpr |
A constexpr loop for compile-time iteration.
Definition at line 202 of file template.hpp.
|
constexpr |
|
inline |
Returns an empty string representing the current source location.
This function is provided for compatibility when source location is not available. It always returns an empty string.
Definition at line 17 of file debug_without_source_location.hpp.
|
inline |
Generates a string representation of the current source location.
location | The source location information (default: current location). |
Definition at line 18 of file debug_with_source_location.hpp.
|
constexpr |
Applies a function to each element in a range and returns true if all return true.
Definition at line 235 of file template.hpp.
|
inline |
Formats a Win32 error code as a string.
This function converts a Win32 error code into a human-readable error message. If the error message ID is 0, an empty string is returned.
errorMessageID | The Win32 error code. |
Definition at line 53 of file win-utils.hpp.
size_t mal_toolkit::GetFunctionAddress | ( | std::function< T(U...)> | f | ) |
Get the address of a callable function.
T | Return type of the function. |
U | Argument types of the function. |
f | The function to get the address of. |
Definition at line 18 of file callback-system.hpp.
void mal_toolkit::hash_combine | ( | size_t & | seed, |
T const & | hash ) |
Combines a hash value into an existing hash using bitwise operations.
seed | The existing hash value, which will be updated. |
hash | The hash value to combine. |
Definition at line 68 of file stl-helpers.hpp.
|
consteval |
Function to find the index of a type within a function's argument list.
This template function determines the index of a specified type T
within the argument list of a provided function Func
. The function is evaluated at compile time and returns the index of the first occurrence of the specified type in the argument list of the function.
T | The type whose index is to be found within the function's argument list. |
Func | The function type whose argument list is to be searched. |
func | An instance of the function for which the argument list type index is sought. |
T
in the function's argument list. Definition at line 191 of file template.hpp.
|
consteval |
Function to find the index of a type in a parameter pack.
This template function determines the index of a specified type T
within a parameter pack Types
. The function is evaluated at compile time and returns the index of the first occurrence of the specified type in the parameter pack.
T | The type whose index is to be found within the parameter pack. |
Types | The parameter pack in which the type index is searched. |
T
in the parameter pack. Definition at line 173 of file template.hpp.
|
inlinenodiscard |
Convert an int16_t value to a ByteArray using little-endian byte order.
This function converts an int16_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The int16_t value to convert. |
Definition at line 494 of file byte-helper.hpp.
|
inlinenodiscard |
Convert an int32_t value to a ByteArray using little-endian byte order.
This function converts an int32_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The int32_t value to convert. |
Definition at line 518 of file byte-helper.hpp.
|
inlinenodiscard |
Convert an int64_t value to a ByteArray using little-endian byte order.
This function converts an int64_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The int64_t value to convert. |
Definition at line 542 of file byte-helper.hpp.
|
inlinenoexcept |
Trims leading whitespace from a string.
s | The input string. |
Definition at line 68 of file string.hpp.
|
constexprnoexcept |
Trims leading whitespace from a string view.
s | The input string view. |
Definition at line 40 of file string.hpp.
|
inlinenoexcept |
Trims trailing whitespace from a string.
s | The input string. |
Definition at line 74 of file string.hpp.
|
constexprnoexcept |
Trims trailing whitespace from a string view.
s | The input string view. |
Definition at line 50 of file string.hpp.
void mal_toolkit::SortedErase | ( | std::vector< T > & | range, |
T && | value ) |
Efficiently erases elements equal to a given value from a sorted vector.
range | The sorted vector to erase from. |
value | The value to erase. |
Definition at line 42 of file stl-helpers.hpp.
void mal_toolkit::SortedErase | ( | std::vector< T > & | range, |
T && | value, | ||
std::function< bool(T const &, T const &)> const & | comparator ) |
Efficiently erases elements equal to a given value from a sorted vector using a custom comparator.
range | The sorted vector to erase from. |
value | The value to erase. |
comparator | A function that compares two values. |
Definition at line 56 of file stl-helpers.hpp.
void mal_toolkit::SortedInsert | ( | std::vector< T > & | range, |
T && | value ) |
Inserts a value into a sorted vector while maintaining the sorted order.
range | The sorted vector to insert into. |
value | The value to insert. |
Definition at line 16 of file stl-helpers.hpp.
void mal_toolkit::SortedInsert | ( | std::vector< T > & | range, |
T && | value, | ||
std::function< bool(T const &, T const &)> const & | comparator ) |
Inserts a value into a sorted vector while maintaining the sorted order using a custom comparator.
range | The sorted vector to insert into. |
value | The value to insert. |
comparator | A function that compares two values. |
Definition at line 30 of file stl-helpers.hpp.
|
inline |
Converts a UTF-8 string to a wide string (UTF16).
str | The input UTF-8 string. |
Definition at line 34 of file win-utils.hpp.
|
inline |
Convert a string_view to an optional int64_t.
Converts the given string_view to an int64_t using the strtoll function. If the conversion is successful, returns an optional containing the result, otherwise returns an empty optional.
str | The string_view to convert. |
Definition at line 21 of file converter.hpp.
|
inline |
Convert a string_view to an optional long double.
Converts the given string_view to a long double using the strtold function. If the conversion is successful, returns an optional containing the result, otherwise returns an empty optional.
str | The string_view to convert. |
Definition at line 65 of file converter.hpp.
|
inline |
Convert a string_view to an optional uint64_t.
Converts the given string_view to a uint64_t using the strtoull function. If the conversion is successful, returns an optional containing the result, otherwise returns an empty optional.
str | The string_view to convert. |
Definition at line 43 of file converter.hpp.
|
inlinenoexcept |
Trims leading and trailing whitespace from a string.
s | The input string. |
Definition at line 81 of file string.hpp.
|
constexprnoexcept |
Trims leading and trailing whitespace from a string view.
s | The input string view. |
Definition at line 61 of file string.hpp.
|
inlinenodiscard |
Convert a uint16_t value to a ByteArray using little-endian byte order.
This function converts a uint16_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The uint16_t value to convert. |
Definition at line 422 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a uint32_t value to a ByteArray using little-endian byte order.
This function converts a uint32_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The uint32_t value to convert. |
Definition at line 446 of file byte-helper.hpp.
|
inlinenodiscard |
Convert a uint64_t value to a ByteArray using little-endian byte order.
This function converts a uint64_t value to a ByteArray of appropriate size, using little-endian byte order.
value | The uint64_t value to convert. |
Definition at line 470 of file byte-helper.hpp.
|
inline |
Converts a wide string (UTF16) to a UTF-8 string.
wstr | The input wide string. |
Definition at line 18 of file win-utils.hpp.