// // Created by erki on 10/12/22. // #ifndef SKULLC_UTILITY_BYTES_HPP_ #define SKULLC_UTILITY_BYTES_HPP_ #include #include #include #include namespace Utility { template T arrayToType(const std::uint8_t raw[N]) { static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); static_assert(sizeof(T) == N, "The raw data array is not the same size as T."); T t; std::memcpy(&t, raw, sizeof(T)); return t; } template T arrayToType(const std::array raw) { static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); static_assert(sizeof(T) == N, "The raw data array is not the same size as T."); T t; std::memcpy(&t, raw.data(), sizeof(T)); return t; } template constexpr T zeroInitialized() { static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); T t; std::memset(&t, 0, sizeof(T)); return t; } template void zeroInitialized(T& t) { static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); std::memset(&t, 0, sizeof(T)); } template void zeroInitialized(T* t) { static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); std::memset(t, 0, sizeof(T)); } }// namespace Utility #endif//SKULLC_UTILITY_BYTES_HPP_