A SimpleMessage wraps a byte array which it may or may not own. More...
#include <message.h>

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_ |
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.
Definition at line 19 of file message.h.
| Dv::Net::SimpleMessage::SimpleMessage | ( | const char * | data = 0, |
|
| size_t | size = 0 | |||
| ) | [inline] |
| virtual Dv::Net::SimpleMessage::~SimpleMessage | ( | ) | [inline, virtual] |
| const char* Dv::Net::SimpleMessage::data | ( | ) | const [inline] |
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] |
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.
| os | stream to send to. |
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.
| is | stream to receive data from. |
| runtime_error | upon any error |
| const char* Dv::Net::SimpleMessage::data | ( | const char * | p, | |
| size_t | size | |||
| ) | [protected] |
Replace underlying byte array.
| p | new byte array | |
| size | of 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.
| size | of new byte array |
const char* Dv::Net::SimpleMessage::data_ [private] |
Definition at line 79 of file message.h.
Referenced by data(), and ~SimpleMessage().
size_t Dv::Net::SimpleMessage::size_ [private] |
bool Dv::Net::SimpleMessage::owner_ [private] |
Definition at line 81 of file message.h.
Referenced by ~SimpleMessage().
| dvnet-0.9.24 | [ 5 December, 2009] |