cpp-common: remove `cfg-*.hpp` and `log-cfg.hpp`
[babeltrace.git] / src / cpp-common / endian.hpp
CommitLineData
df34434f
PP
1/*
2 * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_ENDIAN_HPP
8#define BABELTRACE_CPP_COMMON_ENDIAN_HPP
9
10#include <cstdint>
11
83ad336c 12#include "compat/endian.h" /* IWYU pragma: keep */
df34434f
PP
13
14namespace bt2_common {
15
16static inline std::uint8_t littleEndianToNative(const std::uint8_t val) noexcept
17{
18 return val;
19}
20
21static inline std::uint8_t bigEndianToNative(const std::uint8_t val) noexcept
22{
23 return val;
24}
25
26static inline std::int8_t littleEndianToNative(const std::int8_t val) noexcept
27{
28 return val;
29}
30
31static inline std::int8_t bigEndianToNative(const std::int8_t val) noexcept
32{
33 return val;
34}
35
36static inline std::uint16_t littleEndianToNative(const std::uint16_t val) noexcept
37{
38 return static_cast<std::uint16_t>(le16toh(val));
39}
40
41static inline std::uint16_t bigEndianToNative(const std::uint16_t val) noexcept
42{
43 return static_cast<std::uint16_t>(be16toh(val));
44}
45
46static inline std::int16_t littleEndianToNative(const std::int16_t val) noexcept
47{
48 return static_cast<std::int16_t>(littleEndianToNative(static_cast<std::uint16_t>(val)));
49}
50
51static inline std::int16_t bigEndianToNative(const std::int16_t val) noexcept
52{
53 return static_cast<std::int16_t>(bigEndianToNative(static_cast<std::uint16_t>(val)));
54}
55
56static inline std::uint32_t littleEndianToNative(const std::uint32_t val) noexcept
57{
58 return static_cast<std::uint32_t>(le32toh(val));
59}
60
61static inline std::uint32_t bigEndianToNative(const std::uint32_t val) noexcept
62{
63 return static_cast<std::uint32_t>(be32toh(val));
64}
65
66static inline std::int32_t littleEndianToNative(const std::int32_t val) noexcept
67{
68 return static_cast<std::int32_t>(littleEndianToNative(static_cast<std::uint32_t>(val)));
69}
70
71static inline std::int32_t bigEndianToNative(const std::int32_t val) noexcept
72{
73 return static_cast<std::int32_t>(bigEndianToNative(static_cast<std::uint32_t>(val)));
74}
75
76static inline std::uint64_t littleEndianToNative(const std::uint64_t val) noexcept
77{
78 return static_cast<std::uint64_t>(le64toh(val));
79}
80
81static inline std::uint64_t bigEndianToNative(const std::uint64_t val) noexcept
82{
83 return static_cast<std::uint64_t>(be64toh(val));
84}
85
86static inline std::int64_t littleEndianToNative(const std::int64_t val) noexcept
87{
88 return static_cast<std::int64_t>(littleEndianToNative(static_cast<std::uint64_t>(val)));
89}
90
91static inline std::int64_t bigEndianToNative(const std::int64_t val) noexcept
92{
93 return static_cast<std::int64_t>(bigEndianToNative(static_cast<std::uint64_t>(val)));
94}
95
96} /* namespace bt2_common */
97
98#endif /* BABELTRACE_CPP_COMMON_ENDIAN_HPP */
This page took 0.028076 seconds and 4 git commands to generate.