EHS/include/Data.h

45 lines
1.0 KiB
C
Raw Normal View History

2023-12-17 03:29:08 -08:00
#pragma once
#include "EHS.h"
#include "Serializer.h"
2023-12-17 15:56:13 -08:00
namespace ehs
2023-12-17 03:29:08 -08:00
{
class Data
{
public:
template<typename T>
static void SwapEndianness(T* value)
{
Byte tmp = 0;
for (UInt_64 i = 0; i < sizeof(T) / 2; ++i)
{
tmp = ((Byte*)value)[i];
((Byte*)value)[i] = ((Byte*)value)[sizeof(T) - i - 1];
((Byte*)value)[sizeof(T) - i - 1] = tmp;
}
}
template<typename T>
static Array<T> SwapEndianness(const T* const array, const UInt_64 size)
{
Array<T> result(size);
for (UInt_64 i = size; i; --i)
result[size - i] = array[i - 1];
return result;
}
template<typename N>
static Serializer<N> SwapEndianness(const Serializer<N>& data)
{
Serializer<N> result(data.Size());
for (N i = 0; i < data.Size(); ++i)
result[i] = data[data.Size() - i - 1];
return result;
}
};
}