Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends

CxUtils::Packet Class Reference

Data structure for storing message data into a buffer. More...

#include <packet.h>

List of all members.

Classes

class  Wrapper
 Method to wrap an existing byte array within a Packet for easy Read/Write operations. The wrapped buffer is not resized or deleted by the Packet. More...

Public Types

typedef std::vector< PacketList
 List of packets.
typedef std::list< PacketQueue
 Queue of messages.

Public Member Functions

 Packet (const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Constructor.
 Packet (const Packet &another)
 Copy Constructor.
virtual ~Packet ()
 Destructor.
int SetByteOrder (const unsigned int order=CX_PACKET_LITTLE_ENDIAN)
 Sets what byte order the data should be stored as in the buffer.
int SetWritePos (const unsigned int pos=0)
 Sets the position for writing data in the packet.
int SetReadPos (const unsigned int pos=0) const
 Sets the position for reading data from the packet. This is the byte position.
int SetLength (const unsigned int len=0)
 Sets the length of the data written in the packet to a new value.
int Delete (const unsigned int len, const unsigned int start=0)
 Deletes data in the packet.
int Insert (const unsigned char *buff, const unsigned int len, const unsigned int pos=0)
 Inserts buffered data into the packet at a position.
int InsertCharacter (const unsigned char value, const unsigned int count, const unsigned int pos=0)
 Inserts a value into the packet and repeats it the number of times specified. This can be useful when you are trying to reserve a block of memory within a packet for future data.
unsigned int GetByteOrder () const
 Gets what byte order the data should be stored as in the buffer.
unsigned int GetWritePos () const
unsigned int GetReadPos () const
unsigned int Size () const
unsigned int Length () const
unsigned int Reserved () const
void Reserve (const unsigned int size)
 Reserves memory for storing data or receiving data over a connection.
virtual int Write (const unsigned char val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const char val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const int val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const short val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const unsigned short val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const unsigned int val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const long long int val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const unsigned long long int val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const float val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const double val, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const unsigned char *buff, const unsigned int len, const unsigned int pos=UINT_MAX)
 Write the data to the end of the packet. No byte order conversion is perfomed using this function.
virtual int Write (const Packet &packet, const unsigned int pos=UINT_MAX)
 Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.
virtual int Write (const std::string &str, const unsigned int pos=UINT_MAX)
 Writes the string data to the packet.
virtual int WriteByte (const unsigned char byte)
virtual int Read (unsigned char &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (char &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (int &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (short &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (unsigned short &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (unsigned int &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (long long int &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (unsigned long long int &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (float &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (double &val, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (unsigned char *buff, const unsigned int len, const unsigned int pos=UINT_MAX) const
 Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.
virtual int Read (Packet &packet, const unsigned int len, const unsigned int pos=UINT_MAX) const
 Reads in the number of bytes listed and puts the result into a packet.
virtual int Read (std::string &str, const unsigned int len, const unsigned int pos=UINT_MAX) const
 Reads in the number of bytes listed and puts the result into a string.
void Clear (const bool setZeroFlag=true)
 Resets length, write, and read positions and sets all memory to values of zero. This function does not delete any memory. To delete memory use Destroy.
void Destroy ()
 Deletes all data in the packet passed the header. The header data size values are also set to zero to match the cleared state.
void Print (const unsigned int bytesPerLine=8) const
 Prints byte data to the console.
const unsigned char * Ptr () const
unsigned char * Ptr ()
Packetoperator= (const Packet &another)
 Copies contents of packet.
Packetoperator+= (const Packet &another)
 Adds packet data to the end of the current packet.
unsigned char operator[] (const unsigned int index) const
 Method to index into internal array.

Static Public Member Functions

static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, char &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, unsigned char &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, int &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, short &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, unsigned short &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, unsigned int &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, long long int &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, unsigned long long int &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, float &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static int Read (const unsigned char *buff, const unsigned int len, const unsigned int pos, double &val, const unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Reads the data from a buffer at the byte position specified.
static unsigned int GetMachineEndianness ()
static bool LoadWiresharkCapturePacketExport (const std::string &filename, Packet::List &packets)
 Method to load a exported capture file constructed by the program Wireshark.

Protected Member Functions

void GrowPacket (unsigned int size)
 Grows the packet size to fit the size desired.

Static Protected Member Functions

template<class T >
static int WritePacket (Packet *p, const T val, const unsigned int pos=UINT_MAX)
 Writes a value to buffer in packet.
template<class T >
static int ReadPacket (const Packet *packet, T &val, unsigned int pos=UINT_MAX)
 Read and read value from packet.
template<class T >
static int ReadAtPos (const unsigned char *buff, const unsigned int len, const unsigned int pos, T &val, unsigned int border=CX_PACKET_LITTLE_ENDIAN)
 Read and read value from packet.

Protected Attributes

unsigned char * mpPacket
 Writed data.
unsigned int mLength
 Length of written data.
unsigned int mReserved
 Amount of data reserved.
unsigned int mWritePos
 Encoding position in packet.
unsigned int mReadPos
 Read position in packet.
unsigned int mByteOrder
 Byte order to write data as within packet.
bool mWrappedPacketFlag

Friends

class Wrapper

Detailed Description

Data structure for storing message data into a buffer.

All written messages are stored within a Packet. This data structure handles all memory allocation and deletion for buffered data. It also has utility functions for encoding different size integers and buffers into the packet.

One bonus feature of this data structure is that it can automatically handle byte order conversions.

Definition at line 98 of file packet.h.


Member Typedef Documentation

typedef std::vector<Packet> CxUtils::Packet::List

List of packets.

Definition at line 102 of file packet.h.

typedef std::list<Packet> CxUtils::Packet::Queue

Queue of messages.

Definition at line 103 of file packet.h.


Constructor & Destructor Documentation

Packet::Packet ( const unsigned int  border = CX_PACKET_LITTLE_ENDIAN )

Constructor.

Parameters:
borderByte order to store data as internally.

Definition at line 248 of file packet.cpp.

Packet::Packet ( const Packet another )

Copy Constructor.

Definition at line 264 of file packet.cpp.

Packet::~Packet (  ) [virtual]

Destructor.

Definition at line 277 of file packet.cpp.


Member Function Documentation

void Packet::Clear ( const bool  setZeroFlag = true )

Resets length, write, and read positions and sets all memory to values of zero. This function does not delete any memory. To delete memory use Destroy.

Parameters:
[in]setZeroFlagIf true, all values in the byte array are set to 0. If false, only the first byte value is set to 0.

Definition at line 1013 of file packet.cpp.

int Packet::Delete ( const unsigned int  len,
const unsigned int  start = 0 
)

Deletes data in the packet.

Deletes the range of data from the packet from a starting point to a length in bytes. Encoding and Decoding positions are reset also.

Parameters:
lenThe number of bytes to delete.
startThe starting position in the packet [0,Length()).
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if cleared properly.

Definition at line 495 of file packet.cpp.

void Packet::Destroy (  )

Deletes all data in the packet passed the header. The header data size values are also set to zero to match the cleared state.

Definition at line 1033 of file packet.cpp.

unsigned int Packet::GetByteOrder (  ) const

Gets what byte order the data should be stored as in the buffer.

If the byte order is set to little endian (CX_PACKET_LITTLE_ENDIAN), and the system is big endian, the data will be converted when writing to and reading from the packet. The same is true if the byte order is set to big endian (CX_PACKET_BIG_ENDIAN) and the system is little endian. If the system byte order matches the byte order value set, then not byte order conversion occurs.

Returns:
Gets the byte order that the data is being stored as.

Definition at line 555 of file packet.cpp.

static unsigned int CxUtils::Packet::GetMachineEndianness (  ) [inline, static]
Returns:
CX_PACKET_LITTLE_ENDIAN if the current machine's byte order is little endian, otherwise CX_PACKET_BIG_ENDIAN.

Definition at line 196 of file packet.h.

unsigned int Packet::GetReadPos (  ) const
Returns:
The position being used for reading data.

Definition at line 536 of file packet.cpp.

unsigned int Packet::GetWritePos (  ) const
Returns:
The position being used for writing data in the packet.

Definition at line 526 of file packet.cpp.

void Packet::GrowPacket ( unsigned int  size ) [protected]

Grows the packet size to fit the size desired.

Parameters:
sizeThe size to grow to fit.

Definition at line 1937 of file packet.cpp.

int Packet::Insert ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos = 0 
)

Inserts buffered data into the packet at a position.

This function can be used to pre-pend data or insert data into the middle of a packet. This also resets the read position back to the beginning and moves the write pos to the end of the packet.

Parameters:
lenThe length of the data to insert.
buffThe buffered data to insert.
posThe starting position in the packet [0,Length()).
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if inserted properly.

Definition at line 404 of file packet.cpp.

int Packet::InsertCharacter ( const unsigned char  value,
const unsigned int  len,
const unsigned int  pos = 0 
)

Inserts a value into the packet and repeats it the number of times specified. This can be useful when you are trying to reserve a block of memory within a packet for future data.

This function can be used to pre-pend data or insert data into the middle of a packet. This function will reset the read pos back to 0 (the beginning). The write pos will be reset to the end of the packet.

Parameters:
lenThe length of the data to insert. ( number of times to repeat the value ).
valueThe byte value to insert, typically 0.
posThe starting position in the packet [0,Length()).
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if inserted properly.

Definition at line 446 of file packet.cpp.

unsigned int Packet::Length (  ) const
Returns:
Length of the entire packet in bytes (includes header and data).

Definition at line 572 of file packet.cpp.

bool Packet::LoadWiresharkCapturePacketExport ( const std::string &  filename,
Packet::List packets 
) [static]

Method to load a exported capture file constructed by the program Wireshark.

This method will only load an export of the packet data, with the file containing contents in a specifc format exported from WireShark.

Parameters:
[in]filenameName of the file containing data.
[out]packetsPacket data extracted.
Returns:
True on success, false on failure.

Definition at line 1968 of file packet.cpp.

Packet & Packet::operator+= ( const Packet another )

Adds packet data to the end of the current packet.

Definition at line 1903 of file packet.cpp.

Packet & Packet::operator= ( const Packet another )

Copies contents of packet.

Definition at line 1873 of file packet.cpp.

unsigned char Packet::operator[] ( const unsigned int  index ) const

Method to index into internal array.

Parameters:
[in]indexIndex into packet byte array [0, Length()).
Returns:
Value in packet buffer at index (0 on out of range).

Definition at line 1919 of file packet.cpp.

void Packet::Print ( const unsigned int  bytesPerLine = 8 ) const

Prints byte data to the console.

Parameters:
bytesPerLineNumber of bytes to print per line.

Definition at line 1053 of file packet.cpp.

const unsigned char * Packet::Ptr (  ) const
Returns:
Pointer to written data buffer.

Definition at line 1851 of file packet.cpp.

unsigned char * Packet::Ptr (  )
Returns:
Pointer to written data buffer.

Definition at line 1862 of file packet.cpp.

int Packet::Read ( char &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1121 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
unsigned int &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1620 of file packet.cpp.

int Packet::Read ( short &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1175 of file packet.cpp.

int Packet::Read ( unsigned short &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1256 of file packet.cpp.

int Packet::Read ( unsigned int &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1229 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
unsigned char &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1515 of file packet.cpp.

int Packet::Read ( long long int &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1202 of file packet.cpp.

int Packet::Read ( unsigned long long int &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1283 of file packet.cpp.

int Packet::Read ( float &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1310 of file packet.cpp.

int Packet::Read ( double &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1343 of file packet.cpp.

int Packet::Read ( unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Parameters:
buffPointer to array to save results to.
lenNumber of bytes to read/size of buff.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1373 of file packet.cpp.

int Packet::Read ( Packet packet,
const unsigned int  len,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads in the number of bytes listed and puts the result into a packet.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Parameters:
packetThe packet to read into.
lenNumber of bytes to read/size and put in the string.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1418 of file packet.cpp.

int Packet::Read ( std::string &  str,
const unsigned int  len,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads in the number of bytes listed and puts the result into a string.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Parameters:
strString to store result int.
lenNumber of bytes to read/size and put in the string.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1465 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
char &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1550 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
int &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1585 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
short &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1655 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
unsigned short &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1690 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
double &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1830 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
long long int &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1725 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
unsigned long long int &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1760 of file packet.cpp.

int Packet::Read ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
float &  val,
const unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [static]

Reads the data from a buffer at the byte position specified.

Byte order conversion is performed automatically based on the byte order set by the border parameter. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
buffThe buffered data to try read from.
lenThe total length of the buffer.
posThe byte position in the buffer to read at.
valThe read data.
borderThe byte order of the data in the buffer. Set this so that the data is converted to the system byte order automatically. Possible values are CX_PACKET_LITTLE_ENDIAN, CX_PACKET_BIG_ENDIAN.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1795 of file packet.cpp.

int Packet::Read ( unsigned char &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1094 of file packet.cpp.

int Packet::Read ( int &  val,
const unsigned int  pos = UINT_MAX 
) const [virtual]

Reads the data from the packet at the byte position specified or using the internal read byte position value. The latter is the default behavior.

A call to this function will advance the read position the number of bytes read if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data read.
posThe byte position within the packet to read at. If pos is equal to UINT_MAX, then the internal read position is used, which is the default behavior.
Returns:
The number of bytes read, 0 if nothing read.

Definition at line 1148 of file packet.cpp.

template<class T >
static int CxUtils::Packet::ReadAtPos ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos,
T &  val,
unsigned int  border = CX_PACKET_LITTLE_ENDIAN 
) [inline, static, protected]

Read and read value from packet.

Definition at line 376 of file packet.h.

template<class T >
static int CxUtils::Packet::ReadPacket ( const Packet packet,
T &  val,
unsigned int  pos = UINT_MAX 
) [inline, static, protected]

Read and read value from packet.

Definition at line 319 of file packet.h.

void Packet::Reserve ( const unsigned int  size )

Reserves memory for storing data or receiving data over a connection.

Parameters:
sizeNumber of bytes to reserve (no matter what will be equal to CX_HEADER_SIZE to hold minimum packet size).

Definition at line 583 of file packet.cpp.

unsigned int CxUtils::Packet::Reserved (  ) const [inline]

Definition at line 144 of file packet.h.

int Packet::SetByteOrder ( const unsigned int  order = CX_PACKET_LITTLE_ENDIAN )

Sets what byte order the data should be stored as in the buffer.

If the byte order is set to little endian (CX_PACKET_LITTLE_ENDIAN), and the system is big endian, the data will be converted when writing to and reading from the packet. The same is true if the byte order is set to big endian (CX_PACKET_BIG_ENDIAN) and the system is little endian. If the system byte order matches the byte order value set, then not byte order conversion occurs.

The default value for storage of data is CX_PACKET_LITTLE_ENDIAN.

Parameters:
orderByte order type to store data in packet as.
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if set properly.

Definition at line 301 of file packet.cpp.

int Packet::SetLength ( const unsigned int  len = 0 )

Sets the length of the data written in the packet to a new value.

The length set must be less than the amount of memory reserved. This is only an extra function for some special use cases, and should typically not be used.

The advantage to having this method is if you know you need to write a header at the beginning of the packet, but it requires values that can't be known until after the message body has been written. Using this method, you can set the length to after the header, write the data, then go back and write the header at the beginning.

The write and read position values within the packet will be reset to zero on this function call.

Parameters:
lenNew length of written data in packet.
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if set properly.

Definition at line 377 of file packet.cpp.

int Packet::SetReadPos ( const unsigned int  pos = 0 ) const

Sets the position for reading data from the packet. This is the byte position.

Parameters:
posByte number to start reading from.
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if set properly.

Definition at line 343 of file packet.cpp.

int Packet::SetWritePos ( const unsigned int  pos = 0 )

Sets the position for writing data in the packet.

Parameters:
posByte number to start writing to.
Returns:
CX_PACKET_FAILURE on error, CX_PACKET_OK if set properly.

Definition at line 321 of file packet.cpp.

unsigned int Packet::Size (  ) const
Returns:
Length of the entire packet in bytes (includes header and data).

Definition at line 565 of file packet.cpp.

int Packet::Write ( const float  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 916 of file packet.cpp.

int Packet::Write ( const unsigned int  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 754 of file packet.cpp.

int Packet::Write ( const Packet packet,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
packetPacket data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 978 of file packet.cpp.

int Packet::Write ( const char  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 727 of file packet.cpp.

int Packet::Write ( const double  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 947 of file packet.cpp.

int Packet::Write ( const int  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 808 of file packet.cpp.

int Packet::Write ( const unsigned long long int  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 889 of file packet.cpp.

int Packet::Write ( const std::string &  str,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the string data to the packet.

Parameters:
strString data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 996 of file packet.cpp.

int Packet::Write ( const unsigned char  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 700 of file packet.cpp.

int Packet::Write ( const unsigned char *  buff,
const unsigned int  len,
const unsigned int  pos = UINT_MAX 
) [virtual]

Write the data to the end of the packet. No byte order conversion is perfomed using this function.

Parameters:
buffThe data to add to end of packet.
lenThe size of the data in bytes.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
Number of bytes written.

Definition at line 631 of file packet.cpp.

int Packet::Write ( const short  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 835 of file packet.cpp.

int Packet::Write ( const long long int  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 862 of file packet.cpp.

int Packet::Write ( const unsigned short  val,
const unsigned int  pos = UINT_MAX 
) [virtual]

Writes the data into the packet at the byte position specified or using the internal write byte position value. The latter is the default behavior.

A call to this function will advance the write position the number of bytes written if pos is not used because it is set to UINT_MAX.

Byte order conversion is performed automatically based on the byte order set using the SetByteOrder function. The default byte order is used is CX_PACKET_LITTLE_ENDIAN.

Parameters:
valThe data to write.
posThe byte position within the packet to write at. If pos is equal to UINT_MAX, then the internal write position is used, which is the default behavior.
Returns:
The number of bytes written, 0 if nothing written.

Definition at line 781 of file packet.cpp.

virtual int CxUtils::Packet::WriteByte ( const unsigned char  byte ) [inline, virtual]

Definition at line 160 of file packet.h.

template<class T >
static int CxUtils::Packet::WritePacket ( Packet p,
const T  val,
const unsigned int  pos = UINT_MAX 
) [inline, static, protected]

Writes a value to buffer in packet.

Definition at line 232 of file packet.h.


Friends And Related Function Documentation

friend class Wrapper [friend]

Definition at line 100 of file packet.h.


Member Data Documentation

unsigned int CxUtils::Packet::mByteOrder [protected]

Byte order to write data as within packet.

Definition at line 228 of file packet.h.

unsigned int CxUtils::Packet::mLength [protected]

Length of written data.

Definition at line 224 of file packet.h.

unsigned char* CxUtils::Packet::mpPacket [protected]

Writed data.

Definition at line 223 of file packet.h.

unsigned int CxUtils::Packet::mReadPos [protected]

Read position in packet.

Definition at line 227 of file packet.h.

unsigned int CxUtils::Packet::mReserved [protected]

Amount of data reserved.

Definition at line 225 of file packet.h.

Flag used to force a fixed size packet (mainly used by Wrapper).

Definition at line 229 of file packet.h.

unsigned int CxUtils::Packet::mWritePos [protected]

Encoding position in packet.

Definition at line 226 of file packet.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines