COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
include
comms
util
BitSizeToByteSize.h
1
//
2
// Copyright 2015 - 2026 (C). Alex Robenko. All rights reserved.
3
//
4
// SPDX-License-Identifier: MPL-2.0
5
//
6
// This Source Code Form is subject to the terms of the Mozilla Public
7
// License, v. 2.0. If a copy of the MPL was not distributed with this
8
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
#pragma once
11
12
#include <cstddef>
13
#include <cstdint>
14
15
namespace
comms
16
{
17
18
namespace
util
19
{
20
22
template
<std::
size_t
TSize>
23
struct
BitSizeToByteSize
24
{
25
static_assert
(0 < TSize,
"The number of bits must be greater than 0"
);
26
static_assert
(TSize < 64,
"The number of bits is too high."
);
27
static
const
std::size_t Value = BitSizeToByteSize<TSize + 1>::Value;
28
};
29
30
template
<>
31
struct
BitSizeToByteSize<8>
32
{
33
static
const
std::size_t Value =
sizeof
(std::uint8_t);
34
};
35
36
template
<>
37
struct
BitSizeToByteSize<16>
38
{
39
static
const
std::size_t Value =
sizeof
(std::uint16_t);
40
};
41
42
template
<>
43
struct
BitSizeToByteSize<32>
44
{
45
static
const
std::size_t Value =
sizeof
(std::uint32_t);
46
};
47
48
template
<>
49
struct
BitSizeToByteSize<64>
50
{
51
static
const
std::size_t Value =
sizeof
(std::uint64_t);
52
};
53
55
56
}
// namespace util
57
58
}
// namespace comms
59
comms
Main namespace for all classes / functions of COMMS library.
Generated by
1.9.8