View on GitHub

DSFML

dsfml.network.packet

A module contianing the Packet class.

class Packet;
Utility class to build blocks of data to transfer over the network.

Packets provide a safe and easy way to serialize data, in order to send it over the network using sockets (sf::TcpSocket, sf::UdpSocket).

this();
Default constructor

const const(void)[] getData();
Get a slice of the data contained in the packet.

Returns:
Slice containing the data.

void append(const(void)[] data);
Append data to the end of the packet.

Params:
const(void)[] data Pointer to the sequence of bytes to append.

const bool canRead();
Test the validity of a packet, for reading

This function allows to test 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.





Returns:
True if last data extraction from packet was successful.

void clear();
Clear the packet.

After calling Clear, the packet is empty.

const bool endOfPacket();
Tell if the reading position has reached the end of the packet.

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





Returns:
True if all data was read, false otherwise.

bool readBool();
Reads a bool from the packet.

byte readByte();
Reads a byte from the packet.

ubyte readUbyte();
Reads a ubyte from the packet.

short readShort();
Reads a short from the packet.

ushort readUshort();
Reads a ushort from the packet.

int readInt();
Reads a int from the packet.

uint readUint();
Reads a uint from the packet.

float readFloat();
Reads a float from the packet.

double readDouble();
Reads a double from the packet.

string readString();
Reads a string from the packet.

wstring readWstring();
Reads a wstring from the packet.

dstring readDstring();
Reads a dstring from the packet.

void writeBool(bool value);
Write a bool the the end of the packet.

void writeByte(byte value);
Write a byte the the end of the packet.

void writeUbyte(ubyte value);
Write a ubyte the the end of the packet.

void writeShort(short value);
Write a short the the end of the packet.

void writeUshort(ushort value);
Write a ushort the the end of the packet.

void writeInt(int value);
Write a int the the end of the packet.

void writeUint(uint value);
Write a uint the the end of the packet.

void writeFloat(float value);
Write a float the the end of the packet.

void writeDouble(double value);
Write a double the the end of the packet.

void writeString(string value);
Write a string the the end of the packet.

void writeWstring(wstring value);
Write a wstring the the end of the packet.

void writeDstring(dstring value);
Write a dstring the the end of the packet.

const(void)[] onSend();
Called before the packet is sent over the network.

This function can be defined by derived classes to transform the data before it is sent; this can be used for compression, encryption, etc.

The function must return an array of the modified data, as well as the number of bytes pointed. The default implementation provides the packet's data without transforming it.





Returns:
Array of bytes to send

void onRecieve(const(void)[] data);
Called after the packet is received over the network.

This function can be defined by derived classes to transform the data after it is received; this can be used for uncompression, decryption, etc.

The function receives an array of the received data, and must fill the packet with the transformed bytes. The default implementation fills the packet directly without transforming the data.





Params:

package sfPacket* sfPacket_create();
Create a new packet

package sfPacket* sfPacket_copy(const sfPacket* packet);
Create a new packet by copying an existing one

package void sfPacket_destroy(sfPacket* packet);
Destroy a packet

package void sfPacket_append(sfPacket* packet, const void* data, size_t sizeInBytes);
Append data to the end of a packet

package void sfPacket_clear(sfPacket* packet);
Clear a packet

package const(void)* sfPacket_getData(const sfPacket* packet);
Get a pointer to the data contained in a packet

package size_t sfPacket_getDataSize(const sfPacket* packet);
Get the size of the data contained in a packet

package bool sfPacket_endOfPacket(const sfPacket* packet);
Tell if the reading position has reached the end of a packet

package bool sfPacket_canRead(const sfPacket* packet);
Test the validity of a packet, for reading

package bool sfPacket_readBool(sfPacket* packet);
Functions to extract data from a packet

package void sfPacket_writeBool(sfPacket* packet, bool);
void sfPacket_readString(sfPacket* packet, char* string);

void sfPacket_readWideString(sfPacket* packet, wchar_t* string);///Remove in lieu of readUint16 and readUint32 for W and D chars in D?

Functions to insert data into a packet