Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::NetPacket Class Reference

Network class that represents a packet. More...

Inheritance diagram for Nz::NetPacket:
Nz::ByteStream

Public Member Functions

 NetPacket ()
 Constructs a NetPacket object by default.
 
 NetPacket (UInt16 netCode, std::size_t minCapacity=0)
 Constructs a NetPacket object with a packet number and a minimal capacity. More...
 
 NetPacket (UInt16 netCode, const void *ptr, std::size_t size)
 Constructs a NetPacket object with a packet number and raw memory. More...
 
 NetPacket (const NetPacket &)=delete
 
 NetPacket (NetPacket &&packet)
 Constructs a NetPacket object with another one by move semantic. More...
 
 ~NetPacket ()
 Destructs the object.
 
const UInt8 * GetConstData () const
 Gets the raw buffer. More...
 
UInt8 * GetData () const
 Gets the raw buffer. More...
 
size_t GetDataSize () const
 Gets the size of the data. More...
 
UInt16 GetNetCode () const
 Gets the packet number. More...
 
virtual void OnReceive (UInt16 netCode, const void *data, std::size_t size)
 Operation to do when receiving data. More...
 
virtual const void * OnSend (std::size_t *newSize) const
 Operation to do when sending data. More...
 
void Reset ()
 Resets the packet.
 
void Reset (UInt16 netCode, std::size_t minCapacity=0)
 Resets the packet with a packet number and a minimal capacity. More...
 
void Reset (UInt16 netCode, const void *ptr, std::size_t size)
 Resets the packet with a packet number and raw memory. More...
 
void Resize (std::size_t newSize)
 Resizes the packet. More...
 
void SetNetCode (UInt16 netCode)
 Sets the packet number. More...
 
NetPacketoperator= (const NetPacket &)=delete
 
NetPacketoperator= (NetPacket &&packet)
 Moves the NetPacket into this. More...
 
- Public Member Functions inherited from Nz::ByteStream
 ByteStream (Stream *stream=nullptr)
 Constructs a ByteStream object with a stream.
 
 ByteStream (ByteArray *byteArray, OpenModeFlags openMode=OpenMode_ReadWrite)
 Constructs a ByteStream object with a byte array. More...
 
 ByteStream (void *ptr, Nz::UInt64 size)
 Constructs a ByteStream object with a raw memory and a size. More...
 
 ByteStream (const void *ptr, Nz::UInt64 size)
 Constructs a ByteStream object with a raw memory and a size. More...
 
 ByteStream (const ByteStream &)=delete
 
 ByteStream (ByteStream &&stream)
 Constructs a ByteStream object by move semantic. More...
 
virtual ~ByteStream ()
 Destructs the object and calls FlushBits. More...
 
Endianness GetDataEndianness () const
 Gets the stream endianness. More...
 
Nz::UInt64 GetSize () const
 Gets the size of the byte stream. More...
 
StreamGetStream () const
 Gets the internal stream. More...
 
bool FlushBits ()
 Flushes the stream. More...
 
std::size_t Read (void *ptr, std::size_t size)
 Reads data. More...
 
void SetDataEndianness (Endianness endiannes)
 Sets the stream endianness. More...
 
void SetStream (Stream *stream)
 Sets this with a stream. More...
 
void SetStream (ByteArray *byteArray, OpenModeFlags openMode=OpenMode_ReadWrite)
 Sets this with a byte array. More...
 
void SetStream (void *ptr, Nz::UInt64 size)
 Sets this with a raw memory and a size. More...
 
void SetStream (const void *ptr, Nz::UInt64 size)
 Sets this with a raw memory and a size. More...
 
void Write (const void *data, std::size_t size)
 Writes data. More...
 
template<typename T >
ByteStreamoperator>> (T &value)
 Outputs a data from the stream. More...
 
template<typename T >
ByteStreamoperator<< (const T &value)
 Adds the data to the stream. More...
 
ByteStreamoperator= (const ByteStream &)=delete
 
ByteStreamoperator= (ByteStream &&)
 Moves the other byte stream into this. More...
 

Static Public Member Functions

static bool DecodeHeader (const void *data, UInt16 *packetSize, UInt16 *netCode)
 Decodes the header of the packet. More...
 
static bool EncodeHeader (void *data, UInt16 packetSize, UInt16 netCode)
 Encodes the header of the packet. More...
 

Static Public Attributes

static constexpr std::size_t HeaderSize = sizeof(UInt16) + sizeof(UInt16)
 

Friends

class Network
 

Detailed Description

Network class that represents a packet.

Constructor & Destructor Documentation

◆ NetPacket() [1/3]

Nz::NetPacket::NetPacket ( UInt16  netCode,
std::size_t  minCapacity = 0 
)
inline

Constructs a NetPacket object with a packet number and a minimal capacity.

Parameters
netCodePacket number
minCapacityMinimal capacity of the packet

◆ NetPacket() [2/3]

Nz::NetPacket::NetPacket ( UInt16  netCode,
const void *  ptr,
std::size_t  size 
)
inline

Constructs a NetPacket object with a packet number and raw memory.

Parameters
netCodePacket number
ptrRaw memory
sizeSize of the memory

◆ NetPacket() [3/3]

Nz::NetPacket::NetPacket ( NetPacket &&  packet)
inline

Constructs a NetPacket object with another one by move semantic.

Parameters
packetNetPacket to move into this

< Redirect memory stream to the moved buffer

Member Function Documentation

◆ DecodeHeader()

bool Nz::NetPacket::DecodeHeader ( const void *  data,
UInt16 *  packetSize,
UInt16 *  netCode 
)
static

Decodes the header of the packet.

Returns
true If successful
Parameters
dataRaw memory
packetSizeSize of the packet
netCodePacket number

◆ EncodeHeader()

bool Nz::NetPacket::EncodeHeader ( void *  data,
UInt16  packetSize,
UInt16  netCode 
)
static

Encodes the header of the packet.

Returns
true If successful
Parameters
dataRaw memory
packetSizeSize of the packet
netCodePacket number

◆ GetConstData()

const UInt8 * Nz::NetPacket::GetConstData ( ) const
inline

Gets the raw buffer.

Returns
Constant raw buffer
Remarks
Produces a NazaraAssert if internal buffer is invalid

◆ GetData()

UInt8 * Nz::NetPacket::GetData ( ) const
inline

Gets the raw buffer.

Returns
Raw buffer
Remarks
Produces a NazaraAssert if internal buffer is invalid

◆ GetDataSize()

size_t Nz::NetPacket::GetDataSize ( ) const
inline

Gets the size of the data.

Returns
Size of the data

◆ GetNetCode()

UInt16 Nz::NetPacket::GetNetCode ( ) const
inline

Gets the packet number.

Returns
Packet number

◆ OnReceive()

void Nz::NetPacket::OnReceive ( UInt16  netCode,
const void *  data,
std::size_t  size 
)
virtual

Operation to do when receiving data.

Parameters
netCodePacket number
dataRaw memory
sizeSize of the memory

◆ OnSend()

const void * Nz::NetPacket::OnSend ( std::size_t *  newSize) const
virtual

Operation to do when sending data.

Returns
Beggining of the raw memory
Parameters
newSizeSize of the memory to send
Remarks
Produces a NazaraAssert if newSize is invalid
Produces a NazaraAssert if net code is invalid
Produces a NazaraError if header could not be encoded

◆ operator=()

NetPacket & Nz::NetPacket::operator= ( NetPacket &&  packet)
inline

Moves the NetPacket into this.

Returns
A reference to this
Parameters
packetNetPacket to move in this

< Redirect memory stream to the moved buffer

◆ Reset() [1/2]

void Nz::NetPacket::Reset ( UInt16  netCode,
std::size_t  minCapacity = 0 
)
inline

Resets the packet with a packet number and a minimal capacity.

Parameters
netCodePacket number
minCapacityMinimal capacity of the packet

◆ Reset() [2/2]

void Nz::NetPacket::Reset ( UInt16  netCode,
const void *  ptr,
std::size_t  size 
)
inline

Resets the packet with a packet number and raw memory.

Parameters
netCodePacket number
ptrRaw memory
sizeSize of the memory

◆ Resize()

void Nz::NetPacket::Resize ( std::size_t  newSize)
inline

Resizes the packet.

Parameters
newSizeSize for the resizing operation
Remarks
Produces a NazaraAssert if internal buffer is invalid

◆ SetNetCode()

void Nz::NetPacket::SetNetCode ( UInt16  netCode)
inline

Sets the packet number.

Parameters
netCodePacket number

The documentation for this class was generated from the following files: