2021-03-04 17:37:28 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mqtt_message.hpp"
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
2021-03-12 17:26:49 +08:00
|
|
|
/**
|
|
|
|
* mqtt message object for MQTT_UNSUBSCRIBE type.
|
|
|
|
*/
|
2021-03-07 12:45:22 +08:00
|
|
|
class ACL_CPP_API mqtt_unsubscribe : public mqtt_message {
|
2021-03-04 17:37:28 +08:00
|
|
|
public:
|
2021-03-12 17:26:49 +08:00
|
|
|
/**
|
|
|
|
* constructor for creating MQTT_PUBACK mqtt message object.
|
|
|
|
* @see mqtt_message
|
|
|
|
*/
|
2021-03-08 15:03:32 +08:00
|
|
|
mqtt_unsubscribe(void);
|
2021-03-12 17:26:49 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor for creating MQTT_PUBACK mqtt message object.
|
|
|
|
* @see mqtt_message
|
|
|
|
*/
|
2021-03-08 15:03:32 +08:00
|
|
|
mqtt_unsubscribe(const mqtt_header& header);
|
2021-03-12 17:26:49 +08:00
|
|
|
|
2021-03-04 17:37:28 +08:00
|
|
|
~mqtt_unsubscribe(void);
|
|
|
|
|
2021-03-12 17:26:49 +08:00
|
|
|
/**
|
|
|
|
* set the message id.
|
|
|
|
* @param id {unsigned short} should > 0 && <= 65535.
|
|
|
|
* @return {mqtt_unsubscribe&}
|
|
|
|
*/
|
|
|
|
mqtt_unsubscribe& set_pkt_id(unsigned short id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the message's topic.
|
|
|
|
* @param topic {const char*}
|
|
|
|
* @return {mqtt_unsubscribe&}
|
|
|
|
*/
|
|
|
|
mqtt_unsubscribe& add_topic(const char* topic);
|
2021-03-04 17:37:28 +08:00
|
|
|
|
2022-07-15 15:49:38 +08:00
|
|
|
/**
|
|
|
|
* get all the topics.
|
|
|
|
* @return {const std::vector<string>&}
|
|
|
|
*/
|
|
|
|
const std::vector<string>& get_topics(void) const {
|
|
|
|
return topics_;
|
|
|
|
}
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
protected:
|
|
|
|
// @override
|
2021-03-04 17:37:28 +08:00
|
|
|
bool to_string(string& out);
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
// @override
|
2021-03-04 17:37:28 +08:00
|
|
|
int update(const char* data, int dlen);
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
// @override
|
2021-03-10 17:21:29 +08:00
|
|
|
bool finished(void) const {
|
2021-03-05 14:30:21 +08:00
|
|
|
return finished_;
|
|
|
|
}
|
|
|
|
|
2021-03-04 17:37:28 +08:00
|
|
|
public:
|
2021-03-12 17:26:49 +08:00
|
|
|
// used internal to parse unsubscribe message in streaming mode.
|
|
|
|
|
2021-03-04 17:37:28 +08:00
|
|
|
int update_header_var(const char* data, int dlen);
|
|
|
|
int update_topic_len(const char* data, int dlen);
|
|
|
|
int update_topic_val(const char* data, int dlen);
|
|
|
|
|
|
|
|
private:
|
2021-03-08 15:03:32 +08:00
|
|
|
unsigned status_;
|
2021-03-04 17:37:28 +08:00
|
|
|
bool finished_;
|
|
|
|
char buff_[2];
|
|
|
|
unsigned dlen_;
|
|
|
|
|
|
|
|
unsigned short pkt_id_;
|
|
|
|
std::vector<string> topics_;
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
unsigned body_len_;
|
2021-03-04 17:37:28 +08:00
|
|
|
unsigned nread_;
|
|
|
|
|
|
|
|
string topic_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|
|
|
|
|