types.h
2.89 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3.
FlashMQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.
*/
#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;
};
class PubRec
{
public:
PubRec(uint16_t packet_id);
uint16_t packet_id;
size_t getLengthWithoutFixedHeader() const;
};
class PubComp
{
public:
PubComp(uint16_t packet_id);
uint16_t packet_id;
size_t getLengthWithoutFixedHeader() const;
};
class PubRel
{
public:
PubRel(uint16_t packet_id);
uint16_t packet_id;
size_t getLengthWithoutFixedHeader() const;
};
#endif // TYPES_H