2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Envelope.h
|
|
|
|
|
*
|
|
|
|
|
* When you send or receive a message to the rabbitMQ server, it is encapsulated
|
|
|
|
|
* in an envelope that contains additional meta information as well.
|
|
|
|
|
*
|
|
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
class Envelope : public MetaData
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
2014-01-06 01:50:41 +08:00
|
|
|
protected:
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Pointer to the body data (the memory buffer is not managed by the AMQP
|
|
|
|
|
* library!)
|
|
|
|
|
* @var const char *
|
|
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
const char *_body;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Size of the data
|
2014-01-05 20:08:35 +08:00
|
|
|
* @var uint64_t
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-06 01:50:41 +08:00
|
|
|
uint64_t _bodySize;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* The data buffer that you pass to this constructor must be valid during
|
|
|
|
|
* the lifetime of the Envelope object.
|
|
|
|
|
*
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param body
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param size
|
|
|
|
|
*/
|
2014-01-06 01:50:41 +08:00
|
|
|
Envelope(const char *body, uint64_t size) : MetaData(), _body(body), _bodySize(size) {}
|
2014-01-05 04:01:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor based on a string
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param body
|
2014-01-05 04:01:02 +08:00
|
|
|
*/
|
2014-01-06 01:50:41 +08:00
|
|
|
Envelope(const std::string &body) : MetaData(), _body(body.data()), _bodySize(body.size()) {}
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Envelope() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Access to the full message data
|
|
|
|
|
* @return buffer
|
|
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
const char *body() const
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
2014-01-05 20:08:35 +08:00
|
|
|
return _body;
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Size of the body
|
2014-01-05 20:08:35 +08:00
|
|
|
* @return uint64_t
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
uint64_t bodySize() const
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
2014-01-06 01:50:41 +08:00
|
|
|
return _bodySize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Body as a string
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
std::string message() const
|
|
|
|
|
{
|
|
|
|
|
return std::string(_body, _bodySize);
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|