ability to store and retrieve envelopes
This commit is contained in:
parent
5d95ba824f
commit
96a6fa9a5c
|
|
@ -4,7 +4,7 @@
|
|||
* 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 - 2017 Copernica BV
|
||||
* @copyright 2014 - 2020 Copernica BV
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -24,6 +24,10 @@ namespace AMQP {
|
|||
|
||||
/**
|
||||
* Class definition
|
||||
* The envelope extends from MetaData, although this is conceptually not entirely
|
||||
* correct: and envelope _holds_ meta data and a body, so it would have been more
|
||||
* correct to make the MetaData instance a member. But by extending we automatically
|
||||
* make all meta-data properties accesible.
|
||||
*/
|
||||
class Envelope : public MetaData
|
||||
{
|
||||
|
|
@ -43,18 +47,29 @@ protected:
|
|||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* The data buffer that you pass to this constructor must be valid during
|
||||
* the lifetime of the Envelope object.
|
||||
*
|
||||
* @param body
|
||||
* @param size
|
||||
*/
|
||||
Envelope(const char *body, uint64_t size) : MetaData(), _body(body), _bodySize(size) {}
|
||||
|
||||
/**
|
||||
* Read envelope frmo an input-buffer
|
||||
* This method is the counterpart of the Envelope::fill() method, and is not used
|
||||
* by the library itself, but might be useful for applications that want to store
|
||||
* envelopes.
|
||||
* @param frame
|
||||
*/
|
||||
Envelope(InBuffer &buffer) : MetaData(buffer)
|
||||
{
|
||||
// extract the properties
|
||||
_bodySize = buffer.nextUint64();
|
||||
_body = buffer.nextData(_bodySize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled copy constructor
|
||||
*
|
||||
* @param envelope the envelope to copy
|
||||
*/
|
||||
Envelope(const Envelope &envelope) = delete;
|
||||
|
|
@ -81,6 +96,34 @@ public:
|
|||
{
|
||||
return _bodySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of the envelope, this is the size of the meta+data plus the number of bytes
|
||||
* required to store the size of the body + the actual body. This method is not used
|
||||
* by the AMQP-CPP library, but could be useful if you feel the need to store
|
||||
* @return size_t
|
||||
*/
|
||||
size_t size() const
|
||||
{
|
||||
// this is the size of the meta-data + the size of the body
|
||||
return MetaData::size() + _bodySize + sizeof(uint64_t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill an output buffer
|
||||
* This method is not used by this library, but could be useful if you want to store
|
||||
* the meta-data + message contents (
|
||||
* @param buffer
|
||||
*/
|
||||
void fill(OutBuffer &buffer) const
|
||||
{
|
||||
// first we store the meta-data
|
||||
MetaData::fill(buffer);
|
||||
|
||||
// now the size of the message body + the actual body
|
||||
buffer.add(_bodySize);
|
||||
buffer.add(_body, _bodySize);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue