mqtt_cpp
remaining_length.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2015
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_REMAINING_LENGTH_HPP)
8 #define MQTT_REMAINING_LENGTH_HPP
9 
10 #include <mqtt/namespace.hpp>
11 #include <mqtt/string_view.hpp>
12 #include <mqtt/variable_length.hpp>
13 
14 namespace MQTT_NS {
15 
16 inline std::string
17 remaining_bytes(std::size_t size) {
18  std::string bytes = variable_bytes(size);
19  if (bytes.empty()) throw remaining_length_error();
20  return bytes;
21 }
22 
23 constexpr std::tuple<std::size_t, std::size_t>
25  return variable_length(bytes);
26 }
27 
28 template <typename Iterator>
29 constexpr std::tuple<std::size_t, std::size_t>
30 remaining_length(Iterator b, Iterator e) {
31  return variable_length(b, e);
32 }
33 
34 } // namespace MQTT_NS
35 
36 #endif // MQTT_REMAINING_LENGTH_HPP
Definition: any.hpp:27
std::string variable_bytes(std::size_t size)
Definition: variable_length.hpp:18
std::string remaining_bytes(std::size_t size)
Definition: remaining_length.hpp:17
boost::string_ref string_view
Definition: string_view.hpp:64
constexpr std::tuple< std::size_t, std::size_t > remaining_length(string_view bytes)
Definition: remaining_length.hpp:24
std::size_t size(basic_message_variant< PacketIdBytes > const &mv)
Definition: message_variant.hpp:93
constexpr std::tuple< std::size_t, std::size_t > variable_length(T const &bytes)
Definition: variable_length.hpp:42
Definition: exception.hpp:33