Network/Algorithm: Add HostToNet and NetToHost

This commit is contained in:
Lynix
2017-02-01 00:13:08 +01:00
parent 85257da07e
commit a087174bf8
4 changed files with 35 additions and 47 deletions

View File

@@ -2,6 +2,31 @@
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Network/Debug.hpp>
namespace Nz
{
template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value, T> HostToNet(T value)
{
#ifdef NAZARA_LITTLE_ENDIAN
return SwapBytes(value);
#else
return value;
#endif
}
template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value, T> NetToHost(T value)
{
#ifdef NAZARA_LITTLE_ENDIAN
return SwapBytes(value);
#else
return value;
#endif
}
}
#include <Nazara/Network/DebugOff.hpp>