Network/Algorithm: Add HostToNet and NetToHost
This commit is contained in:
@@ -11,10 +11,17 @@
|
||||
#include <Nazara/Network/Config.hpp>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
NAZARA_NETWORK_API bool ParseIPAddress(const char* addressPtr, UInt8 result[16], UInt16* port = nullptr, bool* isIPv6 = nullptr, const char** endOfRead = nullptr);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, T> HostToNet(T value);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, T> NetToHost(T value);
|
||||
}
|
||||
|
||||
#include <Nazara/Network/Algorithm.inl>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user