#include <Packet.h>
Inheritance diagram for GNE::Packet:
Public Types | |
typedef SmartPtr< Packet > | sptr |
typedef WeakPtr< Packet > | wptr |
Public Member Functions | |
Packet (int id=0) | |
Constructs a packet with the given ID. | |
Packet (const Packet &o) | |
Copy constructor. | |
Packet * | makeClone () const |
Returns a newly allocated exact copy of this packet, using the PacketParser::clonePacket function. | |
int | getType () const |
Returns the type of this instance. | |
virtual int | getSize () const |
Returns the current size of this packet in bytes. | |
virtual void | writePacket (Buffer &raw) const |
Writes the packet to the given Buffer. | |
virtual void | readPacket (Buffer &raw) |
Reads this packet from the given Buffer. | |
Packet & | operator= (const Packet &rhs) |
Copy operator you can use to help you in creating your own. | |
Static Public Attributes | |
const int | ID = 0 |
The ID for this type of packet. |
When you create a new packet you MUST define your own versions of all virtual functions or the program will fail.
See the example expacket on how to properly derive from a Packet class, or look at the code for the other GNE packets.
|
Constructs a packet with the given ID. If you pass no ID, the ID for an empty packet is assumed. Normally sending blank packets are not useful, however. If you are wanting to use a blank packet for some purpose such as a end-of-data marker or for sending some message that requires no data, it is suggested that you simply derive a class from Packet that adds no data, but has a unique ID so it can be "recognized" easier.
|
|
Copy constructor. If your Packet is using the default packet clone function in registration, remember that it uses the copy constructor so if you need to override the default implementation, you must do it. |
|
Returns the current size of this packet in bytes. When overloading this function, call getSize on the parent class then add the sizes of your additional variables. If the size cannot be determined, then getSize should return a value <= Buffer::RAW_PACKET_LEN but >= its possible size -- so in other words if the size cannot be determined, it should return the largest possible size that given packet could be. This is discouraged as much as possible since GNE allocates packets in the data stream based on this value, and large values will hinder performance. Reimplemented in GNE::ChannelPacket, GNE::CustomPacket, GNE::ExitPacket, GNE::ObjectBrokerPacket, GNE::PingPacket, GNE::RateAdjustPacket, and GNE::WrapperPacket. |
|
Returns the type of this instance. This allows you to identify the type of packet you have when you only have a Packet*. |
|
Copy operator you can use to help you in creating your own. There is a debug assert in this function that checks to make sure the types match. Call this operator first from your copy operator. Many GNE packets may not support this operation, so check the documentation first -- if no operator = exists, then assume you cannot copy packets this way, unless the documentation says otherwise. If you can't use operator= on a packet, you can use makeClone to achieve a nearly equivalent result. |
|
Reads this packet from the given Buffer. When overloading this function, call readPacket on the parent class then read your own variables. This method is allowed to throw any subclass of Error. This can happen if accessing the Packet causes a buffer underflow, but an error might occur in the format or consistancy of the data for the user's derived class. If you cannot construct a proper Packet of your type from the data in raw, then you should throw a subclass of Error. Reimplemented in GNE::ChannelPacket, GNE::CustomPacket, GNE::ExitPacket, GNE::ObjectBrokerPacket, GNE::PingPacket, GNE::RateAdjustPacket, and GNE::WrapperPacket. |
|
Writes the packet to the given Buffer. You can continue writing more packets to the Buffer after this method. You must make sure there is enough space in the Buffer to fit this new packet. When overloading this function, call writePacket on the parent class then write your own variables. No more than getSize() bytes may be written to the Buffer. This method is allowed to throw any subclass of Error. Typically this only happens if accesses to Packet case a buffer overflow. Reimplemented in GNE::ChannelPacket, GNE::CustomPacket, GNE::ExitPacket, GNE::ObjectBrokerPacket, GNE::PingPacket, GNE::RateAdjustPacket, and GNE::WrapperPacket. |