From 7d2ebaf265140ee6d2ff0eb469ec36118d3cccc8 Mon Sep 17 00:00:00 2001 From: Shane Whitmire Date: Thu, 25 May 2023 15:59:16 -0500 Subject: [PATCH] PR 1641 Added method to get the current read position of sf::Packet --- include/SFML/Network/Packet.h | 12 ++++++++++++ src/SFML/Network/Packet.cpp | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/include/SFML/Network/Packet.h b/include/SFML/Network/Packet.h index 28e6c70e..c9ea8ce2 100644 --- a/include/SFML/Network/Packet.h +++ b/include/SFML/Network/Packet.h @@ -69,6 +69,18 @@ CSFML_NETWORK_API void sfPacket_destroy(sfPacket* packet); //////////////////////////////////////////////////////////// CSFML_NETWORK_API void sfPacket_append(sfPacket* packet, const void* data, size_t sizeInBytes); +//////////////////////////////////////////////////////////// +/// \brief Get the current reading position in the packet +/// +/// The next read operation will read data from this position +/// +/// \return The byte offset of the current read position +/// +/// \see append +/// +//////////////////////////////////////////////////////////// +CSFML_NETWORK_API size_t sfPacket_getReadPosition(const sfPacket* packet); + //////////////////////////////////////////////////////////// /// \brief Clear a packet /// diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index f0f3a1a4..cd8de463 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -60,6 +60,13 @@ void sfPacket_append(sfPacket* packet, const void* data, size_t sizeInBytes) } +//////////////////////////////////////////////////////////// +size_t sfPacket_getReadPosition(const sfPacket* packet) +{ + CSFML_CALL_RETURN(packet, getReadPosition(), 0); +} + + //////////////////////////////////////////////////////////// void sfPacket_clear(sfPacket* packet) {