mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-10-30 07:11:38 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
	
		
			658 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
	
		
			658 B
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once 
 | 
						|
 | 
						|
#include <cassert>
 | 
						|
 | 
						|
template<typename T>
 | 
						|
inline T ByteSwap(T value)
 | 
						|
{
 | 
						|
    if constexpr (sizeof(T) == 1)
 | 
						|
        return value;
 | 
						|
    else if constexpr (sizeof(T) == 2)
 | 
						|
        return static_cast<T>(__builtin_bswap16(static_cast<uint16_t>(value)));
 | 
						|
    else if constexpr (sizeof(T) == 4)
 | 
						|
        return static_cast<T>(__builtin_bswap32(static_cast<uint32_t>(value)));
 | 
						|
    else if constexpr (sizeof(T) == 8)
 | 
						|
        return static_cast<T>(__builtin_bswap64(static_cast<uint64_t>(value)));
 | 
						|
 | 
						|
    assert(false && "Unexpected byte size.");
 | 
						|
    return value;
 | 
						|
}
 | 
						|
 | 
						|
template<typename T>
 | 
						|
inline void ByteSwapInplace(T& value)
 | 
						|
{
 | 
						|
    value = ByteSwap(value);
 | 
						|
}
 |