Panda3D
Public Member Functions | Static Public Member Functions

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 MemoryBase 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 Datagram &copy)
 Datagram (const string &data)
 Constructs a datagram from an existing block of data.
void add_be_float32 (PN_float32 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_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_bool (bool value)
 Adds a boolean value to the datagram.
void add_fixed_string (const string &str, size_t size)
 Adds a fixed-length string to the datagram.
void add_float32 (PN_float32 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_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_int8 (PN_int8 value)
 Adds a signed 8-bit integer to the datagram.
void add_stdfloat (PN_stdfloat value)
 Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_string (const string &str)
 Adds a variable-length string to the datagram.
void add_string32 (const string &str)
 Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings.
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_uint8 (PN_uint8 value)
 Adds an unsigned 8-bit integer to the datagram.
void add_wstring (const wstring &str)
 Adds a variable-length wstring to the datagram.
void add_z_string (string str)
 Adds a variable-length string to the datagram, as a NULL-terminated string.
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.
void assign (const void *data, size_t size)
 Replaces the datagram's data with the indicated block.
virtual void clear ()
 Resets the datagram to empty, in preparation for building up a new datagram.
void copy_array (CPTA_uchar data)
 Replaces the data in the Datagram with a copy of the data in the indicated CPTA_uchar.
void dump_hex (ostream &out, unsigned int indent=0) const
 Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.
virtual TypeHandle force_init_type ()
CPTA_uchar get_array () const
 Returns a const pointer to the actual data in the Datagram.
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.
string get_message () const
 Returns the datagram's data as a string.
bool get_stdfloat_double () const
 Returns the stdfloat_double flag.
virtual TypeHandle get_type () const
PTA_uchar modify_array ()
 Returns a modifiable pointer to the actual data in the Datagram.
bool operator!= (const Datagram &other) const
bool operator< (const Datagram &other) const
void operator= (const Datagram &copy)
bool operator== (const Datagram &other) const
void output (ostream &out) const
 Write a string representation of this instance to <out>.
void pad_bytes (size_t size)
 Adds the indicated number of zero bytes to the datagram.
void set_array (PTA_uchar data)
 Replaces the data in the Datagram with the data in the indicated PTA_uchar.
void set_stdfloat_double (bool stdfloat_double)
 Changes the stdfloat_double flag, which defines the operation performed by add_stdfloat() and DatagramIterator::get_stdfloat().
void write (ostream &out, unsigned int indent=0) const
 Write a string representation of this instance to <out>.

Static Public Member Functions

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

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 43 of file datagram.h.


Constructor & Destructor Documentation

Datagram::Datagram ( ) [inline]

Constructs an empty datagram.

Definition at line 21 of file datagram.I.

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

Constructs a datagram from an existing block of data.

Definition at line 36 of file datagram.I.

References append_data().

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

Constructs a datagram from an existing block of data.

Definition at line 52 of file datagram.I.

References append_data().


Member Function Documentation

void Datagram::add_be_float32 ( PN_float32  value) [inline]
void Datagram::add_be_float64 ( PN_float64  value) [inline]
void Datagram::add_be_int16 ( PN_int16  value) [inline]
void Datagram::add_be_int32 ( PN_int32  value) [inline]
void Datagram::add_be_int64 ( PN_int64  value) [inline]

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

Definition at line 252 of file datagram.I.

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

void Datagram::add_be_uint16 ( PN_uint16  value) [inline]

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

Definition at line 264 of file datagram.I.

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

Referenced by FltVertex::build_record(), FltMeshPrimitive::build_record(), and FltGeometry::build_record().

void Datagram::add_be_uint32 ( PN_uint32  value) [inline]
void Datagram::add_be_uint64 ( PN_uint64  value) [inline]

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

Definition at line 288 of file datagram.I.

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

void Datagram::add_bool ( bool  value) [inline]
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 377 of file datagram.I.

References append_data(), and pad_bytes().

Referenced by FltMaterial::build_14_record(), FltTexture::build_record(), FltMaterial::build_record(), FltLightSourceDefinition::build_record(), FltHeader::build_record(), FltExternalReference::build_record(), and FltBeadID::build_record().

void Datagram::add_float32 ( PN_float32  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 190 of file datagram.I.

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

Referenced by add_stdfloat(), PStatFrameData::write_datagram(), and PStatCollectorDef::write_datagram().

void Datagram::add_float64 ( PN_float64  value) [inline]
void Datagram::add_int16 ( PN_int16  value) [inline]
void Datagram::add_int32 ( PN_int32  value) [inline]
void Datagram::add_int64 ( PN_int64  value) [inline]

Adds a signed 64-bit integer to the datagram.

Definition at line 143 of file datagram.I.

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

void Datagram::add_int8 ( PN_int8  value) [inline]
void Datagram::add_stdfloat ( PN_stdfloat  value) [inline]
void Datagram::add_string ( const string &  str) [inline]
void Datagram::add_string32 ( const string &  str) [inline]

Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings.

Definition at line 342 of file datagram.I.

References add_uint32(), and append_data().

void Datagram::add_uint16 ( PN_uint16  value) [inline]

Adds an unsigned 16-bit integer to the datagram.

Definition at line 154 of file datagram.I.

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

Referenced by add_string(), add_wstring(), DatagramTCPHeader::DatagramTCPHeader(), DatagramUDPHeader::DatagramUDPHeader(), PStatServerControlMessage::encode(), PStatClientControlMessage::encode(), BamWriter::init(), CConnectionRepository::send_message_bundle(), RecorderTable::write_datagram(), TimedCycle::write_datagram(), BamCacheRecord::write_datagram(), PStatFrameData::write_datagram(), TextureAttrib::write_datagram(), TexProjectorEffect::write_datagram(), TexMatrixAttrib::write_datagram(), TexGenAttrib::write_datagram(), ScissorEffect::write_datagram(), RenderState::write_datagram(), RenderEffects::write_datagram(), PortalNode::write_datagram(), OccluderNode::write_datagram(), OccluderEffect::write_datagram(), ModelNode::write_datagram(), LightAttrib::write_datagram(), CompassEffect::write_datagram(), ClipPlaneAttrib::write_datagram(), AntialiasAttrib::write_datagram(), TransformTable::write_datagram(), TransformBlendTable::write_datagram(), TransformBlend::write_datagram(), SliderTable::write_datagram(), Lens::CData::write_datagram(), GeomVertexFormat::write_datagram(), GeomVertexColumn::write_datagram(), GeomVertexArrayFormat::write_datagram(), GeomVertexAnimationSpec::write_datagram(), ButtonEventList::write_datagram(), ButtonEvent::write_datagram(), DataNodeTransmit::write_datagram(), CollisionPolygon::write_datagram(), CollisionNode::write_datagram(), CollisionFloorMesh::write_datagram(), CollisionBox::write_datagram(), CharacterJoint::write_datagram(), Character::write_datagram(), PartGroup::write_datagram(), PartBundleNode::write_datagram(), AnimPreloadTable::write_datagram(), AnimGroup::write_datagram(), AnimChannelScalarTable::write_datagram(), AnimChannelMatrixXfmTable::write_datagram(), AnimChannelBase::write_datagram(), AnimBundle::write_datagram(), and BamWriter::write_handle().

void Datagram::add_uint32 ( PN_uint32  value) [inline]
void Datagram::add_uint64 ( PN_uint64  value) [inline]

Adds an unsigned 64-bit integer to the datagram.

Definition at line 176 of file datagram.I.

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

Referenced by CConnectionRepository::send_message_bundle(), and BamCacheRecord::write_datagram().

void Datagram::add_uint8 ( PN_uint8  value) [inline]
void Datagram::add_wstring ( const wstring &  str)

Adds a variable-length wstring to the datagram.

Definition at line 92 of file datagram.cxx.

References add_uint16(), and add_uint32().

void Datagram::add_z_string ( string  str) [inline]

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

Definition at line 357 of file datagram.I.

References add_uint8(), and append_data().

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

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

Definition at line 394 of file datagram.I.

References append_data().

void Datagram::append_data ( const void *  data,
size_t  size 
)
void Datagram::assign ( const void *  data,
size_t  size 
)

Replaces the datagram's data with the indicated block.

Definition at line 178 of file datagram.cxx.

void Datagram::clear ( ) [virtual]

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

Reimplemented in NetDatagram.

Definition at line 41 of file datagram.cxx.

Referenced by FltRecordWriter::advance(), PStatServerControlMessage::encode(), PStatClientControlMessage::encode(), and DatagramInputFile::get_datagram().

void Datagram::copy_array ( CPTA_uchar  data) [inline]

Replaces the data in the Datagram with a copy of the data in the indicated CPTA_uchar.

Unlike set_array(), a complete copy is made of the data; subsequent changes to the Datagram will *not* change the source CPTA_uchar.

Definition at line 457 of file datagram.I.

References ConstPointerToArray< Element >::v().

void Datagram::dump_hex ( ostream &  out,
unsigned int  indent = 0 
) const

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

Definition at line 52 of file datagram.cxx.

References get_data(), and get_length().

Referenced by GeomVertexData::describe_vertex(), Buffered_DatagramConnection::SendMessage(), DatagramIterator::skip_bytes(), DatagramTCPHeader::verify_datagram(), DatagramUDPHeader::verify_datagram(), and write().

CPTA_uchar Datagram::get_array ( ) const [inline]

Returns a const pointer to the actual data in the Datagram.

Definition at line 469 of file datagram.I.

const void * Datagram::get_data ( ) const [inline]
size_t Datagram::get_length ( ) const [inline]
string Datagram::get_message ( ) const [inline]
bool Datagram::get_stdfloat_double ( ) const [inline]

Returns the stdfloat_double flag.

See set_stdfloat_double().

Definition at line 507 of file datagram.I.

Referenced by DatagramIterator::get_stdfloat().

static void Datagram::init_type ( ) [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 121 of file datagram.h.

References TypedObject::init_type().

Referenced by NetDatagram::init_type().

PTA_uchar Datagram::modify_array ( ) [inline]

Returns a modifiable pointer to the actual data in the Datagram.

Definition at line 480 of file datagram.I.

void Datagram::output ( ostream &  out) const

Write a string representation of this instance to <out>.

Definition at line 193 of file datagram.cxx.

void Datagram::pad_bytes ( size_t  size)
void Datagram::set_array ( PTA_uchar  data) [inline]

Replaces the data in the Datagram with the data in the indicated PTA_uchar.

This is assignment by reference: subsequent changes to the Datagram will also change the source PTA_uchar.

Definition at line 443 of file datagram.I.

void Datagram::set_stdfloat_double ( bool  stdfloat_double) [inline]

Changes the stdfloat_double flag, which defines the operation performed by add_stdfloat() and DatagramIterator::get_stdfloat().

When this is true, add_stdfloat() adds a 64-bit floating-point number; when it is false, it adds a 32-bit floating-point number. The default is based on the STDFLOAT_DOUBLE compilation flag.

Definition at line 496 of file datagram.I.

void Datagram::write ( ostream &  out,
unsigned int  indent = 0 
) const

Write a string representation of this instance to <out>.

Definition at line 206 of file datagram.cxx.

References dump_hex().

Referenced by DatagramIterator::write().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations