7 #ifndef NAZARA_NETPACKET_HPP 8 #define NAZARA_NETPACKET_HPP 10 #include <Nazara/Prerequesites.hpp> 11 #include <Nazara/Core/ByteStream.hpp> 12 #include <Nazara/Core/MemoryStream.hpp> 13 #include <Nazara/Core/Mutex.hpp> 14 #include <Nazara/Network/Config.hpp> 24 inline NetPacket(UInt16 netCode, std::size_t minCapacity = 0);
25 inline NetPacket(UInt16 netCode,
const void* ptr, std::size_t size);
30 inline const UInt8* GetConstData()
const;
31 inline UInt8* GetData()
const;
32 inline size_t GetDataSize()
const;
33 inline UInt16 GetNetCode()
const;
35 virtual void OnReceive(UInt16 netCode,
const void* data, std::size_t size);
36 virtual const void* OnSend(std::size_t* newSize)
const;
39 inline void Reset(UInt16 netCode, std::size_t minCapacity = 0);
40 inline void Reset(UInt16 netCode,
const void* ptr, std::size_t size);
42 inline void Resize(std::size_t newSize);
44 inline void SetNetCode(UInt16 netCode);
49 static bool DecodeHeader(
const void* data, UInt16* packetSize, UInt16* netCode);
50 static bool EncodeHeader(
void* data, UInt16 packetSize, UInt16 netCode);
52 static constexpr std::size_t HeaderSize =
sizeof(UInt16) +
sizeof(UInt16);
55 void OnEmptyStream()
override;
58 void InitStream(std::size_t minCapacity, UInt64 cursorPos,
OpenModeFlags openMode);
60 static bool Initialize();
61 static void Uninitialize();
63 std::unique_ptr<ByteArray> m_buffer;
67 static std::unique_ptr<Mutex> s_availableBuffersMutex;
68 static std::vector<std::pair<std::size_t, std::unique_ptr<ByteArray>>> s_availableBuffers;
72 #include <Nazara/Network/NetPacket.inl> 74 #endif // NAZARA_NETPACKET_HPP TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Network class that represents a packet.
Definition: NetPacket.hpp:18
Core class that represents a stream of bytes.
Definition: ByteStream.hpp:19
Network class that represents the module initializer of Network.
Definition: Network.hpp:15
Constructs a MemoryStream object by default.
Definition: MemoryStream.hpp:17