Typedefs | |
typedef Packet *(*) | PacketCreateFunc () |
A function pointer to a function that creates a new subclass of a Packet. | |
typedef Packet *(*) | PacketCloneFunc (const Packet *) |
A function pointer to a function to clone a Packet. | |
typedef void(*) | PacketDestroyFunc (Packet *) |
A function pointer to a function to destroy a Packet. | |
Functions | |
void | registerGNEPackets () |
void | registerPacket (guint8 id, PacketCreateFunc createFunc, PacketCloneFunc cloneFunc, PacketDestroyFunc destroyFunc) |
Registers a new type of packet, so GNE can recognize it. | |
Packet * | createPacket (guint8 id) |
Calls the packet creation function registered for the given ID. | |
Packet * | clonePacket (const Packet *p) |
Calls the packet clone function registered for the passed packet type. | |
void | destroyPacket (Packet *p) |
Calls the packet deletion function registered for the passed packet type. | |
Packet * | parseNextPacket (Buffer &raw) |
Parses the next packet from the given Buffer. | |
template<class T> | |
Packet * | defaultPacketCreateFunc () |
Default packet creation function using the "new" operator and the default constructor. | |
template<class T> | |
Packet * | defaultPacketCloneFunc (const Packet *p) |
Default packet clone function using the "new" operator and the copy constructor. | |
template<class T> | |
void | defaultPacketDestroyFunc (Packet *p) |
Default packet destroy function using the "delete" operator. | |
template<class T> | |
void | defaultRegisterPacket () |
Default registration function that works for typical packets without any custom memory allocation. | |
Variables | |
const guint8 | MIN_USER_ID = 16 |
The first number suitable for the user to give IDs to their packets. | |
const guint8 | MAX_USER_ID = 254 |
const guint8 | END_OF_PACKET = 255 |
The network packet ends with this byte, meaning that no more GNE packets exist in this network packet (end-of-data). |
Also contains important constants to be aware of for assigning your packets IDs.
typedef Packet*(*) GNE::PacketParser::PacketCreateFunc() |
A function pointer to a function that creates a new subclass of a Packet.
The return type is of the type registered with this function.
typedef Packet*(*) GNE::PacketParser::PacketCloneFunc(const Packet *) |
typedef void(*) GNE::PacketParser::PacketDestroyFunc(Packet *) |
void GNE::PacketParser::registerGNEPackets | ( | ) |
void GNE::PacketParser::registerPacket | ( | guint8 | id, | |
PacketCreateFunc | createFunc, | |||
PacketCloneFunc | cloneFunc, | |||
PacketDestroyFunc | destroyFunc | |||
) |
Registers a new type of packet, so GNE can recognize it.
In order for GNE to recognize, create, and parse your packets derived from the Packet class, you should register it here, preferably right after initalizing GNE.
You can only register packets from MIN_USER_ID to MAX_USER_ID, inclusive. You may not register a packet multiple times.
Unless you want to create your own memory allocation system, you should consider using the defaultRegisterPacket function.
Packet * GNE::PacketParser::createPacket | ( | guint8 | id | ) |
Calls the packet creation function registered for the given ID.
The ID passed MUST be registered.
Packet * GNE::PacketParser::clonePacket | ( | const Packet * | p | ) |
Calls the packet clone function registered for the passed packet type.
This is based on the Packet::getType() method.
void GNE::PacketParser::destroyPacket | ( | Packet * | p | ) |
Calls the packet deletion function registered for the passed packet type.
This is based on the Packet::getType() method.
Packet * GNE::PacketParser::parseNextPacket | ( | Buffer & | raw | ) |
void GNE::PacketParser::defaultRegisterPacket | ( | ) |
Default registration function that works for typical packets without any custom memory allocation.
This function is a template, and is equivalent to:
registerPacket( T::id, defaultPacketCreateFunc<T>, defaultPacketCloneFunc<T>, defaultPacketDestroyFunc<T> );
const guint8 GNE::PacketParser::MIN_USER_ID = 16 |
The first number suitable for the user to give IDs to their packets.
Any numbers between MIN_USER_ID and MAX_USER_ID inclusive belong to the user. It is suggested that the user assign packet numbers by adding to MIN_USER_ID. (i.e. MIN_USER_ID + 5)
const guint8 GNE::PacketParser::MAX_USER_ID = 254 |