]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/websocket/detail/endian.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / websocket / detail / endian.hpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7
8 #ifndef BEAST_WEBSOCKET_DETAIL_ENDIAN_HPP
9 #define BEAST_WEBSOCKET_DETAIL_ENDIAN_HPP
10
11 #include <cstdint>
12
13 namespace beast {
14 namespace websocket {
15 namespace detail {
16
17 inline
18 std::uint16_t
19 big_uint16_to_native(void const* buf)
20 {
21 auto const p = reinterpret_cast<
22 std::uint8_t const*>(buf);
23 return (p[0]<<8) + p[1];
24 }
25
26 inline
27 std::uint64_t
28 big_uint64_to_native(void const* buf)
29 {
30 auto const p = reinterpret_cast<
31 std::uint8_t const*>(buf);
32 return
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) +
40 p[7];
41 }
42
43 inline
44 std::uint32_t
45 little_uint32_to_native(void const* buf)
46 {
47 auto const p = reinterpret_cast<
48 std::uint8_t const*>(buf);
49 return
50 p[0] +
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);
54 }
55
56 inline
57 void
58 native_to_little_uint32(std::uint32_t v, void* buf)
59 {
60 auto p = reinterpret_cast<std::uint8_t*>(buf);
61 p[0] = v & 0xff;
62 p[1] = (v >> 8) & 0xff;
63 p[2] = (v >> 16) & 0xff;
64 p[3] = (v >> 24) & 0xff;
65 }
66
67 } // detail
68 } // websocket
69 } // beast
70
71 #endif