async_mqtt 4.1.0
Loading...
Searching...
No Matches
packet.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_HPP)
8#define ASYNC_MQTT_PACKET_HPP
9
10#include <async_mqtt/buffer.hpp>
11#include <async_mqtt/util/static_vector.hpp>
12#include <async_mqtt/packet/fixed_header.hpp>
13
14namespace async_mqtt {
15
16namespace detail {
17
18class header_only_packet {
19public:
23 header_only_packet(control_packet_type type, std::uint8_t flags)
24 : packet_ { static_cast<char>(make_fixed_header(type, flags)), 0 }
25 {}
26
32 std::vector<as::const_buffer> const_buffer_sequence() const {
33 return { as::buffer(packet_.data(), packet_.size()) };
34 }
35
40 std::size_t size() const {
41 return packet_.size();
42 }
43
48 static constexpr std::size_t num_of_const_buffer_sequence() {
49 return 1;
50 }
51
58 std::string continuous_buffer() const {
59 return std::string(packet_.data(), size());
60 }
61private:
62 static_vector<char, 2> packet_;
63};
64
65} // namespace detail
66
67} // namespace async_mqtt
68
69#endif // ASYNC_MQTT_PACKET_HPP