00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef __RECVPACKET_H
00024 #define __RECVPACKET_H
00025
00026 #include <cassert>
00027
00028 #include "Shared.h"
00029
00030 class cRecvPacket
00031 {
00032 public:
00033 cRecvPacket( )
00034 : m_wSize( 0 )
00035 {
00036 m_pcTH = reinterpret_cast< cTransportHeader * >( m_bData );
00037 }
00038
00039 ~cRecvPacket( ) {}
00040
00041 inline DWORD GetSequence ( ) { return m_pcTH->m_dwSequence; }
00042 inline DWORD GetFlags ( ) { return m_pcTH->m_dwFlags; }
00043 inline DWORD GetCRC ( ) { return m_pcTH->m_dwCRC; }
00044 inline WORD GetLogicalID( ) { return m_pcTH->m_wLogicalID; }
00045 inline WORD GetTime ( ) { return m_pcTH->m_wTime; }
00046 inline WORD GetTotalSize( ) { return m_pcTH->m_wTotalSize; }
00047 inline WORD GetTable ( ) { return m_pcTH->m_wTable; }
00048
00049 inline BYTE *GetPayloadFront( ) { return m_bData + sizeof( cTransportHeader ); }
00050 inline BYTE *GetPayload ( WORD wOffset ) { return m_bData + sizeof( cTransportHeader ) + wOffset; }
00051 inline BYTE *GetPayloadBack ( ) { return m_bData + sizeof( cTransportHeader ) + m_pcTH->m_wTotalSize; }
00052
00053 inline void CopyPayload( WORD wOffset, void *pDest, WORD wSize )
00054 {
00055 CopyMemory( pDest, m_bData + sizeof( cTransportHeader ) + wOffset, wSize );
00056 }
00057
00058 inline BYTE& operator[]( int n )
00059 {
00060 #ifdef _DEBUG
00061 WORD wMaxSize = GetTotalSize( ) + sizeof( cTransportHeader );
00062 if ( wMaxSize > 0 )
00063 assert( n < wMaxSize );
00064 #endif
00065
00066 return m_bData[n];
00067 }
00068
00069 inline int GetPadding( BYTE *pbStart );
00070
00071 BYTE m_bData[MAX_PACKET_SIZE];
00072 WORD m_wSize;
00073 SOCKADDR_IN m_saSockAddr;
00074
00075 private:
00076 cTransportHeader *m_pcTH;
00077 };
00078
00079 inline int cRecvPacket::GetPadding( BYTE *pbStart )
00080 {
00081 WORD wSize = *(WORD *)pbStart;
00082 pbStart += (sizeof( WORD ) + wSize);
00083
00084 DWORD dwDiff = pbStart - m_bData;
00085
00086 if( dwDiff < 4 )
00087 return 4 - dwDiff;
00088 else if ( (dwDiff % 4) != 0 )
00089 return 4 - (dwDiff % 4);
00090 else
00091 return 0;
00092 }
00093
00094 #endif // #ifndef __RECVPACKET_H