// 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_FOUR_BYTE_UTIL_HPP) #define MQTT_FOUR_BYTE_UTIL_HPP #include #include #include #include #include #include namespace MQTT_NS { inline boost::container::static_vector num_to_4bytes(std::uint32_t val) { return { static_cast(val >> 24), static_cast(val >> 16), static_cast(val >> 8), static_cast(val & 0xff) }; } template inline void add_uint32_t_to_buf(T& buf, std::uint32_t num) { buf.push_back(static_cast(num >> 24)); buf.push_back(static_cast(num >> 16)); buf.push_back(static_cast(num >> 8)); buf.push_back(static_cast(num & 0xff)); } template constexpr std::uint32_t make_uint32_t(It b, It e) { (void)e; // Avoid warning in release builds about unused variable BOOST_ASSERT(std::distance(b, e) == 4); auto b1 = b++; auto b2 = b++; auto b3 = b++; auto b4 = b++; return static_cast( (static_cast(*b1) & 0xff) << 24 | (static_cast(*b2) & 0xff) << 16 | (static_cast(*b3) & 0xff) << 8 | (static_cast(*b4) & 0xff) ); } } // namespace MQTT_NS #endif // MQTT_FOUR_BYTE_UTIL_HPP