2021-03-02 15:43:49 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mqtt_message.hpp"
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
2021-03-07 12:45:22 +08:00
|
|
|
class ACL_CPP_API mqtt_publish : public mqtt_message {
|
2021-03-02 15:43:49 +08:00
|
|
|
public:
|
2021-03-08 15:03:32 +08:00
|
|
|
mqtt_publish(void);
|
|
|
|
mqtt_publish(const mqtt_header& header);
|
2021-03-02 15:43:49 +08:00
|
|
|
~mqtt_publish(void);
|
|
|
|
|
|
|
|
void set_topic(const char* topic);
|
|
|
|
void set_pkt_id(unsigned short id);
|
|
|
|
void set_payload(unsigned len, const char* data = NULL);
|
|
|
|
|
2021-03-02 17:40:14 +08:00
|
|
|
|
2021-03-02 15:43:49 +08:00
|
|
|
const char* get_topic(void) const {
|
|
|
|
return topic_.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short get_pkt_id(void) const {
|
|
|
|
return pkt_id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned get_payload_len(void) const {
|
|
|
|
return payload_len_;
|
|
|
|
}
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
const string& get_payload(void) const {
|
|
|
|
return payload_;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// @override
|
2021-03-02 15:43:49 +08:00
|
|
|
bool to_string(string& out);
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
// @override
|
2021-03-04 16:59:00 +08:00
|
|
|
int update(const char* data, int dlen);
|
2021-03-02 15:43:49 +08:00
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
// @override
|
2021-03-02 15:43:49 +08:00
|
|
|
bool is_finished(void) const {
|
|
|
|
return finished_;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-03-04 16:59:00 +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);
|
2021-03-05 14:30:21 +08:00
|
|
|
int update_pktid(const char* data, int dlen);
|
2021-03-04 16:59:00 +08:00
|
|
|
int update_payload(const char* data, int dlen);
|
2021-03-02 15:43:49 +08:00
|
|
|
|
|
|
|
private:
|
2021-03-08 15:03:32 +08:00
|
|
|
unsigned status_;
|
2021-03-02 15:43:49 +08:00
|
|
|
bool finished_;
|
2021-03-04 16:59:00 +08:00
|
|
|
char buff_[2];
|
|
|
|
int dlen_;
|
|
|
|
unsigned hlen_var_;
|
2021-03-02 15:43:49 +08:00
|
|
|
|
|
|
|
string topic_;
|
|
|
|
unsigned short pkt_id_;
|
|
|
|
unsigned payload_len_;
|
|
|
|
string payload_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|