Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_NETWORK_PACKET_H__
00009 #define __SP_NETWORK_PACKET_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_NETWORKSYSTEM
00015
00016
00017 #include "Framework/Network/spNetworkCore.hpp"
00018
00019 #include <boost/shared_array.hpp>
00020
00021
00022 namespace sp
00023 {
00024 namespace network
00025 {
00026
00027
00029 enum EReservedDescriptors
00030 {
00031 DESCRIPTOR_CLIENT_JOIN = 1000,
00032 DESCRIPTOR_CLIENT_LEFT,
00033 DESCRIPTOR_INTRODUCE_CLIENT,
00034 DESCRIPTOR_CONNECTION_ACCEPTED,
00035 DESCRIPTOR_SERVER_DISCONNECTED,
00036
00037 DESCRIPTOR_SESSION_REQUEST,
00038 DESCRIPTOR_SESSION_ANSWER,
00039 };
00040
00041
00046 class SP_EXPORT NetworkPacket
00047 {
00048
00049 public:
00050
00051 NetworkPacket(u32 Descriptor = 0);
00052 NetworkPacket(const NetworkPacket &Other);
00053 NetworkPacket(const void* Buffer, u32 BufferSize, u32 Descriptor = 0, bool isSetLowLevel = false);
00054 NetworkPacket(const io::stringc &String, u32 Descriptor = 0);
00055 ~NetworkPacket();
00056
00057
00058
00060 io::stringc getString() const;
00062 bool compareString(const io::stringc &Str) const;
00063
00065 void setDescriptor(u32 Descriptor);
00067 u32 getDescriptor() const;
00068
00070 void setReceiverAddress(u32 IPAddress);
00072 u32 getReceiverAddress() const;
00073
00074
00075
00077 inline c8* getBuffer()
00078 {
00079 return Buffer_.get() + NetworkPacket::RESERVED_OFFSET;
00080 }
00081 inline const c8* getBuffer() const
00082 {
00083 return Buffer_.get() + NetworkPacket::RESERVED_OFFSET;
00084 }
00085
00091 inline const c8* getRealBuffer() const
00092 {
00093 return Buffer_.get();
00094 }
00101 inline u32 getRealBufferSize() const
00102 {
00103 return LogicalBufferSize_ + NetworkPacket::RESERVED_OFFSET;
00104 }
00105
00107 inline u32 getBufferSize() const
00108 {
00109 return LogicalBufferSize_;
00110 }
00111
00112 private:
00113
00114
00115
00116 static const u32 RESERVED_OFFSET = sizeof(u32);
00117
00118
00119
00120 void createBuffer(u32 Size);
00121 void createBufferNonOffset(u32 Size);
00122
00123
00124
00125 boost::shared_array<c8> Buffer_;
00126 u32 LogicalBufferSize_;
00127
00128 };
00129
00130
00131 }
00132
00133 }
00134
00135
00136 #endif
00137
00138 #endif
00139
00140
00141
00142