Network/Algorithm: Add HostToNet and NetToHost
This commit is contained in:
parent
85257da07e
commit
a087174bf8
|
|
@ -11,10 +11,17 @@
|
||||||
#include <Nazara/Network/Config.hpp>
|
#include <Nazara/Network/Config.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
NAZARA_NETWORK_API bool ParseIPAddress(const char* addressPtr, UInt8 result[16], UInt16* port = nullptr, bool* isIPv6 = nullptr, const char** endOfRead = nullptr);
|
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>
|
#include <Nazara/Network/Algorithm.inl>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,31 @@
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// 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>
|
#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>
|
#include <Nazara/Network/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,13 @@
|
||||||
#include <Nazara/Network/ENetHost.hpp>
|
#include <Nazara/Network/ENetHost.hpp>
|
||||||
#include <Nazara/Core/Clock.hpp>
|
#include <Nazara/Core/Clock.hpp>
|
||||||
#include <Nazara/Core/Endianness.hpp>
|
|
||||||
#include <Nazara/Core/OffsetOf.hpp>
|
#include <Nazara/Core/OffsetOf.hpp>
|
||||||
|
#include <Nazara/Network/Algorithm.hpp>
|
||||||
#include <Nazara/Network/ENetPeer.hpp>
|
#include <Nazara/Network/ENetPeer.hpp>
|
||||||
#include <Nazara/Network/NetPacket.hpp>
|
#include <Nazara/Network/NetPacket.hpp>
|
||||||
#include <Nazara/Network/Debug.hpp>
|
#include <Nazara/Network/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
/// Temporary
|
|
||||||
template<typename T>
|
|
||||||
T HostToNet(T value)
|
|
||||||
{
|
|
||||||
#ifdef NAZARA_LITTLE_ENDIAN
|
|
||||||
return SwapBytes(value);
|
|
||||||
#else
|
|
||||||
return value;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Temporary
|
|
||||||
template<typename T>
|
|
||||||
T NetToHost(T value)
|
|
||||||
{
|
|
||||||
#ifdef NAZARA_LITTLE_ENDIAN
|
|
||||||
return SwapBytes(value);
|
|
||||||
#else
|
|
||||||
return value;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static std::size_t s_commandSizes[ENetProtocolCommand_Count] =
|
static std::size_t s_commandSizes[ENetProtocolCommand_Count] =
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,11 @@
|
||||||
#include <Nazara/Network/ENetPeer.hpp>
|
#include <Nazara/Network/ENetPeer.hpp>
|
||||||
#include <Nazara/Core/Endianness.hpp>
|
#include <Nazara/Network/Algorithm.hpp>
|
||||||
#include <Nazara/Network/ENetHost.hpp>
|
#include <Nazara/Network/ENetHost.hpp>
|
||||||
#include <Nazara/Network/NetPacket.hpp>
|
#include <Nazara/Network/NetPacket.hpp>
|
||||||
#include <Nazara/Network/Debug.hpp>
|
#include <Nazara/Network/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
/// Temporary
|
|
||||||
template<typename T>
|
|
||||||
T HostToNet(T value)
|
|
||||||
{
|
|
||||||
#ifdef NAZARA_LITTLE_ENDIAN
|
|
||||||
return SwapBytes(value);
|
|
||||||
#else
|
|
||||||
return value;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Temporary
|
|
||||||
template<typename T>
|
|
||||||
T NetToHost(T value)
|
|
||||||
{
|
|
||||||
#ifdef NAZARA_LITTLE_ENDIAN
|
|
||||||
return SwapBytes(value);
|
|
||||||
#else
|
|
||||||
return value;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
ENetPeer::ENetPeer(ENetHost* host, UInt16 peerId) :
|
ENetPeer::ENetPeer(ENetHost* host, UInt16 peerId) :
|
||||||
m_host(host),
|
m_host(host),
|
||||||
m_packetPool(sizeof(ENetPacket)),
|
m_packetPool(sizeof(ENetPacket)),
|
||||||
|
|
@ -683,7 +661,7 @@ namespace Nz
|
||||||
startCommand->fragments.Set(fragmentNumber, true);
|
startCommand->fragments.Set(fragmentNumber, true);
|
||||||
|
|
||||||
if (fragmentOffset + fragmentLength > startCommand->packet->data.GetDataSize())
|
if (fragmentOffset + fragmentLength > startCommand->packet->data.GetDataSize())
|
||||||
fragmentLength = startCommand->packet->data.GetDataSize() - fragmentOffset;
|
fragmentLength = static_cast<UInt16>(startCommand->packet->data.GetDataSize() - fragmentOffset);
|
||||||
|
|
||||||
std::memcpy(startCommand->packet->data.GetData() + NetPacket::HeaderSize + fragmentOffset, reinterpret_cast<const UInt8*>(command) + sizeof(ENetProtocolSendFragment), fragmentLength);
|
std::memcpy(startCommand->packet->data.GetData() + NetPacket::HeaderSize + fragmentOffset, reinterpret_cast<const UInt8*>(command) + sizeof(ENetProtocolSendFragment), fragmentLength);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue