remaining_length.hpp 925 B

123456789101112131415161718192021222324252627282930313233343536
  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. #if !defined(MQTT_REMAINING_LENGTH_HPP)
  7. #define MQTT_REMAINING_LENGTH_HPP
  8. #include <mqtt/namespace.hpp>
  9. #include <mqtt/string_view.hpp>
  10. #include <mqtt/variable_length.hpp>
  11. namespace MQTT_NS {
  12. inline std::string
  13. remaining_bytes(std::size_t size) {
  14. std::string bytes = variable_bytes(size);
  15. if (bytes.empty() || bytes.size() > 4) throw remaining_length_error();
  16. return bytes;
  17. }
  18. constexpr std::tuple<std::size_t, std::size_t>
  19. remaining_length(string_view bytes) {
  20. return variable_length(bytes);
  21. }
  22. template <typename Iterator>
  23. constexpr std::tuple<std::size_t, std::size_t>
  24. remaining_length(Iterator b, Iterator e) {
  25. return variable_length(b, e);
  26. }
  27. } // namespace MQTT_NS
  28. #endif // MQTT_REMAINING_LENGTH_HPP