acl  3.5.3.0
mqtt_suback.hpp
浏览该文件的文档.
1 #pragma once
2 
3 #include <vector>
4 #include "mqtt_message.hpp"
5 
6 namespace acl {
7 
8 /**
9  * mqtt message object for MQTT_SUBACK type.
10  */
12 public:
13  /**
14  * constructor for creating MQTT_SUBACK mqtt message object.
15  * @see mqtt_ack
16  */
17  mqtt_suback(void);
18 
19  /**
20  * constructor for creating MQTT_SUBACK mqtt message object.
21  * @see mqtt_ack
22  */
23  mqtt_suback(const mqtt_header& header);
24 
25  ~mqtt_suback(void);
26 
27  /**
28  * set the messsage's id.
29  * @param id {unsigned short} should > 0 && <= 65535.
30  * @return {mqtt_suback&}
31  */
32  mqtt_suback& set_pkt_id(unsigned short id);
33 
34  /**
35  * add the topic's qos.
36  * @param qos {mqtt_qos_t}
37  * @return {mqtt_suback&}
38  */
39  mqtt_suback& add_topic_qos(mqtt_qos_t qos);
40 
41  /**
42  * add some qoses of topics.
43  * @param qoses {const std::vector<mqtt_qos_t>&}
44  * @return {mqtt_suback&}
45  */
46  mqtt_suback& add_topic_qos(const std::vector<mqtt_qos_t>& qoses);
47 
48  /**
49  * get the messsage's id.
50  * @return {unsigned short} some error happened if return 0.
51  */
52  unsigned short get_pkt_id(void) const {
53  return pkt_id_;
54  }
55 
56  /**
57  * get all qoses of the topics.
58  * @return {const std::vector<mqtt_qos_t>&}
59  */
60  const std::vector<mqtt_qos_t>& get_qoses(void) const {
61  return qoses_;
62  }
63 
64 protected:
65  // @override
66  bool to_string(string& out);
67 
68  // @override
69  int update(const char* data, int dlen);
70 
71  // @override
72  bool finished(void) const {
73  return finished_;
74  }
75 
76 public:
77  // use internal to parse suback message in streaming mode.
78 
79  int update_header_var(const char* data, int dlen);
80  int update_topic_qos(const char* data, int dlen);
81 
82 private:
83  unsigned status_;
84  bool finished_;
85  char buff_[2];
86  unsigned dlen_;
87 
88  unsigned short pkt_id_;
89  std::vector<mqtt_qos_t> qoses_;
90 
91  unsigned body_len_;
92  unsigned nread_;
93 };
94 
95 } // namespace acl
const std::vector< mqtt_qos_t > & get_qoses(void) const
Definition: mqtt_suback.hpp:60
mqtt_qos_t
Definition: mqtt_header.hpp:38
unsigned short get_pkt_id(void) const
Definition: mqtt_suback.hpp:52
#define ACL_CPP_API
bool finished(void) const
Definition: mqtt_suback.hpp:72