NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches

Provides functions and classes for handling binary data. More...

Classes

class  nnl::utl::data::MD5Context
 A utility class for calculating MD5 message digests. More...

Functions

constexpr u32 nnl::utl::data::FourCC (const char(&str)[5]) noexcept
 Generates a numeric four character code from a given string.
template<typename T>
nnl::utl::data::SwapEndian (T src) noexcept
 Swaps endianness of a value.
template<typename E>
constexpr std::underlying_type< E >::type nnl::utl::data::as_int (E e) noexcept
 Converts an enum value to its underlying integer type.
template<class T, class U>
constexpr T nnl::utl::data::narrow_cast (U &&u) noexcept
 Narrowing cast without bounds checking.
template<class T, class U, typename std::enable_if< std::is_arithmetic< T >::value >::type * = nullptr>
constexpr T nnl::utl::data::narrow (U u)
 Safe narrowing cast with runtime bounds checking.
u32 nnl::utl::data::CRC32 (BufferView data, u32 polynomial=0xEDB88320) noexcept
 Calculates a CRC32 checksum.
u32 nnl::utl::data::XXH32 (BufferView data, u32 seed=0xC0108888)
 Calculates an XXH32 checksum.
std::array< u8, 16 > nnl::utl::data::MD5 (BufferView data) noexcept
 Calculates an MD5 checksum.
template<typename To, typename From>
auto nnl::utl::data::ReinterpretContainer (const std::vector< From > &container)
 Reinterprets container data as a different type (via a bitwise copy)
template<typename To, typename From>
auto nnl::utl::data::CastContainer (const std::vector< From > &container)
 Casts container elements to a different type.

Detailed Description

Provides functions and classes for handling binary data.


Class Documentation

◆ nnl::utl::data::MD5Context

class nnl::utl::data::MD5Context

A utility class for calculating MD5 message digests.

This class provides a stateful interface for computing 128-bit hashes using the MD5 algorithm. It follows the "update-final" pattern, allowing datasets to be processed in chunks.

Public Member Functions

void Update (BufferView data) noexcept
 Updates the hash state by processing a new chunk of data.
std::array< u8, 16 > Final () noexcept
 Finalizes the hashing process and retrieves the result.

Member Function Documentation

◆ Final()

std::array< u8, 16 > nnl::utl::data::MD5Context::Final ( )
nodiscardnoexcept

Finalizes the hashing process and retrieves the result.

Returns
A 16-byte array containing the resulting message digest.

◆ Update()

void nnl::utl::data::MD5Context::Update ( BufferView data)
noexcept

Updates the hash state by processing a new chunk of data.

Parameters
dataThe input data to be hashed.

Function Documentation

◆ as_int()

template<typename E>
std::underlying_type< E >::type nnl::utl::data::as_int ( E e)
constexprnoexcept

Converts an enum value to its underlying integer type.

Template Parameters
EEnum type
Parameters
eEnum value
Returns
The underlying integer value of the enum

◆ CastContainer()

template<typename To, typename From>
auto nnl::utl::data::CastContainer ( const std::vector< From > & container)

Casts container elements to a different type.

Template Parameters
ToDestination type
FromSource type
Parameters
containerSource container
Returns
New container with casted elements

◆ CRC32()

u32 nnl::utl::data::CRC32 ( BufferView data,
u32 polynomial = 0xEDB88320 )
noexcept

Calculates a CRC32 checksum.

Parameters
dataData to digest
polynomialCustom polynomial
Returns
CRC32 checksum

◆ FourCC()

u32 nnl::utl::data::FourCC ( const char(&) str[5])
constexprnoexcept

Generates a numeric four character code from a given string.

Combines character values of the input string into a single unsigned integer.

Parameters
strInput string.
Returns
A u32 code.

◆ MD5()

std::array< u8, 16 > nnl::utl::data::MD5 ( BufferView data)
noexcept

Calculates an MD5 checksum.

std::vector<unsigned char> buffer(16,0);
auto digest = utl::data::MD5(buffer);
// auto digest = utl::data::MD5({buffer.data(), buffer.size()*sizeof(unsigned char)});
std::array< u8, 16 > MD5(BufferView data) noexcept
Calculates an MD5 checksum.
Parameters
dataData to digest
Returns
MD5 checksum

◆ narrow()

template<class T, class U, typename std::enable_if< std::is_arithmetic< T >::value >::type * = nullptr>
T nnl::utl::data::narrow ( U u)
constexpr

Safe narrowing cast with runtime bounds checking.

Template Parameters
TDestination type
USource type
Parameters
uValue to cast
Returns
Narrowed value of type T
Exceptions
NarrowErrorif narrowing would lose information
See also
nnl::utl::data::narrow_cast

◆ narrow_cast()

template<class T, class U>
T nnl::utl::data::narrow_cast ( U && u)
constexprnoexcept

Narrowing cast without bounds checking.

This is a semantic alias for static_cast. It signals intent that a loss of precision is expected and handled.

Template Parameters
TDestination type
USource type
Parameters
uValue to cast
Returns
Narrowed value of type T
See also
nnl::utl::data::narrow

◆ ReinterpretContainer()

template<typename To, typename From>
auto nnl::utl::data::ReinterpretContainer ( const std::vector< From > & container)

Reinterprets container data as a different type (via a bitwise copy)

Template Parameters
ToDestination type
FromSource type
Parameters
containerSource container
Returns
New container with reinterpreted data
Exceptions
RuntimeErrorif the byte size of containers is not the same

◆ SwapEndian()

template<typename T>
T nnl::utl::data::SwapEndian ( T src)
noexcept

Swaps endianness of a value.

Template Parameters
TNumeric type
Parameters
srcValue to swap
Returns
Value with swapped endianness

◆ XXH32()

u32 nnl::utl::data::XXH32 ( BufferView data,
u32 seed = 0xC0108888 )

Calculates an XXH32 checksum.

Parameters
dataData to digest
seedCustom seed
Returns
XXH32 checksum