mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 17:04:14 +01:00
Add IntegerFor
template class + Update GenerateUuidV4
This commit is contained in:
parent
ea3c7301b1
commit
14dc42b991
@ -340,6 +340,20 @@ namespace skyline {
|
||||
return frz::elsa<frz::string>{}(frz::string(view.data(), view.size()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects the largest possible integer type for representing an object alongside providing the size of the object in terms of the underlying type
|
||||
*/
|
||||
template<class T>
|
||||
struct IntegerFor {
|
||||
using type = std::conditional_t<sizeof(T) % sizeof(u64) == 0, u64,
|
||||
std::conditional_t<sizeof(T) % sizeof(u32) == 0, u32,
|
||||
std::conditional_t<sizeof(T) % sizeof(u16) == 0, u16, u8>
|
||||
>
|
||||
>;
|
||||
|
||||
static constexpr size_t count{sizeof(T) / sizeof(type)};
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
static thread_local std::mt19937_64 generator{GetTimeTicks()};
|
||||
}
|
||||
@ -354,6 +368,11 @@ namespace skyline {
|
||||
|
||||
std::generate(in.begin(), in.end(), gen);
|
||||
}
|
||||
|
||||
template<class T> requires (!std::is_integral_v<T> && std::is_trivially_copyable_v<T>)
|
||||
void FillRandomBytes(T &object) {
|
||||
FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::type *>(&object), IntegerFor<T>::count));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ namespace skyline {
|
||||
|
||||
// Create an initial random UUID
|
||||
UuidLayout uuid;
|
||||
util::FillRandomBytes(span(&uuid, 1).cast<u64>());
|
||||
util::FillRandomBytes(uuid);
|
||||
|
||||
// Set format bits
|
||||
uuid.reserved = reserved;
|
||||
|
Loading…
Reference in New Issue
Block a user