66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: auMagicUtils.hpp
|
|
Date: 2022-2-1
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
/**
|
|
* @brief
|
|
* @param buffer
|
|
* @return A non-determinstic/platform specific magic number that once written with respect to endianness emits the tag
|
|
*/
|
|
static constexpr auline AuUInt32 AuConvertMagicTag32(const char buffer[4])
|
|
{
|
|
AuUInt32 magic {};
|
|
if (Aurora::Build::kCurrentEndian == Aurora::Build::ECPUEndian::eCPULittle)
|
|
{
|
|
magic |= AuUInt32(buffer[0]);
|
|
magic |= AuUInt32(buffer[1]) << 8;
|
|
magic |= AuUInt32(buffer[2]) << 16;
|
|
magic |= AuUInt32(buffer[3]) << 24;
|
|
}
|
|
else
|
|
{
|
|
magic |= AuUInt32(buffer[4]);
|
|
magic |= AuUInt32(buffer[2]) << 8;
|
|
magic |= AuUInt32(buffer[1]) << 16;
|
|
magic |= AuUInt32(buffer[0]) << 24;
|
|
}
|
|
return magic;
|
|
}
|
|
|
|
/**
|
|
* @brief
|
|
* @param buffer
|
|
* @return A non-determinstic/platform specific magic number that once written with respect to endianness emits the tag
|
|
*/
|
|
static constexpr auline AuUInt64 AuConvertMagicTag64(const char buffer[8])
|
|
{
|
|
AuUInt64 magic {};
|
|
if (Aurora::Build::kCurrentEndian == Aurora::Build::ECPUEndian::eCPULittle)
|
|
{
|
|
magic |= AuUInt64(buffer[0]);
|
|
magic |= AuUInt64(buffer[1]) << 8;
|
|
magic |= AuUInt64(buffer[2]) << 16;
|
|
magic |= AuUInt64(buffer[3]) << 24;
|
|
magic |= AuUInt64(buffer[4]) << 32;
|
|
magic |= AuUInt64(buffer[5]) << 40;
|
|
magic |= AuUInt64(buffer[6]) << 48;
|
|
magic |= AuUInt64(buffer[7]) << 56;
|
|
}
|
|
else
|
|
{
|
|
magic |= AuUInt64(buffer[7]);
|
|
magic |= AuUInt64(buffer[6]) << 8;
|
|
magic |= AuUInt64(buffer[5]) << 16;
|
|
magic |= AuUInt64(buffer[4]) << 24;
|
|
magic |= AuUInt64(buffer[3]) << 32;
|
|
magic |= AuUInt64(buffer[2]) << 40;
|
|
magic |= AuUInt64(buffer[1]) << 48;
|
|
magic |= AuUInt64(buffer[0]) << 56;
|
|
}
|
|
return magic;
|
|
} |