types.h
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef TYPES_H
#define TYPES_H
#include "stdint.h"
#include <list>
#include <string>
enum class PacketType
{
Reserved = 0,
CONNECT = 1,
CONNACK = 2,
PUBLISH = 3,
PUBACK = 4,
PUBREC = 5,
PUBREL = 6,
PUBCOMP = 7,
SUBSCRIBE = 8,
SUBACK = 9,
UNSUBSCRIBE = 10,
UNSUBACK = 11,
PINGREQ = 12,
PINGRESP = 13,
DISCONNECT = 14,
Reserved2 = 15
};
enum class ProtocolVersion
{
None = 0,
Mqtt31 = 0x03,
Mqtt311 = 0x04
};
enum class ConnAckReturnCodes
{
Accepted = 0,
UnacceptableProtocolVersion = 1,
ClientIdRejected = 2,
ServerUnavailable = 3,
MalformedUsernameOrPassword = 4,
NotAuthorized = 5
};
class ConnAck
{
public:
ConnAck(ConnAckReturnCodes return_code, bool session_present=false);
ConnAckReturnCodes return_code;
bool session_present = false;
size_t getLengthWithoutFixedHeader() const { return 2;} // size of connack is always the same
};
enum class SubAckReturnCodes
{
MaxQoS0 = 0,
MaxQoS1 = 1,
MaxQoS2 = 2,
Fail = 0x80
};
class SubAck
{
public:
uint16_t packet_id;
std::list<SubAckReturnCodes> responses;
SubAck(uint16_t packet_id, const std::list<char> &subs_qos_reponses);
size_t getLengthWithoutFixedHeader() const;
};
class UnsubAck
{
public:
uint16_t packet_id;
UnsubAck(uint16_t packet_id);
size_t getLengthWithoutFixedHeader() const;
};
class Publish
{
public:
std::string topic;
std::string payload;
char qos = 0;
bool retain = false; // Note: existing subscribers don't get publishes of retained messages with retain=1. [MQTT-3.3.1-9]
Publish(const std::string &topic, const std::string payload, char qos);
size_t getLengthWithoutFixedHeader() const;
};
class PubAck
{
public:
PubAck(uint16_t packet_id);
uint16_t packet_id;
size_t getLengthWithoutFixedHeader() const;
};
#endif // TYPES_H