Data structure for storing message data into a buffer. More...
#include <packet.h>
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< Packet > | List |
List of packets. | |
typedef std::list< Packet > | Queue |
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 () |
Packet & | operator= (const Packet &another) |
Copies contents of packet. | |
Packet & | operator+= (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 |
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.
typedef std::vector<Packet> CxUtils::Packet::List |
typedef std::list<Packet> CxUtils::Packet::Queue |
Packet::Packet | ( | const unsigned int | border = CX_PACKET_LITTLE_ENDIAN ) |
Constructor.
border | Byte 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.
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.
[in] | setZeroFlag | If 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.
len | The number of bytes to delete. |
start | The starting position in the packet [0,Length()). |
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.
Definition at line 555 of file packet.cpp.
static unsigned int CxUtils::Packet::GetMachineEndianness | ( | ) | [inline, static] |
unsigned int Packet::GetReadPos | ( | ) | const |
Definition at line 536 of file packet.cpp.
unsigned int Packet::GetWritePos | ( | ) | const |
Definition at line 526 of file packet.cpp.
void Packet::GrowPacket | ( | unsigned int | size ) | [protected] |
Grows the packet size to fit the size desired.
size | The 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.
len | The length of the data to insert. |
buff | The buffered data to insert. |
pos | The starting position in the packet [0,Length()). |
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.
len | The length of the data to insert. ( number of times to repeat the value ). |
value | The byte value to insert, typically 0. |
pos | The starting position in the packet [0,Length()). |
Definition at line 446 of file packet.cpp.
unsigned int Packet::Length | ( | ) | const |
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.
[in] | filename | Name of the file containing data. |
[out] | packets | Packet data extracted. |
Definition at line 1968 of file packet.cpp.
Adds packet data to the end of the current packet.
Definition at line 1903 of file packet.cpp.
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.
[in] | index | Index into packet byte array [0, Length()). |
Definition at line 1919 of file packet.cpp.
void Packet::Print | ( | const unsigned int | bytesPerLine = 8 ) |
const |
Prints byte data to the console.
bytesPerLine | Number of bytes to print per line. |
Definition at line 1053 of file packet.cpp.
const unsigned char * Packet::Ptr | ( | ) | const |
Definition at line 1851 of file packet.cpp.
unsigned char * Packet::Ptr | ( | ) |
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.
val | The data read. |
pos | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
buff | Pointer to array to save results to. |
len | Number of bytes to read/size of buff. |
pos | The 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. |
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.
packet | The packet to read into. |
len | Number of bytes to read/size and put in the string. |
pos | The 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. |
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.
str | String to store result int. |
len | Number of bytes to read/size and put in the string. |
pos | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
buff | The buffered data to try read from. |
len | The total length of the buffer. |
pos | The byte position in the buffer to read at. |
val | The read data. |
border | The 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. |
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.
val | The data read. |
pos | The 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. |
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.
val | The data read. |
pos | The 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. |
Definition at line 1148 of file packet.cpp.
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] |
static int CxUtils::Packet::ReadPacket | ( | const Packet * | packet, |
T & | val, | ||
unsigned int | pos = UINT_MAX |
||
) | [inline, static, protected] |
void Packet::Reserve | ( | const unsigned int | size ) |
Reserves memory for storing data or receiving data over a connection.
size | Number 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.
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.
order | Byte order type to store data in packet as. |
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.
len | New length of written data in packet. |
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.
pos | Byte number to start reading from. |
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.
pos | Byte number to start writing to. |
Definition at line 321 of file packet.cpp.
unsigned int Packet::Size | ( | ) | const |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
packet | Packet data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
str | String data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
buff | The data to add to end of packet. |
len | The size of the data in bytes. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
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.
val | The data to write. |
pos | The 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. |
Definition at line 781 of file packet.cpp.
virtual int CxUtils::Packet::WriteByte | ( | const unsigned char | byte ) | [inline, virtual] |
static int CxUtils::Packet::WritePacket | ( | Packet * | p, |
const T | val, | ||
const unsigned int | pos = UINT_MAX |
||
) | [inline, static, protected] |
unsigned int CxUtils::Packet::mByteOrder [protected] |
unsigned int CxUtils::Packet::mLength [protected] |
unsigned char* CxUtils::Packet::mpPacket [protected] |
unsigned int CxUtils::Packet::mReadPos [protected] |
unsigned int CxUtils::Packet::mReserved [protected] |
bool CxUtils::Packet::mWrappedPacketFlag [protected] |
unsigned int CxUtils::Packet::mWritePos [protected] |