2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Class describing an AMQP basic header frame
|
2016-06-23 20:42:50 +08:00
|
|
|
*
|
2017-03-08 20:32:51 +08:00
|
|
|
* @copyright 2014 - 2017 Copernica BV
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
|
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dependencies
|
|
|
|
|
*/
|
|
|
|
|
#include "headerframe.h"
|
2018-01-24 08:58:18 +08:00
|
|
|
#include "amqpcpp/metadata.h"
|
|
|
|
|
#include "amqpcpp/envelope.h"
|
|
|
|
|
#include "amqpcpp/connectionimpl.h"
|
|
|
|
|
#include "amqpcpp/deferredconsumerbase.h"
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class implementation
|
|
|
|
|
*/
|
|
|
|
|
class BasicHeaderFrame : public HeaderFrame
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* Weight field, unused but must be sent, always value 0;
|
|
|
|
|
* @var uint16_t
|
|
|
|
|
*/
|
2014-02-12 15:27:07 +08:00
|
|
|
uint16_t _weight = 0;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Body size, sum of the sizes of all body frames following the content header
|
|
|
|
|
* @var uint64_t
|
|
|
|
|
*/
|
|
|
|
|
uint64_t _bodySize;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-01-05 20:08:35 +08:00
|
|
|
* The meta data
|
|
|
|
|
* @var MetaData
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
MetaData _metadata;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* Encode a header frame to a string buffer
|
|
|
|
|
*
|
|
|
|
|
* @param buffer buffer to write frame to
|
|
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
virtual void fill(OutBuffer &buffer) const override
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
// call base
|
|
|
|
|
HeaderFrame::fill(buffer);
|
|
|
|
|
|
|
|
|
|
// fill own fields.
|
|
|
|
|
buffer.add(_weight);
|
|
|
|
|
buffer.add(_bodySize);
|
|
|
|
|
|
2014-01-05 20:08:35 +08:00
|
|
|
// the meta data
|
|
|
|
|
_metadata.fill(buffer);
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct an empty basic header frame
|
|
|
|
|
*
|
|
|
|
|
* All options are set using setter functions.
|
2016-06-23 20:42:50 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param channel channel we're working on
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param envelope the envelope
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
BasicHeaderFrame(uint16_t channel, const Envelope &envelope) :
|
|
|
|
|
HeaderFrame(channel, 10 + envelope.size()), // there are at least 10 bytes sent, weight (2), bodySize (8), plus the size of the meta data
|
|
|
|
|
_bodySize(envelope.bodySize()),
|
|
|
|
|
_metadata(envelope)
|
2014-01-04 19:45:04 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor to parse incoming frame
|
|
|
|
|
* @param frame
|
|
|
|
|
*/
|
2016-06-23 20:42:50 +08:00
|
|
|
BasicHeaderFrame(ReceivedFrame &frame) :
|
2014-01-04 19:45:04 +08:00
|
|
|
HeaderFrame(frame),
|
|
|
|
|
_weight(frame.nextUint16()),
|
|
|
|
|
_bodySize(frame.nextUint64()),
|
2014-01-05 20:08:35 +08:00
|
|
|
_metadata(frame)
|
|
|
|
|
{}
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
2016-06-23 20:42:50 +08:00
|
|
|
virtual ~BasicHeaderFrame() = default;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Size of the body
|
|
|
|
|
* @return uint64_t
|
|
|
|
|
*/
|
|
|
|
|
uint64_t bodySize() const
|
|
|
|
|
{
|
|
|
|
|
return _bodySize;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
/**
|
|
|
|
|
* The metadata sent in this frame
|
|
|
|
|
*
|
|
|
|
|
* @return All the metadata for this message
|
|
|
|
|
*/
|
|
|
|
|
const MetaData &metaData() const
|
|
|
|
|
{
|
|
|
|
|
return _metadata;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* The class ID
|
|
|
|
|
* @return uint16_t
|
|
|
|
|
*/
|
|
|
|
|
virtual uint16_t classID() const override
|
|
|
|
|
{
|
|
|
|
|
return 60;
|
|
|
|
|
}
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Process the frame
|
|
|
|
|
* @param connection The connection over which it was received
|
|
|
|
|
* @return bool Was it succesfully processed?
|
|
|
|
|
*/
|
2014-01-06 04:21:09 +08:00
|
|
|
virtual bool process(ConnectionImpl *connection) override
|
2014-01-06 01:50:41 +08:00
|
|
|
{
|
|
|
|
|
// we need the appropriate channel
|
2014-08-20 17:47:16 +08:00
|
|
|
auto channel = connection->channel(this->channel());
|
2016-06-23 20:42:50 +08:00
|
|
|
|
|
|
|
|
// check if we have a valid channel and consumer
|
|
|
|
|
if (!channel || !channel->consumer()) return false;
|
|
|
|
|
|
|
|
|
|
// the channel can process the frame
|
|
|
|
|
channel->consumer()->process(*this);
|
|
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
// done
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-01-04 19:45:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|