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