1 /**
2  *  Class describing an AMQP method frame
3  *
4  *  @copyright 2014 Copernica BV
5  */
6 
7 /**
8  *  Include guard
9  */
10 #pragma once
11 
12 /**
13  *  Dependencies
14  */
15 #include "extframe.h"
16 
17 /**
18  *  Set up namespace
19  */
20 namespace AMQP {
21 
22 /**
23  *  Class implementation
24  */
25 class MethodFrame : public ExtFrame
26 {
27 protected:
28     /**
29      *  Constructor for a methodFrame
30      *
31      *  @param  channel     channel we're working on
32      *  @param  size        size of the frame.
33      */
MethodFrame(uint16_t channel,uint32_t size)34     MethodFrame(uint16_t channel, uint32_t size) : ExtFrame(channel, size + 4) {} // size of classID and methodID
35 
36     /**
37      *  Load a method from from a received frame
38      *  @param  frame       The received frame
39      */
MethodFrame(ReceivedFrame & frame)40     MethodFrame(ReceivedFrame &frame) : ExtFrame(frame) {}
41 
42     /**
43      *  Fill an output buffer
44      *  @param  buffer
45      */
fill(OutBuffer & buffer)46     virtual void fill(OutBuffer &buffer) const override
47     {
48         // call base
49         ExtFrame::fill(buffer);
50 
51         // add type
52         buffer.add(classID());
53         buffer.add(methodID());
54     }
55 
56 public:
57     /**
58      *  Destructor
59      */
~MethodFrame()60     virtual ~MethodFrame() {}
61 
62     /**
63      *  Is this a synchronous frame?
64      *
65      *  After a synchronous frame no more frames may be
66      *  sent until the accompanying -ok frame arrives
67      */
synchronous()68     bool synchronous() const override { return true; }
69 
70     /**
71      *  Get the message type
72      *  @return uint8_t
73      */
type()74     virtual uint8_t type() const override
75     {
76         return 1;
77     }
78 
79     /**
80      *  Class id
81      *  @return uint16_t
82      */
83     virtual uint16_t classID() const = 0;
84 
85     /**
86      *  Method id
87      *  @return uint16_t
88      */
89     virtual uint16_t methodID() const = 0;
90 
91     /**
92      *  Process the frame
93      *  @param  connection      The connection over which it was received
94      *  @return bool            Was it succesfully processed?
95      */
process(ConnectionImpl * connection)96     virtual bool process(ConnectionImpl *connection) override
97     {
98         // this is an exception
99         throw ProtocolException("unimplemented frame type " + std::to_string(type()) + " class " + std::to_string(classID()) + " method " + std::to_string(methodID()));
100     }
101 };
102 
103 /**
104  *  end namespace
105  */
106 }
107 
108