2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Class describing an AMQP Body Frame
|
2015-04-30 20:18:18 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dependencies
|
|
|
|
|
*/
|
|
|
|
|
#include "extframe.h"
|
|
|
|
|
#include "../include/connectionimpl.h"
|
|
|
|
|
#include "../include/deferredconsumerbase.h"
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class implementation
|
2015-04-30 20:18:18 +08:00
|
|
|
*/
|
2014-01-04 19:45:04 +08:00
|
|
|
class BodyFrame : public ExtFrame
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* Payload of the frame
|
|
|
|
|
* Payload can be any number of octets
|
2014-01-05 20:08:35 +08:00
|
|
|
* @var const char *
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
const char *_payload;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* Encode a body frame to a string buffer
|
|
|
|
|
*
|
|
|
|
|
* @param buffer buffer to write frame to
|
|
|
|
|
*/
|
|
|
|
|
virtual void fill(OutBuffer& buffer) const override
|
|
|
|
|
{
|
|
|
|
|
// call base
|
|
|
|
|
ExtFrame::fill(buffer);
|
|
|
|
|
|
|
|
|
|
// add payload to buffer
|
2014-01-05 20:08:35 +08:00
|
|
|
buffer.add(_payload, _size);
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct a body frame
|
|
|
|
|
*
|
|
|
|
|
* @param channel channel identifier
|
|
|
|
|
* @param payload payload of the body
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param size size of the payload
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
BodyFrame(uint16_t channel, const char *payload, uint32_t size) :
|
|
|
|
|
ExtFrame(channel, size),
|
2015-04-30 20:18:18 +08:00
|
|
|
_payload(payload)
|
2014-01-04 19:45:04 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor for incoming data
|
|
|
|
|
*
|
|
|
|
|
* @param frame received frame to decode
|
|
|
|
|
* @return shared pointer to newly created frame
|
|
|
|
|
*/
|
2015-04-30 20:18:18 +08:00
|
|
|
BodyFrame(ReceivedFrame& frame) :
|
|
|
|
|
ExtFrame(frame),
|
|
|
|
|
_payload(frame.nextData(frame.payloadSize()))
|
2014-01-04 19:45:04 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~BodyFrame() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the type of frame
|
|
|
|
|
* @return uint8_t
|
2015-04-30 20:18:18 +08:00
|
|
|
*/
|
2015-11-28 18:38:15 +08:00
|
|
|
virtual uint8_t type() const override
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the payload of the body
|
2014-01-05 20:08:35 +08:00
|
|
|
* @return const char *
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-05 20:08:35 +08:00
|
|
|
const char *payload() const
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _payload;
|
|
|
|
|
}
|
2015-04-30 20:18:18 +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());
|
2015-04-30 20:18:18 +08:00
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
// check if we have a valid channel and consumer
|
|
|
|
|
if (!channel || !channel->consumer()) return false;
|
2015-04-30 20:18:18 +08:00
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
// the consumer may process the frame
|
|
|
|
|
channel->consumer()->process(*this);
|
2015-04-30 20:18:18 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
// done
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-04-30 20:18:18 +08:00
|
|
|
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* end namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|