CPacket Class Reference
The class used for packet exchange with network module and creating-decoding packets.
More...
#include <Packet.h>
List of all members.
|
Public Member Functions |
| CPacket () |
void | SetUser (const char *user) |
const char * | GetUser () |
void | SetModule (int module) |
int | GetModule () |
void | EnlargeDataSize (int size) |
void | ResetWrite () |
| Clears all of the written data to the packet. No need to call for newly created packets.
|
void | WriteInt1 (int i) |
| Writes a 1 byte integer to the packet.
|
void | WriteInt2 (int i) |
| Writes a 2 byte integer to the packet.
|
void | WriteInt4 (int i) |
| Writes a 4 byte integer to the packet.
|
void | WriteChar (char c) |
| Writes a char to the packet.
|
void | WriteFloat (float f) |
| Writes a float to the packet.
|
void | WriteString (const char *s) |
| Writes a string to the packet.
|
void | WriteString (string s) |
| Writes a string to the packet.
|
void | WriteBinary (const void *b, int length) |
| Writes binary data to the packet.
|
void * | WriteBinary (int length) |
void | ResetRead () |
| Makes the reading return to the start of the packet. No need to call this if the packet is received from the network module.
|
int | ReadInt1 () |
| Reads a 1 byte integer from the packet.
|
int | ReadInt2 () |
| Reads a 2 byte integer from the packet.
|
int | ReadInt4 () |
| Reads a 4 byte integer from the packet.
|
char | ReadChar () |
| Reads a char from the packet.
|
float | ReadFloat () |
| Reads a float from the packet.
|
const char * | ReadString () |
| Reads a string from the packet by returning the readonly pointer to it. Important: The returned string should not be accessed after returning from ReceivePacket.
|
string | ReadSTLString () |
| Reads a string from the packet and returns it as an STL string.
|
const void * | ReadBinary (int length) |
void | ReadBinary (void *b, int length) |
| ~CPacket () |
Detailed Description
The class used for packet exchange with network module and creating-decoding packets.
The class used for packet exchange with network module and creating-decoding packets.
- See also:
- CModule_Conn::SendPacket CModule_Conn::ReceivePacket
Constructor & Destructor Documentation
Consructor. When a packet is created it is ready for being written. OPSIMUS convention states: Packets must be destroyed by their creators. So after creating and sending a packet you must destroy it yourself.
Destructor. OPSIMUS convention states: Packets must be destroyed by their creators. So after creating and sending a packet you must destroy it yourself. And destroy packets that you did not create.
Member Function Documentation
void CPacket::SetUser |
( |
const char * |
user |
) |
|
Sets the user(network module user id) of the packet. Setting it is not necessary if the packet will be sent to the server. User property indicates to which user the packet is directed to or is from which user.
- Parameters:
-
const char* CPacket::GetUser |
( |
|
) |
|
Gets the user(network module user id) of the packet. Reading is meaningless if the packet is received from the server. User property indicates to which user the packet is directed to or is from which user.
- Returns:
- The readonly string denoting the user. If the return value is NULL, this means that the user field is left empty.
void CPacket::SetModule |
( |
int |
module |
) |
|
Sets the module identifier of the packet. Module property is the type of the packet. Indicates to which module the packet must be directed to. Most of the time this function is not used since SendPacket of each handles this field.
- Parameters:
-
| module | The module identifier to be set. Must be one of the ID_* values declared in Module.h . |
int CPacket::GetModule |
( |
|
) |
|
Gets the module of the packet. Module property is the type of the packet. Indicates to which module the packet must be directed to.
- Returns:
- The module identifier for this packet.
void CPacket::EnlargeDataSize |
( |
int |
size |
) |
|
Sets the size of the data portion in the packet. Call this if you know the size of the data portion before writing and you want to reduce the number of memory reallocations.
- Parameters:
-
| size | The size of intended data portion in bytes. Example: If you are going to write 3 chars to the packet call EnlargeDataSize(3). |
void* CPacket::WriteBinary |
( |
int |
length |
) |
|
Writes binary data to the packet.
- Parameters:
-
| length | The length of the binary data in bytes. Notice that this field is not written to the packet. So if you want to retrieve the size of the binary data upon receiving a packet you must write it manually. |
- Returns:
- The address pointing to the memory area that the binary data should be written. You can write the data by directly modifying this memory area which is length(the parameter) bytes.
const void* CPacket::ReadBinary |
( |
int |
length |
) |
|
Reads binary data from the packet.
- Parameters:
-
| length | The length of the data to read in bytes. |
- Returns:
- The readonly pointer to the binary data. Important: The returned data should not be accessed after returning from ReceivePacket.
void CPacket::ReadBinary |
( |
void * |
b, |
|
|
int |
length | |
|
) |
| | |
Reads binary data from the packet.
- Parameters:
-
| b | The address of the destination area that the read binary data will be written. |
| length | The length of the data to read in bytes. |
The documentation for this class was generated from the following file: