2021-03-02 11:31:24 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../stdlib/string.hpp"
|
2021-03-08 15:03:32 +08:00
|
|
|
#include "mqtt_header.hpp"
|
2021-03-02 11:31:24 +08:00
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
2021-03-07 12:45:22 +08:00
|
|
|
class ACL_CPP_API mqtt_message {
|
2021-03-02 11:31:24 +08:00
|
|
|
public:
|
|
|
|
mqtt_message(mqtt_type_t type);
|
2021-03-08 15:03:32 +08:00
|
|
|
mqtt_message(const mqtt_header& header);
|
2021-03-02 11:31:24 +08:00
|
|
|
virtual ~mqtt_message(void);
|
|
|
|
|
2021-03-05 14:30:21 +08:00
|
|
|
public:
|
|
|
|
virtual bool to_string(string& out) {
|
|
|
|
(void) out;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int update(const char* data, int dlen) {
|
|
|
|
(void) data;
|
|
|
|
return dlen;
|
|
|
|
}
|
|
|
|
|
2021-03-10 17:21:29 +08:00
|
|
|
virtual bool finished(void) const {
|
2021-03-05 14:30:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:03:32 +08:00
|
|
|
mqtt_header& get_header(void) {
|
|
|
|
return header_;
|
2021-03-02 17:40:14 +08:00
|
|
|
}
|
2021-03-02 11:31:24 +08:00
|
|
|
|
2021-03-08 19:57:24 +08:00
|
|
|
const mqtt_header& get_header(void) const {
|
|
|
|
return header_;
|
|
|
|
}
|
|
|
|
|
2021-03-09 16:16:32 +08:00
|
|
|
public:
|
|
|
|
static mqtt_message* create_message(const mqtt_header& header);
|
|
|
|
|
2021-03-08 15:03:32 +08:00
|
|
|
protected:
|
|
|
|
mqtt_header header_;
|
2021-03-02 11:31:24 +08:00
|
|
|
|
|
|
|
void pack_add(unsigned char ch, string& out);
|
|
|
|
void pack_add(unsigned short n, string& out);
|
|
|
|
void pack_add(const string& s, string& out);
|
|
|
|
|
|
|
|
bool unpack_short(const char* data, size_t len, unsigned short& out);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|