Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::BinaryMessage Class Reference
[Network]

Little-, Big endian independent message buffer. More...

#include <OSGBinaryMessage.h>

Inheritance diagram for osg::BinaryMessage:

osg::NetworkMessage List of all members.

Public Types

typedef std::vector< UInt8BufferType

Public Member Functions

Constructors
BinaryMessage (void)
 BinaryMessage (const BinaryMessage &source)
Destructor
*virtual ~BinaryMessage (void)
Get
*virtual UInt32 getSize (void)
virtual MemoryHandle getBuffer (void)
Misc
*virtual void setSize (UInt32 size)
void clear (void)
void reset (void)
write message
*void putUInt32 (const UInt32 value)
void putInt32 (const Int32 value)
void putUInt16 (const UInt16 value)
void putInt16 (const Int16 value)
void putUInt8 (const UInt8 value)
void putInt8 (const Int8 value)
void putString (const std::string &value)
void putReal32 (const Real32 value)
read message
*void getUInt32 (UInt32 &value)
void getInt32 (Int32 &value)
void getUInt16 (UInt16 &value)
void getInt16 (Int16 &value)
void getUInt8 (UInt8 &value)
void getInt8 (Int8 &value)
void getString (std::string &value)
void getReal32 (Real32 &value)
UInt32 getUInt32 (void)
Int32 getInt32 (void)
UInt16 getUInt16 (void)
Int16 getInt16 (void)
UInt8 getUInt8 (void)
Int8 getInt8 (void)
std::string getString (void)
Real32 getReal32 (void)
Assignment
*BinaryMessageoperator= (const BinaryMessage &source)
Get
Header & getHeader (void)

Protected Attributes

Member
*BufferType _buffer
UInt32 _pos

Private Types

typedef NetworkMessage Inherited

Detailed Description

Little-, Big endian independent message buffer.

Example:

 
 // send
 BinSockMessage msg;
 msg.clear();              // if not already empty
 msg.putUInt32(220);
 msg.putInt32 (221);
 msg.putUInt16(222);
 msg.putInt16 (223);
 msg.putUInt8 (224);
 msg.putInt8  (225);
 msg.putReal32(226.0);
 msg.putString("227");
 socket.send(msg);
 // receive
 string str;
 socket.recv(msg);
 str = msg.getString();
 msg.getString(str);        // avoid one copy
 

Definition at line 53 of file OSGBinaryMessage.h.


Member Typedef Documentation

typedef std::vector<UInt8> osg::BinaryMessage::BufferType
 

Definition at line 58 of file OSGBinaryMessage.h.

typedef NetworkMessage osg::BinaryMessage::Inherited [private]
 

Definition at line 150 of file OSGBinaryMessage.h.


Constructor & Destructor Documentation

BinaryMessage::BinaryMessage void   ) 
 

Constructor

Definition at line 86 of file OSGBinaryMessage.cpp.

References clear().

00086                                 :
00087     NetworkMessage(),
00088     _buffer(),
00089     _pos(sizeof(Header))
00090 {
00091     clear();
00092 }

BinaryMessage::BinaryMessage const BinaryMessage source  ) 
 

Copy constructor

Definition at line 96 of file OSGBinaryMessage.cpp.

00096                                                        :
00097     NetworkMessage(source),
00098     _buffer(source._buffer),
00099     _pos(source._pos)
00100 {
00101 }

BinaryMessage::~BinaryMessage void   )  [virtual]
 

Destructor

Definition at line 108 of file OSGBinaryMessage.cpp.

00109 {
00110 }


Member Function Documentation

UInt32 BinaryMessage::getSize void   )  [virtual]
 

Get message size in bytes

Implements osg::NetworkMessage.

Definition at line 166 of file OSGBinaryMessage.cpp.

References _buffer.

00167 {
00168     return _buffer.size();
00169 }

MemoryHandle BinaryMessage::getBuffer void   )  [virtual]
 

Get buffer address

Implements osg::NetworkMessage.

Definition at line 173 of file OSGBinaryMessage.cpp.

References _buffer.

00174 {
00175     if(_buffer.size())
00176         return static_cast<MemoryHandle>(&_buffer[0]);
00177     else
00178         return 0;
00179 }

void BinaryMessage::setSize UInt32  size  )  [virtual]
 

Set message size. This is called by the socket to get enough space to read a message.

Implements osg::NetworkMessage.

Definition at line 141 of file OSGBinaryMessage.cpp.

References _buffer, and reset().

00142 {
00143     _buffer.resize(size);
00144     reset();
00145 }

void BinaryMessage::clear void   ) 
 

Clear message buffer

Definition at line 149 of file OSGBinaryMessage.cpp.

References _buffer.

Referenced by osg::ClusterServer::acceptClient(), BinaryMessage(), osg::ClusterWindow::init(), osg::PointMCastConnection::initialize(), osg::GroupSockPipeline::initialize(), and osg::GroupMCastConnection::initialize().

00150 {
00151     _buffer.resize(sizeof(Header));
00152 }

void BinaryMessage::reset void   ) 
 

Reset readpointer to the beginn of the buffer

Definition at line 156 of file OSGBinaryMessage.cpp.

References _pos.

Referenced by setSize().

00157 {
00158     _pos=sizeof(Header);
00159 }

void osg::BinaryMessage::putUInt32 const UInt32  value  )  [inline]
 

Definition at line 47 of file OSGBinaryMessage.inl.

References _buffer, and osg::osghtonl().

Referenced by osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::GroupSockPipeline::initialize(), osg::GroupMCastConnection::initialize(), and putString().

00048 {
00049     Int32 net=osghtonl(value);
00050     _buffer.insert(_buffer.end(),(UInt8*)(&net),((UInt8*)(&net))+sizeof(net));
00051 }

void osg::BinaryMessage::putInt32 const Int32  value  )  [inline]
 

Definition at line 53 of file OSGBinaryMessage.inl.

References _buffer, and osg::osghtonl().

Referenced by putReal32().

00054 {
00055     Int32 net=osghtonl(value);
00056     _buffer.insert(_buffer.end(),(UInt8*)(&net),((UInt8*)(&net))+sizeof(net));
00057 }

void osg::BinaryMessage::putUInt16 const UInt16  value  )  [inline]
 

Definition at line 59 of file OSGBinaryMessage.inl.

References _buffer, and osg::osghtons().

00060 {
00061     Int16 net=osghtons(value);
00062     _buffer.insert(_buffer.end(),(UInt8*)(&net),((UInt8*)(&net))+sizeof(net));
00063 }

void osg::BinaryMessage::putInt16 const Int16  value  )  [inline]
 

Definition at line 65 of file OSGBinaryMessage.inl.

References _buffer, and osg::osghtons().

00066 {
00067     Int16 net=osghtons(value);
00068     _buffer.insert(_buffer.end(),(UInt8*)(&net),((UInt8*)(&net))+sizeof(net));
00069 }

void osg::BinaryMessage::putUInt8 const UInt8  value  )  [inline]
 

Definition at line 71 of file OSGBinaryMessage.inl.

References _buffer.

00072 {
00073     _buffer.push_back(value);
00074 }

void osg::BinaryMessage::putInt8 const Int8  value  )  [inline]
 

Definition at line 76 of file OSGBinaryMessage.inl.

References _buffer.

00077 {
00078     UInt8 v=static_cast<UInt8>(value);
00079     _buffer.push_back(v);
00080 }

void osg::BinaryMessage::putString const std::string &  value  )  [inline]
 

Definition at line 82 of file OSGBinaryMessage.inl.

References _buffer, and putUInt32().

Referenced by osg::ClusterServer::acceptClient(), osg::ClusterWindow::init(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::GroupSockPipeline::initialize(), and osg::GroupMCastConnection::initialize().

00083 {
00084     putUInt32(value.size());
00085     if(value.size())
00086     {
00087         const UInt8 *s=(const UInt8*)(value.c_str());
00088         const UInt8 *e=s+value.size();
00089         _buffer.insert(_buffer.end(),s,e);
00090     }
00091 }

void osg::BinaryMessage::putReal32 const Real32  value  )  [inline]
 

Definition at line 93 of file OSGBinaryMessage.inl.

References putInt32().

00094 {
00095     putInt32(*((const Int32*)(&value)));
00096 }

void osg::BinaryMessage::getUInt32 UInt32 value  )  [inline]
 

Definition at line 101 of file OSGBinaryMessage.inl.

References _buffer, _pos, and osg::osgntohl().

Referenced by osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::GroupSockPipeline::initialize(), and osg::GroupMCastConnection::initialize().

00102 {
00103     Int32 net;
00104     memcpy(&net,&_buffer[_pos],sizeof(net));
00105     value=osgntohl(net);
00106     _pos+=sizeof(net);
00107 }

void osg::BinaryMessage::getInt32 Int32 value  )  [inline]
 

Definition at line 109 of file OSGBinaryMessage.inl.

References _buffer, _pos, and osg::osgntohl().

00110 {
00111     Int32 net;
00112     memcpy(&net,&_buffer[_pos],sizeof(net));
00113     value=osgntohl(net);
00114     _pos+=sizeof(net);
00115 }

void osg::BinaryMessage::getUInt16 UInt16 value  )  [inline]
 

Definition at line 117 of file OSGBinaryMessage.inl.

References _buffer, _pos, and osg::osgntohs().

00118 {
00119     Int16 net=*((Int16 *)( &_buffer[_pos]));
00120     value=osgntohs(net);
00121     _pos+=sizeof(net);
00122 }

void osg::BinaryMessage::getInt16 Int16 value  )  [inline]
 

Definition at line 124 of file OSGBinaryMessage.inl.

References _buffer, _pos, and osg::osgntohs().

00125 {
00126     Int16 net=*((Int16 *)( &_buffer[_pos]));
00127     value=osgntohs(net);
00128     _pos+=sizeof(net);
00129 }

void osg::BinaryMessage::getUInt8 UInt8 value  )  [inline]
 

Definition at line 131 of file OSGBinaryMessage.inl.

References _buffer, and _pos.

00132 {
00133     value=_buffer[_pos++];
00134 }

void osg::BinaryMessage::getInt8 Int8 value  )  [inline]
 

Definition at line 136 of file OSGBinaryMessage.inl.

References _buffer, and _pos.

00137 {
00138     value=_buffer[_pos++];
00139 }

void osg::BinaryMessage::getString std::string &  value  )  [inline]
 

Definition at line 141 of file OSGBinaryMessage.inl.

References _buffer, _pos, and getUInt32().

Referenced by osg::ClusterServer::acceptClient(), osg::ClusterWindow::init(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::GroupSockPipeline::initialize(), and osg::GroupMCastConnection::initialize().

00142 {
00143     UInt32 size;
00144     getUInt32(size);
00145     if(!value.empty())
00146         value.erase();
00147     if(size)
00148     {
00149         value.insert(value.begin(),
00150                      (char*)&_buffer[_pos],
00151                      (char*)&_buffer[_pos+size]);
00152         _pos+=size;
00153     }
00154 }

void osg::BinaryMessage::getReal32 Real32 value  )  [inline]
 

Definition at line 156 of file OSGBinaryMessage.inl.

References getInt32().

00157 {
00158     getInt32(*((Int32*)(&value)));
00159 }

UInt32 osg::BinaryMessage::getUInt32 void   )  [inline]
 

Definition at line 161 of file OSGBinaryMessage.inl.

Referenced by getString().

00162 {
00163     UInt32 value;
00164     getUInt32(value);
00165     return value;
00166 }

Int32 osg::BinaryMessage::getInt32 void   )  [inline]
 

Definition at line 168 of file OSGBinaryMessage.inl.

Referenced by getReal32().

00169 {
00170     Int32 value;
00171     getInt32(value);
00172     return value;
00173 }

UInt16 osg::BinaryMessage::getUInt16 void   )  [inline]
 

Definition at line 175 of file OSGBinaryMessage.inl.

00176 {
00177     UInt16 value;
00178     getUInt16(value);
00179     return value;
00180 }

Int16 osg::BinaryMessage::getInt16 void   )  [inline]
 

Definition at line 182 of file OSGBinaryMessage.inl.

00183 {
00184     Int16 value;
00185     getInt16(value);
00186     return value;
00187 }

UInt8 osg::BinaryMessage::getUInt8 void   )  [inline]
 

Definition at line 189 of file OSGBinaryMessage.inl.

00190 {
00191     UInt8 value;
00192     getUInt8(value);
00193     return value;
00194 }

Int8 osg::BinaryMessage::getInt8 void   )  [inline]
 

Definition at line 196 of file OSGBinaryMessage.inl.

00197 {
00198     Int8 value;
00199     getInt8(value);
00200     return value;
00201 }

std::string osg::BinaryMessage::getString void   )  [inline]
 

Definition at line 203 of file OSGBinaryMessage.inl.

00204 {
00205     std::string value;
00206     getString(value);
00207     return value;
00208 }

Real32 osg::BinaryMessage::getReal32 void   )  [inline]
 

Definition at line 210 of file OSGBinaryMessage.inl.

00211 {
00212     Real32 value;
00213     getReal32(value);
00214     return value;
00215 }

BinaryMessage & BinaryMessage::operator= const BinaryMessage source  ) 
 

assignment

Definition at line 117 of file OSGBinaryMessage.cpp.

References _buffer, and _pos.

00118 {
00119     if(this == &source)
00120         return *this;
00121 
00122     // copy parts inherited from parent
00123     *(static_cast<Inherited *>(this)) = source;
00124 
00125     // free mem alloced by members of 'this'
00126 
00127     // alloc new mem for members
00128 
00129     // copy
00130     _buffer=source._buffer;
00131     _pos   =source._pos;
00132     return *this;
00133 }

NetworkMessage::Header & NetworkMessage::getHeader void   )  [inherited]
 

Get message header. A pointer to the first byte of the message is returned

Definition at line 97 of file OSGNetworkMessage.cpp.

References osg::NetworkMessage::getBuffer().

Referenced by osg::Socket::send(), and osg::DgramSocket::sendTo().

00098 {
00099     return *((Header*)(getBuffer()));
00100 }


Member Data Documentation

* BufferType osg::BinaryMessage::_buffer [protected]
 

Definition at line 143 of file OSGBinaryMessage.h.

Referenced by clear(), getBuffer(), getInt16(), getInt32(), getInt8(), getSize(), getString(), getUInt16(), getUInt32(), getUInt8(), operator=(), putInt16(), putInt32(), putInt8(), putString(), putUInt16(), putUInt32(), putUInt8(), and setSize().

UInt32 osg::BinaryMessage::_pos [protected]
 

Definition at line 144 of file OSGBinaryMessage.h.

Referenced by getInt16(), getInt32(), getInt8(), getString(), getUInt16(), getUInt32(), getUInt8(), operator=(), and reset().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:12:50 2005 for OpenSG by  doxygen 1.4.3