mqtt_cpp
two_or_four_byte_util.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2021
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(MQTT_TWO_OR_FOUR_BYTE_UTIL_HPP)
8 #define MQTT_TWO_OR_FOUR_BYTE_UTIL_HPP
9 
10 #include <cstdint>
11 #include <cstdlib>
12 
13 #include <mqtt/namespace.hpp>
14 #include <mqtt/two_byte_util.hpp>
15 #include <mqtt/four_byte_util.hpp>
16 
17 namespace MQTT_NS {
18 
19 template <std::size_t Bytes>
21 
22 template <>
24  using type = std::uint16_t;
25 };
26 
27 template <>
29  using type = std::uint32_t;
30 };
31 
32 template <std::size_t Bytes>
34 
35 template <>
37  template <typename It>
38  static constexpr std::uint16_t apply(It b, It e) {
39  return make_uint16_t(b, e);
40  }
41 };
42 
43 template <>
45  template <typename It>
46  static constexpr std::uint32_t apply(It b, It e) {
47  return make_uint32_t(b, e);
48  }
49 };
50 
51 template <std::size_t Bytes>
53 
54 template <>
56  template <typename T>
57  static void apply(T& buf, std::uint16_t two_or_four_byte) {
58  add_uint16_t_to_buf(buf, two_or_four_byte);
59  }
60 };
61 
62 template <>
64  template <typename T>
65  static void apply(T& buf, std::uint32_t two_or_four_byte) {
66  add_uint32_t_to_buf(buf, two_or_four_byte);
67  }
68 };
69 
70 } // namespace MQTT_NS
71 
72 #endif // MQTT_TWO_OR_FOUR_BYTE_UTIL_HPP
Definition: any.hpp:27
void add_uint32_t_to_buf(T &buf, std::uint32_t num)
Definition: four_byte_util.hpp:31
void add_uint16_t_to_buf(T &buf, std::uint16_t num)
Definition: two_byte_util.hpp:28
constexpr std::uint16_t make_uint16_t(It b, It e)
Definition: two_byte_util.hpp:34
constexpr std::uint32_t make_uint32_t(It b, It e)
Definition: four_byte_util.hpp:39
static void apply(T &buf, std::uint16_t two_or_four_byte)
Definition: two_or_four_byte_util.hpp:57
static void apply(T &buf, std::uint32_t two_or_four_byte)
Definition: two_or_four_byte_util.hpp:65
Definition: two_or_four_byte_util.hpp:52
static constexpr std::uint16_t apply(It b, It e)
Definition: two_or_four_byte_util.hpp:38
static constexpr std::uint32_t apply(It b, It e)
Definition: two_or_four_byte_util.hpp:46
Definition: two_or_four_byte_util.hpp:33
std::uint16_t type
Definition: two_or_four_byte_util.hpp:24
std::uint32_t type
Definition: two_or_four_byte_util.hpp:29
Definition: two_or_four_byte_util.hpp:20