// Copyright Takatoshi Kondo 2018 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #if !defined(MQTT_TWO_BYTE_UTIL_HPP) #define MQTT_TWO_BYTE_UTIL_HPP #include #include #include #include #include namespace MQTT_NS { inline boost::container::static_vector num_to_2bytes(std::uint16_t val) { return { static_cast(val >> 8), static_cast(val & 0xff) }; } template inline void add_uint16_t_to_buf(T& buf, std::uint16_t num) { buf.push_back(static_cast(num >> 8)); buf.push_back(static_cast(num & 0xff)); } template constexpr std::uint16_t make_uint16_t(It b, It e) { (void)e; // Avoid warning in release builds about unused variable BOOST_ASSERT(std::distance(b, e) == 2); auto b1 = b++; auto b2 = b++; return static_cast( (static_cast(*b1) & 0xff) << 8 | (static_cast(*b2) & 0xff) ); } } // namespace MQTT_NS #endif // MQTT_TWO_BYTE_UTIL_HPP