mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
FS refactoring, 64-bit timestamps
This commit is contained in:
@@ -1,37 +1,54 @@
|
||||
#include "ByteSwap.h"
|
||||
#include "ByteSwap.h"
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteSwap
|
||||
{
|
||||
void BigInt16(int16_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
|
||||
{
|
||||
template<class TNumberType, class TUnsignedType>
|
||||
void SwapArbitrary(TNumberType &v)
|
||||
{
|
||||
PL_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
|
||||
|
||||
uint8_t bytes[sizeof(TNumberType)];
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
bytes[i] = reinterpret_cast<const uint8_t*>(&v)[i];
|
||||
|
||||
TUnsignedType result = 0;
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
result |= static_cast<TUnsignedType>(bytes[i]) << (sizeof(TUnsignedType) * 8 - 8 - (i * 8));
|
||||
|
||||
v = static_cast<int16_t>((asS8[0] << 8) | asU8[1]);
|
||||
v = static_cast<TNumberType>(result);
|
||||
}
|
||||
|
||||
void BigInt16(int16_t &v)
|
||||
{
|
||||
SwapArbitrary<int16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigInt32(int32_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
|
||||
|
||||
v = static_cast<int32_t>((asS8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
|
||||
SwapArbitrary<int32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt16(uint16_t &v)
|
||||
void BigInt64(int64_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
SwapArbitrary<int64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
v = static_cast<uint16_t>((asU8[0] << 8) | asU8[1]);
|
||||
void BigUInt16(uint16_t &v)
|
||||
{
|
||||
SwapArbitrary<uint16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt32(uint32_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
SwapArbitrary<uint32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
v = static_cast<uint32_t>((asU8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
|
||||
void BigUInt64(uint64_t &v)
|
||||
{
|
||||
SwapArbitrary<uint64_t, uint64_t>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user