cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Toggle main menu visibility
Loading...
Searching...
No Matches
to_big_endian.h
Go to the documentation of this file.
1
/*
2
* Copyright 2024 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <array>
23
#include <cstddef>
// IWYU pragma: keep
24
#include <cstdint>
25
#include <cstring>
26
27
#include "
msgpack_light/details/mutable_static_binary_view.h
"
28
29
namespace
msgpack_light::details
{
30
38
template
<std::
size_t
N>
39
inline
void
to_big_endian
(
40
const
void
* from,
mutable_static_binary_view<N>
to)
noexcept
;
41
48
template
<>
49
inline
void
to_big_endian<1U>
(
50
const
void
* from,
mutable_static_binary_view<1U>
to)
noexcept
{
51
std::memcpy(to.data(), from, 1U);
52
}
53
60
template
<>
61
inline
void
to_big_endian<2U>
(
62
const
void
* from,
mutable_static_binary_view<2U>
to)
noexcept
{
63
std::uint16_t value{};
64
std::memcpy(&value, from,
sizeof
(value));
65
to[0U] =
static_cast<
unsigned
char
>
(value >> 8U);
// NOLINT
66
to[1U] =
static_cast<
unsigned
char
>
(value);
// NOLINT
67
}
68
75
template
<>
76
inline
void
to_big_endian<4U>
(
77
const
void
* from,
mutable_static_binary_view<4U>
to)
noexcept
{
78
std::uint32_t value{};
79
std::memcpy(&value, from,
sizeof
(value));
80
to[0U] =
static_cast<
unsigned
char
>
(value >> 24U);
// NOLINT
81
to[1U] =
static_cast<
unsigned
char
>
(value >> 16U);
// NOLINT
82
to[2U] =
static_cast<
unsigned
char
>
(value >> 8U);
// NOLINT
83
to[3U] =
static_cast<
unsigned
char
>
(value);
// NOLINT
84
}
85
92
template
<>
93
// NOLINTNEXTLINE(readability-magic-numbers)
94
inline
void
to_big_endian<8U>
(
95
// NOLINTNEXTLINE(readability-magic-numbers)
96
const
void
* from,
mutable_static_binary_view<8U>
to)
noexcept
{
97
std::uint64_t value{};
98
std::memcpy(&value, from,
sizeof
(value));
99
to[0U] =
static_cast<
unsigned
char
>
(value >> 56U);
// NOLINT
100
to[1U] =
static_cast<
unsigned
char
>
(value >> 48U);
// NOLINT
101
to[2U] =
static_cast<
unsigned
char
>
(value >> 40U);
// NOLINT
102
to[3U] =
static_cast<
unsigned
char
>
(value >> 32U);
// NOLINT
103
to[4U] =
static_cast<
unsigned
char
>
(value >> 24U);
// NOLINT
104
to[5U] =
static_cast<
unsigned
char
>
(value >> 16U);
// NOLINT
105
to[6U] =
static_cast<
unsigned
char
>
(value >> 8U);
// NOLINT
106
to[7U] =
static_cast<
unsigned
char
>
(value);
// NOLINT
107
}
108
116
template
<std::
size_t
N>
117
inline
void
to_big_endian
(
118
const
void
* from, std::array<unsigned char, N>* to)
noexcept
{
119
to_big_endian
(from,
mutable_static_binary_view<N>
(to->data()));
120
}
121
122
}
// namespace msgpack_light::details
msgpack_light::details::mutable_static_binary_view
Class of views of mutable buffers with static sizes.
Definition
mutable_static_binary_view.h:32
mutable_static_binary_view.h
Definition of mutable_static_binary_view class.
msgpack_light::details
Namespace of internal implementations.
Definition
binary.h:35
msgpack_light::details::to_big_endian
void to_big_endian(const void *from, mutable_static_binary_view< N > to) noexcept
Convert to big endian.
include
msgpack_light
details
to_big_endian.h
Generated on
for cpp-msgpack-light by
1.18.0