Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::CustomPacket Class Reference
[Mid-Level API]

#include <CustomPacket.h>

Inheritance diagram for GNE::CustomPacket:

GNE::Packet List of all members.

Public Types

typedef SmartPtr< CustomPacket > sptr
typedef WeakPtr< CustomPacket > wptr

Public Member Functions

 CustomPacket (const CustomPacket &o)
BuffergetBuffer ()
 Returns the Buffer for reading or writing.

void clear ()
 If you want to reuse a CustomPacket after using it for reading or writing, you should call clear which will reset this object as if it were newly constructed with the default constructor.

virtual int getSize () const
virtual void writePacket (Buffer &raw) const
 Writes a CustomPacket to the given Buffer.

virtual void readPacket (Buffer &raw)
 Reads a CustomPacket from the given Buffer.


Static Public Member Functions

int getMaxUserDataSize ()
 Returns the capacity of Buffers created by CustomPacket made for writing.


Static Public Attributes

const int ID = 1
 The ID for this type of packet.


Detailed Description

Many times, espically during connection, you want to send some more "free-form" data that may or may not all be related and will only be sent once. It may not make sense to create a completely new packet type just to send a few things one time. This packet type will allow you to send whatever you want. Basically, CustomPacket is just a packet that contains a Buffer. You can use the Buffer to put in data and pull it out. Remember Buffer does endian and processor-type conversions for you.

The maximum amount of data that can be stored in the CustomPacket is defined by its Buffer's capacity, which at the current time is 3 bytes smaller than Buffer::RAW_PACKET_LEN.

See the documentation for Packet for more info on some of these functions.


Member Function Documentation

Buffer & GNE::CustomPacket::getBuffer  ) 
 

Returns the Buffer for reading or writing.

You should not keep the returned reference longer than the packet's destruction, or a reset or readPacket call.

When writing data to the buffer, do not call "flip" after writing data. The position should be left at the point after your last write call.

After a CustomPacket has been read, and you are pulling data out of it, the position and the limit will be the number of bytes stored in this CustomPacket. You need to call rewind or flip (at this point, both are equivalent) on the buffer before pulling data from it, or a buffer overflow exception will result.

int GNE::CustomPacket::getSize  )  const [virtual]
 

See also:
Packet::getSize()

Reimplemented from GNE::Packet.

void GNE::CustomPacket::readPacket Buffer raw  )  [virtual]
 

Reads a CustomPacket from the given Buffer.

The data in this packet will be erased and replaced by the new data. Then flip is called on the Buffer, so position is 0 and the bytes this CustomPacket contains is the Buffer's limit.

Reimplemented from GNE::Packet.

void GNE::CustomPacket::writePacket Buffer raw  )  const [virtual]
 

Writes a CustomPacket to the given Buffer.

Flip will be called on the Buffer then it will be written to the passed Buffer, so the final result will be an unchanged position, but limit == position.

Reimplemented from GNE::Packet.


The documentation for this class was generated from the following files:
Generated on Fri Aug 22 13:40:06 2003 for GNE by doxygen1.3