CSFML - C binding of the Simple and Fast Multimedia Library

CSFML
Functions
Packet.h File Reference
`#include <SFML/Network/Export.h>`
`#include <SFML/Network/Types.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Functions
CSFML_NETWORK_API sfPacket * | sfPacket_create (void)
| Create a new packet. More...
CSFML_NETWORK_API sfPacket * | sfPacket_copy (const sfPacket *packet)
| Create a new packet by copying an existing one. More...
CSFML_NETWORK_API void | sfPacket_destroy (sfPacket *packet)
| Destroy a packet. More...
CSFML_NETWORK_API void | sfPacket_append (sfPacket *packet, const void *data, size_t sizeInBytes)
| Append data to the end of a packet. More...
CSFML_NETWORK_API void | sfPacket_clear (sfPacket *packet)
| Clear a packet. More...
CSFML_NETWORK_API const void * | sfPacket_getData (const sfPacket *packet)
| Get a pointer to the data contained in a packet. More...
CSFML_NETWORK_API size_t | sfPacket_getDataSize (const sfPacket *packet)
| Get the size of the data contained in a packet. More...
CSFML_NETWORK_API sfBool | sfPacket_endOfPacket (const sfPacket *packet)
| Tell if the reading position has reached the end of a packet. More...
CSFML_NETWORK_API sfBool | sfPacket_canRead (const sfPacket *packet)
| Test the validity of a packet, for reading. More...
CSFML_NETWORK_API sfBool | sfPacket_readBool (sfPacket *packet)
| Functions to extract data from a packet. More...
CSFML_NETWORK_API sfInt8 | sfPacket_readInt8 (sfPacket *packet)
CSFML_NETWORK_API sfUint8 | sfPacket_readUint8 (sfPacket *packet)
CSFML_NETWORK_API sfInt16 | sfPacket_readInt16 (sfPacket *packet)
CSFML_NETWORK_API sfUint16 | sfPacket_readUint16 (sfPacket *packet)
CSFML_NETWORK_API sfInt32 | sfPacket_readInt32 (sfPacket *packet)
CSFML_NETWORK_API sfUint32 | sfPacket_readUint32 (sfPacket *packet)
CSFML_NETWORK_API float | sfPacket_readFloat (sfPacket *packet)
CSFML_NETWORK_API double | sfPacket_readDouble (sfPacket *packet)
CSFML_NETWORK_API void | sfPacket_readString (sfPacket *packet, char *string)
CSFML_NETWORK_API void | sfPacket_readWideString (sfPacket *packet, wchar_t *string)
CSFML_NETWORK_API void | sfPacket_writeBool (sfPacket *packet, sfBool)
| Functions to insert data into a packet. More...
CSFML_NETWORK_API void | sfPacket_writeInt8 (sfPacket *packet, sfInt8)
CSFML_NETWORK_API void | sfPacket_writeUint8 (sfPacket *packet, sfUint8)
CSFML_NETWORK_API void | sfPacket_writeInt16 (sfPacket *packet, sfInt16)
CSFML_NETWORK_API void | sfPacket_writeUint16 (sfPacket *packet, sfUint16)
CSFML_NETWORK_API void | sfPacket_writeInt32 (sfPacket *packet, sfInt32)
CSFML_NETWORK_API void | sfPacket_writeUint32 (sfPacket *packet, sfUint32)
CSFML_NETWORK_API void | sfPacket_writeFloat (sfPacket *packet, float)
CSFML_NETWORK_API void | sfPacket_writeDouble (sfPacket *packet, double)
CSFML_NETWORK_API void | sfPacket_writeString (sfPacket *packet, const char *string)
CSFML_NETWORK_API void | sfPacket_writeWideString (sfPacket *packet, const wchar_t *string)

## Function Documentation

## ◆ sfPacket_append()

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

Append data to the end of a packet.

Parameters

  packet | Packet object
  data | Pointer to the sequence of bytes to append
  sizeInBytes | Number of bytes to append

## ◆ sfPacket_canRead()

CSFML_NETWORK_API sfBool sfPacket_canRead | ( | const sfPacket * | packet | ) |

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.

Parameters

  packet | Packet object

Returns
  sfTrue if last data extraction from packet was successful

## ◆ sfPacket_clear()

CSFML_NETWORK_API void sfPacket_clear | ( | sfPacket * | packet | ) |

Clear a packet.

After calling Clear, the packet is empty.

Parameters

  packet | Packet object

## ◆ sfPacket_copy()

CSFML_NETWORK_API sfPacket* sfPacket_copy | ( | const sfPacket * | packet | ) |

Create a new packet by copying an existing one.

Parameters

  packet | Packet to copy

Returns
  A new sfPacket object which is a copy of packet

## ◆ sfPacket_create()

CSFML_NETWORK_API sfPacket* sfPacket_create | ( | void |  | ) |

Create a new packet.

Returns
  A new sfPacket object

## ◆ sfPacket_destroy()

CSFML_NETWORK_API void sfPacket_destroy | ( | sfPacket * | packet | ) |

Destroy a packet.

Parameters

  packet | Packet to destroy

## ◆ sfPacket_endOfPacket()

CSFML_NETWORK_API sfBool 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

  packet | Packet object

Returns
  sfTrue if all data was read, sfFalse otherwise

## ◆ sfPacket_getData()

CSFML_NETWORK_API 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

  packet | Packet object

Returns
  Pointer to the data

## ◆ sfPacket_getDataSize()

CSFML_NETWORK_API 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

  packet | Packet object

Returns
  Data size, in bytes

## ◆ sfPacket_readBool()

CSFML_NETWORK_API sfBool sfPacket_readBool | ( | sfPacket * | packet | ) |

Functions to extract data from a packet.

Parameters

  packet | Packet object

## ◆ sfPacket_readDouble()

CSFML_NETWORK_API double sfPacket_readDouble | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readFloat()

CSFML_NETWORK_API float sfPacket_readFloat | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readInt16()

CSFML_NETWORK_API sfInt16 sfPacket_readInt16 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readInt32()

CSFML_NETWORK_API sfInt32 sfPacket_readInt32 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readInt8()

CSFML_NETWORK_API sfInt8 sfPacket_readInt8 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readString()

CSFML_NETWORK_API void sfPacket_readString | ( | sfPacket * | packet,
|  | char * | string
| ) |  |

## ◆ sfPacket_readUint16()

CSFML_NETWORK_API sfUint16 sfPacket_readUint16 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readUint32()

CSFML_NETWORK_API sfUint32 sfPacket_readUint32 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readUint8()

CSFML_NETWORK_API sfUint8 sfPacket_readUint8 | ( | sfPacket * | packet | ) |

## ◆ sfPacket_readWideString()

CSFML_NETWORK_API void sfPacket_readWideString | ( | sfPacket * | packet,
|  | wchar_t * | string
| ) |  |

## ◆ sfPacket_writeBool()

CSFML_NETWORK_API void sfPacket_writeBool | ( | sfPacket * | packet,
|  | sfBool |
| ) |  |

Functions to insert data into a packet.

Parameters

  packet | Packet object

## ◆ sfPacket_writeDouble()

CSFML_NETWORK_API void sfPacket_writeDouble | ( | sfPacket * | packet,
|  | double |
| ) |  |

## ◆ sfPacket_writeFloat()

CSFML_NETWORK_API void sfPacket_writeFloat | ( | sfPacket * | packet,
|  | float |
| ) |  |

## ◆ sfPacket_writeInt16()

CSFML_NETWORK_API void sfPacket_writeInt16 | ( | sfPacket * | packet,
|  | sfInt16 |
| ) |  |

## ◆ sfPacket_writeInt32()

CSFML_NETWORK_API void sfPacket_writeInt32 | ( | sfPacket * | packet,
|  | sfInt32 |
| ) |  |

## ◆ sfPacket_writeInt8()

CSFML_NETWORK_API void sfPacket_writeInt8 | ( | sfPacket * | packet,
|  | sfInt8 |
| ) |  |

## ◆ sfPacket_writeString()

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

## ◆ sfPacket_writeUint16()

CSFML_NETWORK_API void sfPacket_writeUint16 | ( | sfPacket * | packet,
|  | sfUint16 |
| ) |  |

## ◆ sfPacket_writeUint32()

CSFML_NETWORK_API void sfPacket_writeUint32 | ( | sfPacket * | packet,
|  | sfUint32 |
| ) |  |

## ◆ sfPacket_writeUint8()

CSFML_NETWORK_API void sfPacket_writeUint8 | ( | sfPacket * | packet,
|  | sfUint8 |
| ) |  |

## ◆ sfPacket_writeWideString()

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