Documentation for module: Network
Former-commit-id: cb5674c011d3d6895848cab77bb2e4a05e5d9b7b
This commit is contained in:
@@ -9,21 +9,46 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a NetPacket object by default
|
||||
*/
|
||||
|
||||
inline NetPacket::NetPacket() :
|
||||
m_netCode(NetCode_Invalid)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a NetPacket object with a packet number and a minimal capacity
|
||||
*
|
||||
* \param netCode Packet number
|
||||
* \param minCapacity Minimal capacity of the packet
|
||||
*/
|
||||
|
||||
inline NetPacket::NetPacket(UInt16 netCode, std::size_t minCapacity)
|
||||
{
|
||||
Reset(netCode, minCapacity);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a NetPacket object with a packet number and raw memory
|
||||
*
|
||||
* \param netCode Packet number
|
||||
* \param ptr Raw memory
|
||||
* \param size Size of the memory
|
||||
*/
|
||||
|
||||
inline NetPacket::NetPacket(UInt16 netCode, const void* ptr, std::size_t size)
|
||||
{
|
||||
Reset(netCode, ptr, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a NetPacket object with another one by move semantic
|
||||
*
|
||||
* \param packet NetPacket to move into this
|
||||
*/
|
||||
|
||||
inline NetPacket::NetPacket(NetPacket&& packet) :
|
||||
ByteStream(std::move(packet)),
|
||||
m_buffer(std::move(packet.m_buffer)),
|
||||
@@ -35,12 +60,23 @@ namespace Nz
|
||||
SetStream(&m_memoryStream);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object
|
||||
*/
|
||||
|
||||
inline NetPacket::~NetPacket()
|
||||
{
|
||||
FlushBits(); //< Needs to be done here as the stream will be freed before ByteStream calls it
|
||||
FreeStream();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Constant raw buffer
|
||||
*
|
||||
* \remark Produces a NazaraAssert if internal buffer is invalid
|
||||
*/
|
||||
|
||||
inline const UInt8* NetPacket::GetConstData() const
|
||||
{
|
||||
NazaraAssert(m_buffer, "Invalid buffer");
|
||||
@@ -48,6 +84,13 @@ namespace Nz
|
||||
return m_buffer->GetConstBuffer();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Raw buffer
|
||||
*
|
||||
* \remark Produces a NazaraAssert if internal buffer is invalid
|
||||
*/
|
||||
|
||||
inline UInt8* NetPacket::GetData() const
|
||||
{
|
||||
NazaraAssert(m_buffer, "Invalid buffer");
|
||||
@@ -55,6 +98,11 @@ namespace Nz
|
||||
return m_buffer->GetBuffer();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the data
|
||||
* \return Size of the data
|
||||
*/
|
||||
|
||||
inline size_t NetPacket::GetDataSize() const
|
||||
{
|
||||
if (m_buffer)
|
||||
@@ -63,22 +111,46 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the packet number
|
||||
* \return Packet number
|
||||
*/
|
||||
|
||||
inline UInt16 NetPacket::GetNetCode() const
|
||||
{
|
||||
return m_netCode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the packet
|
||||
*/
|
||||
|
||||
inline void NetPacket::Reset()
|
||||
{
|
||||
FreeStream();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the packet with a packet number and a minimal capacity
|
||||
*
|
||||
* \param netCode Packet number
|
||||
* \param minCapacity Minimal capacity of the packet
|
||||
*/
|
||||
|
||||
inline void NetPacket::Reset(UInt16 netCode, std::size_t minCapacity)
|
||||
{
|
||||
InitStream(HeaderSize + minCapacity, HeaderSize, OpenMode_ReadWrite);
|
||||
m_netCode = netCode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the packet with a packet number and raw memory
|
||||
*
|
||||
* \param netCode Packet number
|
||||
* \param ptr Raw memory
|
||||
* \param size Size of the memory
|
||||
*/
|
||||
|
||||
inline void NetPacket::Reset(UInt16 netCode, const void* ptr, std::size_t size)
|
||||
{
|
||||
InitStream(HeaderSize + size, HeaderSize, OpenMode_ReadOnly);
|
||||
@@ -88,6 +160,14 @@ namespace Nz
|
||||
m_netCode = netCode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resizes the packet
|
||||
*
|
||||
* \param newSize Size for the resizing operation
|
||||
*
|
||||
* \remark Produces a NazaraAssert if internal buffer is invalid
|
||||
*/
|
||||
|
||||
inline void NetPacket::Resize(std::size_t newSize)
|
||||
{
|
||||
NazaraAssert(m_buffer, "Invalid buffer");
|
||||
@@ -95,11 +175,24 @@ namespace Nz
|
||||
m_buffer->Resize(newSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the packet number
|
||||
*
|
||||
* \param netCode Packet number
|
||||
*/
|
||||
|
||||
inline void NetPacket::SetNetCode(UInt16 netCode)
|
||||
{
|
||||
m_netCode = netCode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the NetPacket into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param packet NetPacket to move in this
|
||||
*/
|
||||
|
||||
inline NetPacket& Nz::NetPacket::operator=(NetPacket&& packet)
|
||||
{
|
||||
FreeStream();
|
||||
|
||||
Reference in New Issue
Block a user