SNode.C
Loading...
Searching...
No Matches
ControlPacketFactory.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "iot/mqtt-fast/ControlPacketFactory.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include <vector>
25
26#endif // DOXYGEN_SHOULD_SKIP_THIS
27
28namespace iot::mqtt_fast {
29
31 : typeFlags(socketContext)
32 , remainingLength(socketContext)
34 }
35
37 std::size_t consumed = 0;
38
39 switch (state) {
40 case 0: // Type - Flags
41 consumed = typeFlags.construct();
43 state++;
44 } else {
46 }
47 break;
48 case 1: // Remaining length
51 data.setLength(remainingLength.getValue());
53 state++;
54 } else {
56 }
57 break;
58 case 2: // Var-Header + Payload
59 consumed = data.construct();
60 if (data.isComplete()) {
61 completed = true;
62 state++;
63 } else {
64 error = data.isError();
65 }
66 break;
67 }
68
69 return consumed;
70 }
71
73 return completed;
74 }
75
77 return error;
78 }
79
81 return data;
82 }
83
85 return static_cast<uint8_t>(typeFlags.getValue() >> 0x04);
86 }
87
89 return static_cast<uint8_t>(typeFlags.getValue() & 0x0F);
90 }
91
93 return data.getValue().size();
94 }
95
97 completed = false;
98 error = false;
99 state = 0;
100
103 data.reset();
104 }
105
106} // namespace iot::mqtt_fast
ControlPacketFactory(core::socket::SocketContext *socketContext)
iot::mqtt_fast::types::Int_V remainingLength
iot::mqtt_fast::types::Binary & getPacket()
iot::mqtt_fast::types::Int_1 typeFlags
std::size_t construct() override
Definition Int_1.cpp:32
void reset() override
Definition Int_1.cpp:45
Int_1(core::socket::SocketContext *socketContext=nullptr)
Definition Int_1.cpp:28
uint32_t getValue() const
Definition Int_V.cpp:55
void reset() override
Definition Int_V.cpp:59
std::size_t construct() override
Definition Int_V.cpp:32
Int_V(core::socket::SocketContext *socketContext=nullptr)
Definition Int_V.cpp:28