From db5ad2e09a6b38e841463dbe7eb076492b62c948 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Aug 2009 15:58:17 +0200 Subject: Mad funktioniert jetzt unter Windows --- src/Net/Packet.h | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src/Net/Packet.h') diff --git a/src/Net/Packet.h b/src/Net/Packet.h index dc62cb7..567c9c3 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -20,30 +20,36 @@ #ifndef MAD_NET_PACKET_H_ #define MAD_NET_PACKET_H_ +#include "export.h" + #include #include -#include -#include +#include + +#ifdef _WIN32 +# include +#else +# include +#endif namespace Mad { namespace Net { -class Packet { +class MAD_NET_EXPORT Packet { public: - struct Data { - uint16_t requestId; - uint16_t length; - uint8_t data[0]; + struct Header { + boost::uint16_t requestId; + boost::uint16_t length; }; protected: - Data *rawData; + Header *rawData; public: - Packet(uint16_t requestId, const void *data = 0, uint16_t length = 0); + Packet(boost::uint16_t requestId, const void *data = 0, boost::uint16_t length = 0); Packet(const Packet &p) { - rawData = (Data*)std::malloc(p.getRawDataLength()); + rawData = reinterpret_cast(std::malloc(p.getRawDataLength())); std::memcpy(rawData, p.rawData, p.getRawDataLength()); } @@ -53,24 +59,24 @@ class Packet { Packet& operator=(const Packet &p); - uint16_t getRequestId() const { + boost::uint16_t getRequestId() const { return ntohs(rawData->requestId); } - uint16_t getLength() const { + boost::uint16_t getLength() const { return ntohs(rawData->length); } - const uint8_t* getData() const { - return rawData->data; + const boost::uint8_t* getData() const { + return reinterpret_cast(rawData)+sizeof(Header); } - const Data* getRawData() const { - return rawData; + const boost::uint8_t* getRawData() const { + return reinterpret_cast(rawData); } unsigned long getRawDataLength() const { - return sizeof(Data) + ntohs(rawData->length); + return sizeof(Header) + ntohs(rawData->length); } }; -- cgit v1.2.3