async_mqtt 9.0.1
Loading...
Searching...
No Matches
v5_puback.hpp
1// Copyright Takatoshi Kondo 2022
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PACKET_V5_PUBACK_HPP)
8#define ASYNC_MQTT_PACKET_V5_PUBACK_HPP
9
10#include <async_mqtt/buffer_to_packet_variant.hpp>
11#include <async_mqtt/error.hpp>
12
13#include <async_mqtt/packet/control_packet_type.hpp>
14#include <async_mqtt/packet/packet_id_type.hpp>
15#include <async_mqtt/packet/property_variant.hpp>
16
17#include <async_mqtt/util/buffer.hpp>
18#include <async_mqtt/util/static_vector.hpp>
19
30namespace async_mqtt::v5 {
31
32namespace as = boost::asio;
33
54template <std::size_t PacketIdBytes>
56public:
57
69 puback_reason_code reason_code,
71 );
72
80 );
81
91 puback_reason_code reason_code
92 );
93
98 static constexpr control_packet_type type() {
100 }
101
107 std::vector<as::const_buffer> const_buffer_sequence() const;
108
113 std::size_t size() const;
114
119 std::size_t num_of_const_buffer_sequence() const;
120
126
132
137 properties const& props() const;
138
145 friend
146 std::ostream& operator<<(std::ostream& o, basic_puback_packet<PacketIdBytes> const& v) {
147 o <<
148 "v5::puback{" <<
149 "pid:" << v.packet_id();
150 if (v.reason_code_) {
151 o << ",rc:" << *v.reason_code_;
152 }
153 if (!v.props().empty()) {
154 o << ",ps:" << v.props();
155 };
156 o << "}";
157 return o;
158 }
159
160private:
161
162 template <std::size_t PacketIdBytesArg>
165
166#if defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
167 friend struct ::ut_packet::v5_puback;
168 friend struct ::ut_packet::v5_puback_pid4;
169 friend struct ::ut_packet::v5_puback_pid_only;
170 friend struct ::ut_packet::v5_puback_pid_rc;
171 friend struct ::ut_packet::v5_puback_prop_len_last;
172 friend struct ::ut_packet::v5_puback_error;
173#endif // defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
174
175 // private constructor for internal use
176 explicit basic_puback_packet(
178 std::optional<puback_reason_code> reason_code,
180 );
181
182 explicit basic_puback_packet(buffer buf, error_code& ec);
183
184private:
185 std::uint8_t fixed_header_;
186 std::size_t remaining_length_;
187 static_vector<char, 4> remaining_length_buf_;
188 static_vector<char, PacketIdBytes> packet_id_;
189
190 std::optional<puback_reason_code> reason_code_;
191
192 std::size_t property_length_ = 0;
193 static_vector<char, 4> property_length_buf_;
194 properties props_;
195};
196
209template <std::size_t PacketIdBytes>
211
224template <std::size_t PacketIdBytes>
226
238
239} // namespace async_mqtt::v5
240
241#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
242#include <async_mqtt/packet/impl/v5_puback.ipp>
243#endif // !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
244
245#endif // ASYNC_MQTT_PACKET_V5_PUBACK_HPP
The varaint type of all packets and system_error.
Definition packet_variant_fwd.hpp:37
buffer that has string_view interface and shared ownership This class is only for advanced usecase su...
Definition buffer.hpp:46
MQTT PUBACK packet (v5)
Definition v5_puback.hpp:55
basic_puback_packet(typename basic_packet_id_type< PacketIdBytes >::type packet_id)
constructor
bool operator<(basic_puback_packet< PacketIdBytes > const &lhs, basic_puback_packet< PacketIdBytes > const &rhs)
less than operator
std::size_t num_of_const_buffer_sequence() const
Get number of element of const_buffer_sequence.
properties const & props() const
Get properties.
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
static constexpr control_packet_type type()
Get MQTT control packet type.
Definition v5_puback.hpp:98
basic_puback_packet(typename basic_packet_id_type< PacketIdBytes >::type packet_id, puback_reason_code reason_code)
constructor
basic_packet_id_type< PacketIdBytes >::type packet_id() const
Get packet_id.
std::size_t size() const
Get packet size.
friend std::ostream & operator<<(std::ostream &o, basic_puback_packet< PacketIdBytes > const &v)
stream output operator
Definition v5_puback.hpp:146
puback_reason_code code() const
Get reason code.
bool operator==(basic_puback_packet< PacketIdBytes > const &lhs, basic_puback_packet< PacketIdBytes > const &rhs)
equal operator
basic_puback_packet(typename basic_packet_id_type< PacketIdBytes >::type packet_id, puback_reason_code reason_code, properties props)
constructor
sys::error_code error_code
sys is a namespace alias of boost::sytem.
Definition error.hpp:56
protocol_version
MQTT protocol version.
Definition protocol_version.hpp:29
basic_packet_variant< PacketIdBytes > buffer_to_basic_packet_variant(buffer buf, protocol_version ver, error_code &ec)
create basic_packet_variant from the buffer
control_packet_type
MQTT control packet type.
Definition control_packet_type.hpp:26
std::vector< property_variant > properties
property variant collection type
Definition property_variant.hpp:224
puback_reason_code
puback reason code It is reported as PUBLISH (QoS1) response via PUBACK packet
Definition error.hpp:718
packet idenfitifer type class template
Definition packet_id_type.hpp:25