Loading...
Searching...
No Matches
Packet.h File Reference
#include <CSFML/Network/Export.h>
#include <CSFML/Network/Types.h>
#include <stddef.h>

Go to the source code of this file.

Functions

sfPacketsfPacket_create (void)
 Create a new packet.
 
sfPacketsfPacket_copy (const sfPacket *packet)
 Create a new packet by copying an existing one.
 
void sfPacket_destroy (const sfPacket *packet)
 Destroy a packet.
 
void sfPacket_append (sfPacket *packet, const void *data, size_t sizeInBytes)
 Append data to the end of a packet.
 
size_t sfPacket_getReadPosition (const sfPacket *packet)
 Get the current reading position in the packet.
 
void sfPacket_clear (sfPacket *packet)
 Clear a packet.
 
const void * sfPacket_getData (const sfPacket *packet)
 Get a pointer to the data contained in a packet.
 
size_t sfPacket_getDataSize (const sfPacket *packet)
 Get the size of the data contained in a packet.
 
bool sfPacket_endOfPacket (const sfPacket *packet)
 Tell if the reading position has reached the end of a packet.
 
bool sfPacket_canRead (const sfPacket *packet)
 Test the validity of a packet, for reading.
 
bool sfPacket_readBool (sfPacket *packet)
 Functions to extract data from a packet.
 
int8_t sfPacket_readInt8 (sfPacket *packet)
 
uint8_t sfPacket_readUint8 (sfPacket *packet)
 
int16_t sfPacket_readInt16 (sfPacket *packet)
 
uint16_t sfPacket_readUint16 (sfPacket *packet)
 
int32_t sfPacket_readInt32 (sfPacket *packet)
 
uint32_t sfPacket_readUint32 (sfPacket *packet)
 
float sfPacket_readFloat (sfPacket *packet)
 
double sfPacket_readDouble (sfPacket *packet)
 
void sfPacket_readString (sfPacket *packet, char *string)
 
void sfPacket_readWideString (sfPacket *packet, wchar_t *string)
 
void sfPacket_writeBool (sfPacket *packet, bool)
 Functions to insert data into a packet.
 
void sfPacket_writeInt8 (sfPacket *packet, int8_t)
 
void sfPacket_writeUint8 (sfPacket *packet, uint8_t)
 
void sfPacket_writeInt16 (sfPacket *packet, int16_t)
 
void sfPacket_writeUint16 (sfPacket *packet, uint16_t)
 
void sfPacket_writeInt32 (sfPacket *packet, int32_t)
 
void sfPacket_writeUint32 (sfPacket *packet, uint32_t)
 
void sfPacket_writeFloat (sfPacket *packet, float)
 
void sfPacket_writeDouble (sfPacket *packet, double)
 
void sfPacket_writeString (sfPacket *packet, const char *string)
 
void sfPacket_writeWideString (sfPacket *packet, const wchar_t *string)
 

Function Documentation

◆ sfPacket_append()

void sfPacket_append ( sfPacket * packet,
const void * data,
size_t sizeInBytes )

Append data to the end of a packet.

Parameters
packetPacket object
dataPointer to the sequence of bytes to append
sizeInBytesNumber of bytes to append

◆ sfPacket_canRead()

bool sfPacket_canRead ( const sfPacket * packet)

Test the validity of a packet, for reading.

This function allows for testing the packet, to check if a reading operation was successful.

A packet will be in an invalid state if it has no more data to read.

Parameters
packetPacket object
Returns
true if last data extraction from packet was successful

◆ sfPacket_clear()

void sfPacket_clear ( sfPacket * packet)

Clear a packet.

After calling Clear, the packet is empty.

Parameters
packetPacket object

◆ sfPacket_copy()

sfPacket * sfPacket_copy ( const sfPacket * packet)

Create a new packet by copying an existing one.

Parameters
packetPacket to copy
Returns
A new sfPacket object which is a copy of packet

◆ sfPacket_create()

sfPacket * sfPacket_create ( void )

Create a new packet.

Returns
A new sfPacket object

◆ sfPacket_destroy()

void sfPacket_destroy ( const sfPacket * packet)

Destroy a packet.

Parameters
packetPacket to destroy

◆ sfPacket_endOfPacket()

bool sfPacket_endOfPacket ( const sfPacket * packet)

Tell if the reading position has reached the end of a packet.

This function is useful to know if there is some data left to be read, without actually reading it.

Parameters
packetPacket object
Returns
true if all data was read, false otherwise

◆ sfPacket_getData()

const void * sfPacket_getData ( const sfPacket * packet)

Get a pointer to the data contained in a packet.

Warning: the returned pointer may become invalid after you append data to the packet, therefore it should never be stored. The return pointer is NULL if the packet is empty.

Parameters
packetPacket object
Returns
Pointer to the data

◆ sfPacket_getDataSize()

size_t sfPacket_getDataSize ( const sfPacket * packet)

Get the size of the data contained in a packet.

This function returns the number of bytes pointed to by what sfPacket_getData returns.

Parameters
packetPacket object
Returns
Data size, in bytes

◆ sfPacket_getReadPosition()

size_t sfPacket_getReadPosition ( const sfPacket * packet)

Get the current reading position in the packet.

The next read operation will read data from this position

Returns
The byte offset of the current read position
See also
append

◆ sfPacket_readBool()

bool sfPacket_readBool ( sfPacket * packet)

Functions to extract data from a packet.

Parameters
packetPacket object

◆ sfPacket_readDouble()

double sfPacket_readDouble ( sfPacket * packet)

◆ sfPacket_readFloat()

float sfPacket_readFloat ( sfPacket * packet)

◆ sfPacket_readInt16()

int16_t sfPacket_readInt16 ( sfPacket * packet)

◆ sfPacket_readInt32()

int32_t sfPacket_readInt32 ( sfPacket * packet)

◆ sfPacket_readInt8()

int8_t sfPacket_readInt8 ( sfPacket * packet)

◆ sfPacket_readString()

void sfPacket_readString ( sfPacket * packet,
char * string )

◆ sfPacket_readUint16()

uint16_t sfPacket_readUint16 ( sfPacket * packet)

◆ sfPacket_readUint32()

uint32_t sfPacket_readUint32 ( sfPacket * packet)

◆ sfPacket_readUint8()

uint8_t sfPacket_readUint8 ( sfPacket * packet)

◆ sfPacket_readWideString()

void sfPacket_readWideString ( sfPacket * packet,
wchar_t * string )

◆ sfPacket_writeBool()

void sfPacket_writeBool ( sfPacket * packet,
bool  )

Functions to insert data into a packet.

Parameters
packetPacket object

◆ sfPacket_writeDouble()

void sfPacket_writeDouble ( sfPacket * packet,
double  )

◆ sfPacket_writeFloat()

void sfPacket_writeFloat ( sfPacket * packet,
float  )

◆ sfPacket_writeInt16()

void sfPacket_writeInt16 ( sfPacket * packet,
int16_t  )

◆ sfPacket_writeInt32()

void sfPacket_writeInt32 ( sfPacket * packet,
int32_t  )

◆ sfPacket_writeInt8()

void sfPacket_writeInt8 ( sfPacket * packet,
int8_t  )

◆ sfPacket_writeString()

void sfPacket_writeString ( sfPacket * packet,
const char * string )

◆ sfPacket_writeUint16()

void sfPacket_writeUint16 ( sfPacket * packet,
uint16_t  )

◆ sfPacket_writeUint32()

void sfPacket_writeUint32 ( sfPacket * packet,
uint32_t  )

◆ sfPacket_writeUint8()

void sfPacket_writeUint8 ( sfPacket * packet,
uint8_t  )

◆ sfPacket_writeWideString()

void sfPacket_writeWideString ( sfPacket * packet,
const wchar_t * string )