00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __UT_Packet__
00023 #define __UT_Packet__
00024
00025 #include "UT_API.h"
00026 #include "UT_NTStreamUtil.h"
00027
00028
00029
00030 typedef int UT_StreamPos;
00031 class UT_IStream;
00032 class UT_PacketTaint;
00033
00034 UT_API short UTgetClassPacketID(const char *classname);
00035
00036 class UT_API UT_Packet
00037 {
00038 public:
00039 UT_Packet();
00040 ~UT_Packet();
00041
00042 int beginWrite(ostream &str, short class_id, short signature);
00043 int endWrite();
00044
00045 bool beginRead(UT_IStream &stream, short &class_id,
00046 short &signature);
00047 int cancelRead();
00048 int endRead();
00049
00050
00051
00052 ostream *beginPipeWrite(ostream &str, short class_id, short signature);
00053 int endPipeWrite();
00054
00055 UT_IStream *beginPipeRead(UT_IStream &stream, short &class_id, short &sig);
00056 int endPipeRead();
00057
00058 void setHeaderTaint(UT_PacketTaint *taint);
00059
00060
00061
00062
00063
00064
00065
00066
00067 static char *compressPacket(const char *src, int &size);
00068
00069
00070
00071
00072 static char *uncompressPacket(const char *src, int &size);
00073
00074
00075 static unsigned int getHeaderSize();
00076
00077
00078 private:
00079 char myState;
00080 UT_StreamPos myPacketSize;
00081 UT_StreamPos myPacketStart;
00082 UT_OStrStream *myOutBuffer;
00083 UT_IStream *mySBuffer;
00084 UT_IStream *mySStreamPtr;
00085 ostream *myOutStreamPtr;
00086 char *myData;
00087 UT_PacketTaint *myHeaderTaint;
00088 };
00089
00090
00091
00092
00093
00094
00095 #define SETUPCLASSPACKETID(classname) \
00096 static int \
00097 getClassPacketID() \
00098 { \
00099 static int firsttime = 1; \
00100 static int classid; \
00101 if (firsttime) \
00102 { \
00103 firsttime = 0; \
00104 classid = UTgetClassPacketID(classname); \
00105 } \
00106 return classid; \
00107 }
00108
00109 #endif