Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Datagram Class Reference

An ordered list of data elements, formatted in memory for transmission over a socket or writing to a data file. More...

#include <datagram.h>

Inheritance diagram for Datagram:

TypedObject NetDatagram List of all members.

Public Member Functions

 Datagram ()
 Constructs an empty datagram.

 Datagram (const void *data, size_t size)
 Constructs a datagram from an existing block of data.

 Datagram (const string &data)
 Constructs a datagram from an existing block of data.

 Datagram (const Datagram &copy)
void operator= (const Datagram &copy)
virtual ~Datagram ()
virtual void clear ()
 Resets the datagram to empty, in preparation for building up a new datagram.

void dump_hex (ostream &out) const
 Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.

void add_bool (bool value)
 Adds a boolean value to the datagram.

void add_int8 (PN_int8 value)
 Adds a signed 8-bit integer to the datagram.

void add_uint8 (PN_uint8 value)
 Adds an unsigned 8-bit integer to the datagram.

void add_int16 (PN_int16 value)
 Adds a signed 16-bit integer to the datagram.

void add_int32 (PN_int32 value)
 Adds a signed 32-bit integer to the datagram.

void add_int64 (PN_int64 value)
 Adds a signed 64-bit integer to the datagram.

void add_uint16 (PN_uint16 value)
 Adds an unsigned 16-bit integer to the datagram.

void add_uint32 (PN_uint32 value)
 Adds an unsigned 32-bit integer to the datagram.

void add_uint64 (PN_uint64 value)
 Adds an unsigned 64-bit integer to the datagram.

void add_float32 (float value)
 Adds a 32-bit single-precision floating-point number to the datagram.

void add_float64 (PN_float64 value)
 Adds a 64-bit floating-point number to the datagram.

void add_be_int16 (PN_int16 value)
 Adds a signed 16-bit big-endian integer to the datagram.

void add_be_int32 (PN_int32 value)
 Adds a signed 32-bit big-endian integer to the datagram.

void add_be_int64 (PN_int64 value)
 Adds a signed 64-bit big-endian integer to the datagram.

void add_be_uint16 (PN_uint16 value)
 Adds an unsigned 16-bit big-endian integer to the datagram.

void add_be_uint32 (PN_uint32 value)
 Adds an unsigned 32-bit big-endian integer to the datagram.

void add_be_uint64 (PN_uint64 value)
 Adds an unsigned 64-bit big-endian integer to the datagram.

void add_be_float32 (float value)
 Adds a 32-bit single-precision big-endian floating-point number to the datagram.

void add_be_float64 (PN_float64 value)
 Adds a 64-bit big-endian floating-point number to the datagram.

void add_string (const string &str)
 Adds a variable-length string to the datagram.

void add_z_string (string str)
 Adds a variable-length string to the datagram, as a NULL-terminated string.

void add_fixed_string (const string &str, size_t size)
 Adds a fixed-length string to the datagram.

void pad_bytes (size_t size)
 Adds the indicated number of zero bytes to the datagram.

void append_data (const void *data, size_t size)
 Appends some more raw data to the end of the datagram.

void append_data (const string &data)
 Appends some more raw data to the end of the datagram.

string get_message () const
 Returns the datagram's data as a string.

const void * get_data () const
 Returns a pointer to the beginning of the datagram's data.

size_t get_length () const
 Returns the number of bytes in the datagram.

bool operator== (const Datagram &other) const
bool operator!= (const Datagram &other) const
bool operator< (const Datagram &other) const
virtual TypeHandle get_type () const
virtual TypeHandle force_init_type ()
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.

bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.


Static Public Member Functions

TypeHandle get_class_type ()
void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.


Private Attributes

PTA_uchar _data

Static Private Attributes

TypeHandle _type_handle

Detailed Description

An ordered list of data elements, formatted in memory for transmission over a socket or writing to a data file.

Data elements should be added one at a time, in order, to the Datagram. The nature and contents of the data elements are totally up to the user. When a Datagram has been transmitted and received, its data elements may be extracted using a DatagramIterator; it is up to the caller to know the correct type of each data element in order.

A Datagram is itself headerless; it is simply a collection of data elements.

Definition at line 66 of file datagram.h.


Constructor & Destructor Documentation

Datagram::Datagram  )  [inline]
 

Constructs an empty datagram.

Definition at line 31 of file datagram.I.

References append_data(), and INLINE.

Datagram::Datagram const void *  data,
size_t  size
[inline]
 

Constructs a datagram from an existing block of data.

Definition at line 43 of file datagram.I.

References append_data(), and INLINE.

Datagram::Datagram const string &  data  )  [inline]
 

Constructs a datagram from an existing block of data.

Definition at line 56 of file datagram.I.

Datagram::Datagram const Datagram &  copy  )  [inline]
 

Definition at line 68 of file datagram.I.

References add_uint8(), and INLINE.

Datagram::~Datagram  )  [virtual]
 

Definition at line 40 of file datagram.cxx.

References _data, and PointerToArray< unsigned char >::clear().


Member Function Documentation

void Datagram::add_be_float32 float  value  )  [inline]
 

Adds a 32-bit single-precision big-endian floating-point number to the datagram.

Since this kind of float is not necessarily portable across different architectures, special care is required.

Definition at line 357 of file datagram.I.

References append_data(), and INLINE.

void Datagram::add_be_float64 PN_float64  value  )  [inline]
 

Adds a 64-bit big-endian floating-point number to the datagram.

Definition at line 377 of file datagram.I.

References _data, INLINE, and PointerToArray< unsigned char >::p().

void Datagram::add_be_int16 PN_int16  value  )  [inline]
 

Adds a signed 16-bit big-endian integer to the datagram.

Definition at line 257 of file datagram.I.

References append_data(), ReversedNumericData::get_data(), and INLINE.

void Datagram::add_be_int32 PN_int32  value  )  [inline]
 

Adds a signed 32-bit big-endian integer to the datagram.

Definition at line 273 of file datagram.I.

References append_data(), ReversedNumericData::get_data(), INLINE, and nassertv.

void Datagram::add_be_int64 PN_int64  value  )  [inline]
 

Adds a signed 64-bit big-endian integer to the datagram.

Definition at line 289 of file datagram.I.

References append_data(), ReversedNumericData::get_data(), and INLINE.

void Datagram::add_be_uint16 PN_uint16  value  )  [inline]
 

Adds an unsigned 16-bit big-endian integer to the datagram.

Definition at line 305 of file datagram.I.

void Datagram::add_be_uint32 PN_uint32  value  )  [inline]
 

Adds an unsigned 32-bit big-endian integer to the datagram.

Definition at line 321 of file datagram.I.

References add_uint8(), append_data(), and size_t.

void Datagram::add_be_uint64 PN_uint64  value  )  [inline]
 

Adds an unsigned 64-bit big-endian integer to the datagram.

Definition at line 337 of file datagram.I.

References append_data(), INLINE, and pad_bytes().

void Datagram::add_bool bool  value  )  [inline]
 

Adds a boolean value to the datagram.

Definition at line 94 of file datagram.I.

References append_data(), and INLINE.

Referenced by Camera::add_display_region().

void Datagram::add_fixed_string const string &  str,
size_t  size
[inline]
 

Adds a fixed-length string to the datagram.

If the string given is less than the requested size, this will pad the string out with zeroes; if it is greater than the requested size, this will silently truncate the string.

Definition at line 442 of file datagram.I.

void Datagram::add_float32 float  value  )  [inline]
 

Adds a 32-bit single-precision floating-point number to the datagram.

Since this kind of float is not necessarily portable across different architectures, special care is required.

Definition at line 223 of file datagram.I.

References append_data(), ReversedNumericData::get_data(), and INLINE.

Referenced by GeomLine::draw_immediate(), GeomLinestrip::explode(), FFTCompressor::get_transpose_quats(), Spotlight::CData::make_copy(), LODSwitch::operator==(), Material::output(), AnimBundle::output(), and PStatCollectorDef::set_parent().

void Datagram::add_float64 PN_float64  value  )  [inline]
 

Adds a 64-bit floating-point number to the datagram.

Definition at line 241 of file datagram.I.

References append_data(), ReversedNumericData::get_data(), and INLINE.

Referenced by ClassicNurbsCurve::convert_to_nurbs().

void Datagram::add_int16 PN_int16  value  )  [inline]
 

Adds a signed 16-bit integer to the datagram.

Definition at line 133 of file datagram.I.

References append_data(), NativeNumericData::get_data(), and INLINE.

Referenced by ComputedVerticesMorph< ValueType, MorphValueType >::ComputedVerticesMorph(), and PStatCollectorDef::set_parent().

void Datagram::add_int32 PN_int32  value  )  [inline]
 

Adds a signed 32-bit integer to the datagram.

Definition at line 147 of file datagram.I.

References append_data(), NativeNumericData::get_data(), and INLINE.

Referenced by Material::output(), and DownloadDb::Db::write().

void Datagram::add_int64 PN_int64  value  )  [inline]
 

Adds a signed 64-bit integer to the datagram.

Definition at line 161 of file datagram.I.

void Datagram::add_int8 PN_int8  value  )  [inline]
 

Adds a signed 8-bit integer to the datagram.

Definition at line 107 of file datagram.I.

Referenced by ColorAttrib::compare_to_impl(), and ClassicNurbsCurve::convert_to_nurbs().

void Datagram::add_string const string &  str  )  [inline]
 

Adds a variable-length string to the datagram.

This actually adds a count followed by n bytes.

Definition at line 393 of file datagram.I.

References _data, INLINE, NULL, uchar, and PointerToArray< unsigned char >::v().

Referenced by AnimGroup::output(), PStatClientControlMessage::PStatClientControlMessage(), PStatServerControlMessage::PStatServerControlMessage(), and PStatCollectorDef::set_parent().

void Datagram::add_uint16 PN_uint16  value  )  [inline]
 

Adds an unsigned 16-bit integer to the datagram.

Definition at line 175 of file datagram.I.

Referenced by CharacterJoint::add_local_transform(), ComputedVerticesMorph< ValueType, MorphValueType >::ComputedVerticesMorph(), PandaNode::CData::fillin(), GeomNode::CData::make_copy(), AnimGroup::output(), AnimChannelBase::output(), AnimBundle::output(), PStatClientControlMessage::PStatClientControlMessage(), PStatServerControlMessage::PStatServerControlMessage(), ComputedVerticesMorphValue3::read_datagram(), ComputedVerticesMorphValue2::read_datagram(), RenderEffects::return_new(), BamWriter::write_pointer(), and BamWriter::~BamWriter().

void Datagram::add_uint32 PN_uint32  value  )  [inline]
 

Adds an unsigned 32-bit integer to the datagram.

Definition at line 189 of file datagram.I.

References append_data(), and NativeNumericData::get_data().

Referenced by Camera::add_display_region(), ClassicNurbsCurve::convert_to_nurbs(), PandaNode::CData::make_copy(), DownloadDb::Db::write(), and DatagramOutputFile::write_header().

void Datagram::add_uint64 PN_uint64  value  )  [inline]
 

Adds an unsigned 64-bit integer to the datagram.

Definition at line 203 of file datagram.I.

void Datagram::add_uint8 PN_uint8  value  )  [inline]
 

Adds an unsigned 8-bit integer to the datagram.

Definition at line 120 of file datagram.I.

References append_data(), NativeNumericData::get_data(), and INLINE.

Referenced by add_be_uint32(), Datagram(), GeomSprite::print_draw_immediate(), PStatClientControlMessage::PStatClientControlMessage(), PStatServerControlMessage::PStatServerControlMessage(), Texture::register_with_read_factory(), and CollisionSolid::report_undefined_intersection_test().

void Datagram::add_z_string string  str  )  [inline]
 

Adds a variable-length string to the datagram, as a NULL-terminated string.

Definition at line 415 of file datagram.I.

References operator==().

void Datagram::append_data const string &  data  )  [inline]
 

Appends some more raw data to the end of the datagram.

Definition at line 463 of file datagram.I.

void Datagram::append_data const void *  data,
size_t  size
 

Appends some more raw data to the end of the datagram.

Definition at line 150 of file datagram.cxx.

References _data, size_t, uchar, and PointerToArray< unsigned char >::v().

Referenced by add_be_float32(), add_be_int16(), add_be_int32(), add_be_int64(), add_be_uint32(), add_be_uint64(), add_bool(), add_float32(), add_float64(), add_int16(), add_int32(), add_uint32(), add_uint8(), Datagram(), DownloadDb::Db::Db(), DownloadDb::Db::get_multifile_name(), DownloadDb::insert_new_version(), operator=(), and DownloadDb::Db::parse_header().

void Datagram::clear  )  [virtual]
 

Resets the datagram to empty, in preparation for building up a new datagram.

Reimplemented in NetDatagram.

Definition at line 54 of file datagram.cxx.

References get_data(), get_length(), and size_t.

Referenced by DownloadDb::Db::Db(), DownloadDb::Db::get_multifile_name(), DownloadDb::insert_new_version(), DownloadDb::Db::parse_header(), PStatClientControlMessage::PStatClientControlMessage(), PStatServerControlMessage::PStatServerControlMessage(), and DownloadDb::Db::write().

void Datagram::dump_hex ostream &  out  )  const
 

Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.

Definition at line 69 of file datagram.cxx.

virtual TypeHandle Datagram::force_init_type void   )  [inline, virtual]
 

Implements TypedObject.

Reimplemented in NetDatagram.

Definition at line 135 of file datagram.h.

TypeHandle Datagram::get_class_type void   )  [inline, static]
 

Reimplemented from TypedObject.

Reimplemented in NetDatagram.

Definition at line 124 of file datagram.h.

const void * Datagram::get_data  )  const [inline]
 

Returns a pointer to the beginning of the datagram's data.

Definition at line 491 of file datagram.I.

Referenced by clear(), DatagramIterator::get_be_int16(), DatagramIterator::get_be_uint64(), DatagramIterator::get_fixed_string(), DatagramIterator::get_float64(), DatagramIterator::get_int64(), DatagramIterator::get_uint16(), DatagramIterator::get_uint32(), DatagramIterator::get_uint64(), and DatagramOutputFile::write_header().

size_t Datagram::get_length void   )  const [inline]
 

Returns the number of bytes in the datagram.

Definition at line 504 of file datagram.I.

Referenced by clear(), DatagramIterator::get_be_uint64(), ConnectionWriter::send(), and DatagramOutputFile::write_header().

string Datagram::get_message  )  const [inline]
 

Returns the datagram's data as a string.

Definition at line 476 of file datagram.I.

Referenced by ClientState::ClientState(), DatagramUDPHeader::get_datagram_checksum(), DatagramTCPHeader::get_datagram_size(), HTTPClient::read(), Connection::set_ip_type_of_service(), Connection::set_keep_alive(), and DownloadDb::Db::write().

virtual TypeHandle Datagram::get_type void   )  const [inline, virtual]
 

Implements TypedObject.

Reimplemented in NetDatagram.

Definition at line 132 of file datagram.h.

int TypedObject::get_type_index  )  const [inline, inherited]
 

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

Definition at line 71 of file typedObject.I.

References TypeHandle::get_name(), TypedObject::get_type(), and INLINE.

void Datagram::init_type void   )  [inline, static]
 

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Reimplemented from TypedObject.

Reimplemented in NetDatagram.

Definition at line 127 of file datagram.h.

Referenced by ConfigureFn().

bool TypedObject::is_exact_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is the indicated type exactly.

Definition at line 101 of file typedObject.I.

Referenced by PT(), and CollisionNode::xform().

bool TypedObject::is_of_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is or derives from the indicated type.

Definition at line 86 of file typedObject.I.

Referenced by EggMaterialCollection::collapse_equivalent_materials(), EggTextureCollection::collapse_equivalent_textures(), DeferredNodeProperty::compose(), AnimBundleMaker::create_s_channel(), CharacterMaker::create_slider(), ProjectionScreen::cull_callback(), DataNode::define_output(), EggNode::determine_draw_order(), CharacterMaker::egg_to_index(), EggGroupUniquifier::EggGroupUniquifier(), EggPoolUniquifier::EggPoolUniquifier(), EggGroupNode::find_textures(), StaticTextFont::get_glyph(), EggMaterialCollection::insert_materials(), EggTextureCollection::insert_textures(), CharacterJoint::make_copy(), PT(), EggGroupNode::r_flatten_transforms(), EggGroupNode::r_transform_vertices(), EggGroupNode::recompute_polygon_normals(), CollisionLevelState::reserve(), PandaFramework::reset_frame_rate(), PandaFramework::set_texture(), EggGroupNode::steal_children(), and DataGraphTraverser::traverse().

bool Datagram::operator!= const Datagram &  other  )  const [inline]
 

Definition at line 534 of file datagram.I.

bool Datagram::operator< const Datagram &  other  )  const [inline]
 

Definition at line 546 of file datagram.I.

void Datagram::operator= const Datagram &  copy  )  [inline]
 

Reimplemented in NetDatagram.

Definition at line 81 of file datagram.I.

References append_data(), and INLINE.

Referenced by NetDatagram::NetDatagram().

bool Datagram::operator== const Datagram &  other  )  const [inline]
 

Definition at line 516 of file datagram.I.

Referenced by add_z_string().

void Datagram::pad_bytes size_t  size  ) 
 

Adds the indicated number of zero bytes to the datagram.

Definition at line 112 of file datagram.cxx.

References _data, and PointerToArray< unsigned char >::push_back().

Referenced by add_be_uint64().


Member Data Documentation

PTA_uchar Datagram::_data [private]
 

Definition at line 120 of file datagram.h.

Referenced by add_be_float64(), add_string(), append_data(), pad_bytes(), and ~Datagram().

TypeHandle Datagram::_type_handle [static, private]
 

Reimplemented from TypedObject.

Reimplemented in NetDatagram.

Definition at line 30 of file datagram.cxx.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:49:10 2003 for Panda by doxygen1.3