Dv::Net::SimpleMessage Class Reference

A SimpleMessage wraps a byte array which it may or may not own. More...

#include <message.h>

Inheritance diagram for Dv::Net::SimpleMessage:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 SimpleMessage (const char *data=0, size_t size=0)
 Constructor.
virtual ~SimpleMessage ()
 Destructor.
const char * data () const
size_t size () const
std::ostream & send (std::ostream &os) const
 Send data byte-array.
std::istream & receive (std::istream &is) throw (std::runtime_error)
 Receive data byte-array sent by Dv::Net::SimpleMessage::send.

Protected Member Functions

const char * data (const char *p, size_t size)
 Replace underlying byte array.
char * data (size_t size)
 Replace byte array by a newly allocated array of size bytes.

Private Attributes

const char * data_
size_t size_
bool owner_

Detailed Description

A SimpleMessage wraps a byte array which it may or may not own.

A SimpleMessage can be sent to a stream and it can received from a stream. The protocol ensures that any byte array can be transferred.

Deprecated:
This class uses the deprecated [io]strstream classes, it should be rewritten to use std::[io]stringstream.

Definition at line 19 of file message.h.


Constructor & Destructor Documentation

Dv::Net::SimpleMessage::SimpleMessage ( const char *  data = 0,
size_t  size = 0 
) [inline]

Constructor.

Parameters:
data pointer to byte array.
size of byte array
Warning:
The array will not be copied and the message will not be its owner.

Definition at line 27 of file message.h.

virtual Dv::Net::SimpleMessage::~SimpleMessage (  )  [inline, virtual]

Destructor.

Delete the data if we are the owner.

Definition at line 31 of file message.h.

References data_, and owner_.


Member Function Documentation

const char* Dv::Net::SimpleMessage::data (  )  const [inline]
Returns:
pointer to data char array
Warning:
this is not a C string
See also:
Dv::Net::SimpleMessage::size

Definition at line 39 of file message.h.

References data_.

Referenced by Dv::Net::Message< std::string >::Message(), Dv::Net::Message< T >::Message(), Dv::Net::Message< std::string >::operator std::string(), and Dv::Net::Message< T >::operator T().

size_t Dv::Net::SimpleMessage::size (  )  const [inline]
Returns:
size of data array

Definition at line 41 of file message.h.

References size_.

Referenced by Dv::Net::Message< std::string >::operator std::string(), and Dv::Net::Message< T >::operator T().

std::ostream& Dv::Net::SimpleMessage::send ( std::ostream &  os  )  const

Send data byte-array.

The following protocol is used:

 size-of-encoded-byte-array <newline> encoded-byte-array

Test stream status to find out whether the operation succeeded.

Parameters:
os stream to send to.
Returns:
os
See also:
Dv::Net::SimpleMessage::receive

Referenced by operator<<().

std::istream& Dv::Net::SimpleMessage::receive ( std::istream &  is  )  throw (std::runtime_error)

Receive data byte-array sent by Dv::Net::SimpleMessage::send.

Parameters:
is stream to receive data from.
Returns:
is
See also:
SimpleMessage::send
Exceptions:
runtime_error upon any error
Warning:
the message will become the owner of the byte array.
const char* Dv::Net::SimpleMessage::data ( const char *  p,
size_t  size 
) [protected]

Replace underlying byte array.

Parameters:
p new byte array
size of new byte array
Returns:
p
Warning:
the message will not be the owner of the new byte array.
char* Dv::Net::SimpleMessage::data ( size_t  size  )  [protected]

Replace byte array by a newly allocated array of size bytes.

Note that the returned pointer is not const, so a derived class can update the byte array.

Parameters:
size of new byte array
Returns:
pointer to newly allocated byte array.
Warning:
The message owns the new byte array, so the derived class should not delete it.

Member Data Documentation

const char* Dv::Net::SimpleMessage::data_ [private]

Definition at line 79 of file message.h.

Referenced by data(), and ~SimpleMessage().

Definition at line 80 of file message.h.

Referenced by size().

Definition at line 81 of file message.h.

Referenced by ~SimpleMessage().


The documentation for this class was generated from the following file:

dvnet-0.9.24 [ 5 December, 2009]