2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* ReceivedFrame.h
|
|
|
|
|
*
|
|
|
|
|
* The received frame class is a wrapper around a data buffer, it tries to
|
|
|
|
|
* find out if the buffer is big enough to contain an entire frame, and
|
|
|
|
|
* it will try to recognize the frame type in the buffer
|
|
|
|
|
*
|
|
|
|
|
* This is a class that is used internally by the AMQP library. As a used
|
|
|
|
|
* of this library, you normally do not have to instantiate it.
|
|
|
|
|
*
|
|
|
|
|
* @documentation public
|
|
|
|
|
*/
|
|
|
|
|
|
2014-08-13 19:01:27 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
class ReceivedFrame
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The buffer we are reading from
|
2014-08-13 19:01:27 +08:00
|
|
|
* @var Buffer
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-08-13 19:01:27 +08:00
|
|
|
const Buffer &_buffer;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
2014-08-13 19:01:27 +08:00
|
|
|
* Number of bytes already processed
|
2014-01-04 19:45:04 +08:00
|
|
|
* @var uint32_t
|
|
|
|
|
*/
|
2014-08-13 19:01:27 +08:00
|
|
|
uint32_t _skip = 0;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Type of frame
|
|
|
|
|
* @var uint8_t
|
|
|
|
|
*/
|
|
|
|
|
uint8_t _type = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Channel identifier
|
|
|
|
|
* @var uint16_t
|
|
|
|
|
*/
|
|
|
|
|
uint16_t _channel = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The payload size
|
|
|
|
|
* @var uint32_t
|
|
|
|
|
*/
|
|
|
|
|
uint32_t _payloadSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a method frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processMethodFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a connection frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processConnectionFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a channel frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processChannelFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process an exchange frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processExchangeFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a queue frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processQueueFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a basic frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processBasicFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a transaction frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processTransactionFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process a header frame
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool processHeaderFrame(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param buffer Binary buffer
|
|
|
|
|
* @param max Max buffer size
|
|
|
|
|
*/
|
2014-08-13 19:01:27 +08:00
|
|
|
ReceivedFrame(const Buffer &buffer, uint32_t max);
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~ReceivedFrame() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this a complete frame?
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
bool complete() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the channel identifier
|
|
|
|
|
* @return uint16_t
|
|
|
|
|
*/
|
|
|
|
|
uint16_t channel() const
|
|
|
|
|
{
|
|
|
|
|
return _channel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Total size of the frame (headers + payload)
|
|
|
|
|
* @return uint32_t
|
|
|
|
|
*/
|
|
|
|
|
uint64_t totalSize() const
|
|
|
|
|
{
|
|
|
|
|
// payload size + size of headers and end of frame byte
|
|
|
|
|
return _payloadSize + 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The size of the payload
|
|
|
|
|
* @return uint32_t
|
|
|
|
|
*/
|
|
|
|
|
uint32_t payloadSize() const
|
|
|
|
|
{
|
|
|
|
|
return _payloadSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next uint8_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return uint8_t value read
|
|
|
|
|
*/
|
|
|
|
|
uint8_t nextUint8();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next int8_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return int8_t value read
|
|
|
|
|
*/
|
|
|
|
|
int8_t nextInt8();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next uint16_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return uint16_t value read
|
|
|
|
|
*/
|
|
|
|
|
uint16_t nextUint16();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next int16_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return int16_t value read
|
|
|
|
|
*/
|
|
|
|
|
int16_t nextInt16();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next uint32_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return uint32_t value read
|
|
|
|
|
*/
|
|
|
|
|
uint32_t nextUint32();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next int32_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return int32_t value read
|
|
|
|
|
*/
|
|
|
|
|
int32_t nextInt32();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next uint64_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return uint64_t value read
|
|
|
|
|
*/
|
|
|
|
|
uint64_t nextUint64();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next int64_t from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return int64_t value read
|
|
|
|
|
*/
|
|
|
|
|
int64_t nextInt64();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a float from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return float float read from buffer.
|
|
|
|
|
*/
|
|
|
|
|
float nextFloat();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a double from the buffer
|
|
|
|
|
*
|
|
|
|
|
* @return double double read from buffer
|
|
|
|
|
*/
|
|
|
|
|
double nextDouble();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a pointer to the next binary buffer of a certain size
|
|
|
|
|
* @param size
|
|
|
|
|
* @return char*
|
|
|
|
|
*/
|
|
|
|
|
const char *nextData(uint32_t size);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process the received frame
|
|
|
|
|
*
|
|
|
|
|
* If this method returns false, it means that the frame was not processed,
|
|
|
|
|
* because it was an unrecognized frame. This does not mean that the
|
|
|
|
|
* connection is now in an invalid state however.
|
|
|
|
|
*
|
|
|
|
|
* @param connection the connection over which the data was received
|
|
|
|
|
* @return bool was the frame fully processed
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
bool process(ConnectionImpl *connection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The checker may access private data
|
|
|
|
|
*/
|
|
|
|
|
friend class FrameCheck;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|