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