2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BEAST_WEBSOCKET_DETAIL_ENDIAN_HPP
9 #define BEAST_WEBSOCKET_DETAIL_ENDIAN_HPP
19 big_uint16_to_native(void const* buf)
21 auto const p = reinterpret_cast<
22 std::uint8_t const*>(buf);
23 return (p[0]<<8) + p[1];
28 big_uint64_to_native(void const* buf)
30 auto const p = reinterpret_cast<
31 std::uint8_t const*>(buf);
33 (static_cast<std::uint64_t>(p[0])<<56) +
34 (static_cast<std::uint64_t>(p[1])<<48) +
35 (static_cast<std::uint64_t>(p[2])<<40) +
36 (static_cast<std::uint64_t>(p[3])<<32) +
37 (static_cast<std::uint64_t>(p[4])<<24) +
38 (static_cast<std::uint64_t>(p[5])<<16) +
39 (static_cast<std::uint64_t>(p[6])<< 8) +
45 little_uint32_to_native(void const* buf)
47 auto const p = reinterpret_cast<
48 std::uint8_t const*>(buf);
51 (static_cast<std::uint32_t>(p[1])<< 8) +
52 (static_cast<std::uint32_t>(p[2])<<16) +
53 (static_cast<std::uint32_t>(p[3])<<24);
58 native_to_little_uint32(std::uint32_t v, void* buf)
60 auto p = reinterpret_cast<std::uint8_t*>(buf);
62 p[1] = (v >> 8) & 0xff;
63 p[2] = (v >> 16) & 0xff;
64 p[3] = (v >> 24) & 0xff;