Download Source Code

CDataPacket Class Reference

Provides basic serial packetizing class. More...

#include <DataPacket.h>

Inheritance diagram for CDataPacket:

Inheritance graph
[legend]
Collaboration diagram for CDataPacket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

BOOL VerifyPacketData (DWORD dwBlock, DWORD dwType, const GUID *pGuid)
 Call this function to verify the packet data.
BOOL GetPacketDataHash (GUID *pGuid, DWORD dwBlock, DWORD dwType)
 Returns packet data hash.
BOOL ReadPacketData (DWORD dwBlock, DWORD dwType, LPVOID pBuf, DWORD dwMax, LPDWORD pdwRead=NULL, long lOffset=0)
 This function is used to retrieve the packet data.
BOOL ReadPacketString (DWORD dwBlock, DWORD dwType, LPSTR pStr, DWORD dwMax)
 Reads a string from the packet data. Ensures no buffer overflow and NULL terminates.
virtual void Destroy ()
 Releases resources and readys the object for reuse.
virtual BOOL SkipPacket ()
 Skips the first complete and valid packet in the buffer.
virtual BOOL VerifyPacket ()
 Verifys a packet at current buffer position.
virtual BOOL FindPacket (LPSPacketHeader pPh, LPDWORD pdwAvailable)
 Searches the buffer for the packet ID. Does not mean it is a valid packet.
virtual BOOL ReadPacket (LPVOID pBuf, DWORD dwSize)
 Adds the specified data to the buffer and checks for a valid packet.
DWORD GetMinimumPacketOverhead ()
 Returns the minimum packet size.
BOOL WritePacket (DWORD dwPacketType, DWORD dwDataType, LPVOID pData, DWORD dwData)
 Writes a complete packet to the buffer containing a single data block.
BOOL _cdecl WriteMultiPacket (DWORD dwPacketType, DWORD dwBuffers=0,...)
 Writes multiple packet buffers.
BOOL vWriteMultiPacket (DWORD dwPacketType, DWORD dwBuffers=0, LPVOID *pArgs=NULL)
 Writes multiple packet buffers.
BOOL EndPacket ()
 Call to conclude a packet being written to the buffer.
BOOL AddPacketData (DWORD dwType, LPVOID pData, DWORD dwSize)
 Creates a data block and writes it into the buffer.
BOOL WritePacketData (LPVOID pData, DWORD dwSize, DWORD dwEncode=0)
 Write raw data into packet and update checksum.
BOOL InitPacket (DWORD dwType, DWORD dwDataBlocks, DWORD dwTotalDataSize)
 Initializes the packet header and writes it to the buffer.
virtual BOOL OnInspectWrite (DWORD dwBlock, LPBYTE pBuf, DWORD dwSize)
 Over-ride to implement write block inspection.
 CDataPacket ()
 Constructor.
 CDataPacket (DWORD dwSize)
 Constructor.
virtual ~CDataPacket ()
 Destructor.
void SetEncoding (DWORD dw)
 Call this function to enable packet data encoding.
DWORD GetEncoding ()
 Returns the type of packet data encoding.

Classes

struct  SCheckSum
 Data check sum. More...
struct  SDataHeader
 This structure defines a data chunk. More...
struct  SPacketHeader
 This structure defines a serial packet header. More...

Detailed Description

Provides basic serial packetizing class.

Use this class to provide serial communication packetizing. Useful for sending data over any serial link such as Ethernet.


Member Function Documentation

BOOL CDataPacket::AddPacketData DWORD  dwType,
LPVOID  pData,
DWORD  dwSize
 

Creates a data block and writes it into the buffer.

Parameters:
[in] dwType - Packet data type
[in] pData - Buffer containing packet data
[in] dwSize - Number of bytes in pData
Returns:
Non-zero if success
See also:

BOOL CDataPacket::EndPacket  ) 
 

Call to conclude a packet being written to the buffer.

Returns:
Non-zero if success
See also:

BOOL CDataPacket::FindPacket LPSPacketHeader  pPh,
LPDWORD  pdwAvailable
[virtual]
 

Searches the buffer for the packet ID. Does not mean it is a valid packet.

Parameters:
[in] pPh - Receives packet header data
[in] pdwAvailable - Number of valid bytes left in buffer
Returns:
Non-zero if valid packet header is found.
See also:

BOOL CDataPacket::GetPacketDataHash GUID *  pGuid,
DWORD  dwBlock,
DWORD  dwType
 

Returns packet data hash.

Parameters:
[in] pGuid - Buffer to hold hash
[in] dwBlock - Block index we're looking for
[in] dwType - Block type
Returns:
Non-zero if hash was retrieved.
See also:

BOOL CDataPacket::InitPacket DWORD  dwType,
DWORD  dwDataBlocks,
DWORD  dwTotalDataSize
 

Initializes the packet header and writes it to the buffer.

Parameters:
[in] dwType - Packet type
[in] dwDataBlocks - Number of data blocks
[in] dwTotalDataSize - Total size of packet data
Returns:
Non-zero if success
See also:

BOOL CDataPacket::OnInspectWrite DWORD  dwBlock,
LPBYTE  pBuf,
DWORD  dwSize
[virtual]
 

Over-ride to implement write block inspection.

Parameters:
[in] dwBlock - Block index
[in] pBuf - Pointer to write buffer
[in] dwSize - Size of data in pBuf
Returns:
Non-zero if success.
See also:

Reimplemented from CCircBuf.

BOOL CDataPacket::ReadPacket LPVOID  pBuf,
DWORD  dwSize
[virtual]
 

Adds the specified data to the buffer and checks for a valid packet.

Parameters:
[in] pBuf - Buffer containing new raw data to read
[in] dwSize - Size of the data in pBuf
Returns:
Non-zero if success.
See also:

Reimplemented in CNetMsg.

BOOL CDataPacket::ReadPacketData DWORD  dwBlock,
DWORD  dwType,
LPVOID  pBuf,
DWORD  dwMax,
LPDWORD  pdwRead = NULL,
long  lOffset = 0
 

This function is used to retrieve the packet data.

Parameters:
[in] dwBlock - Index of block
[in] dwType - Block type
[in] pBuf - Pointer to buffer that receives the data.
[in] dwMax - Size of buffer in pBuf
[in] pdwRead - Number of bytes written to pBuf
[in] lOffset - Offset from block start pointer
Returns:
Non-zero if success
See also:

BOOL CDataPacket::ReadPacketString DWORD  dwBlock,
DWORD  dwType,
LPSTR  pStr,
DWORD  dwMax
[inline]
 

Reads a string from the packet data. Ensures no buffer overflow and NULL terminates.

Parameters:
[in] dwBlock - Block index
[in] dwType - Block type
[in] pStr - Buffer that receives the string
[in] dwMax - Size of the buffer in pStr
Returns:
Non-zero if success
See also:

void CDataPacket::SetEncoding DWORD  dw  )  [inline]
 

Call this function to enable packet data encoding.

Parameters:
[in] dw - Current encoding value

BOOL CDataPacket::SkipPacket  )  [virtual]
 

Skips the first complete and valid packet in the buffer.

Returns:
Non-zero if success
See also:

BOOL CDataPacket::VerifyPacket  )  [virtual]
 

Verifys a packet at current buffer position.

Searches for the packet ID, then verifys the length and checksum If this function returns TRUE, a valid packet awaits in the buffer.

Returns:
Non-zero if a valid packet is in the buffer.
See also:

Reimplemented in CNetMsg.

BOOL CDataPacket::VerifyPacketData DWORD  dwBlock,
DWORD  dwType,
const GUID *  pGuid
 

Call this function to verify the packet data.

Parameters:
[in] dwBlock - Block index
[in] dwType - Block type
[in] pGuid - Block ID
Returns:
Non-zero if verified
See also:

BOOL CDataPacket::vWriteMultiPacket DWORD  dwPacketType,
DWORD  dwBuffers = 0,
LPVOID *  pArgs = NULL
 

Writes multiple packet buffers.

Parameters:
[in] dwPacketType - Packet type
[in] dwBuffers - Number of buffers
[in] pArgs - Pointer to argument pointer list
pArgs[] = { DWORD *dwDataType, LPBYTE *pBuf, DWORD *dwSize, ... }

Returns:
Non-zero if success
See also:

BOOL _cdecl CDataPacket::WriteMultiPacket DWORD  dwPacketType,
DWORD  dwBuffers = 0,
  ...
[inline]
 

Writes multiple packet buffers.

Parameters:
[in] dwPacketType - Packet type
[in] dwBuffers - Number of buffers
Writes multiple buffers add ( DWORD dwDataType, LPBYTE pBuf, DWORD dwSize, ... ) for each buffer

Returns:
See also:

BOOL CDataPacket::WritePacket DWORD  dwPacketType,
DWORD  dwDataType,
LPVOID  pData,
DWORD  dwData
 

Writes a complete packet to the buffer containing a single data block.

Parameters:
[in] dwPacketType - Packet type id
[in] dwDataType - Data type id
[in] pData - Pointer to data
[in] dwData - Number of bytes in pData
Writes packet data to buffer.

Returns:
Non-zero if success
See also:

BOOL CDataPacket::WritePacketData LPVOID  pData,
DWORD  dwSize,
DWORD  dwEncode = 0
 

Write raw data into packet and update checksum.

Parameters:
[in] pData - Pointer to packet data
[in] dwSize - Number of bytes in pData
[in] dwEncode - Optional encoding
Returns:
Non-zero if success
See also:


The documentation for this class was generated from the following files:
  • inc/DataPacket.h
  • DataPacket.cpp
Copyright Robert Umbehant
This documentation is covered by the LGPL