COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
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
15namespace comms
16{
17
18namespace util
19{
20
22template <std::size_t TSize>
23struct 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
30template <>
31struct BitSizeToByteSize<8>
32{
33 static const std::size_t Value = sizeof(std::uint8_t);
34};
35
36template <>
37struct BitSizeToByteSize<16>
38{
39 static const std::size_t Value = sizeof(std::uint16_t);
40};
41
42template <>
43struct BitSizeToByteSize<32>
44{
45 static const std::size_t Value = sizeof(std::uint32_t);
46};
47
48template <>
49struct 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
Main namespace for all classes / functions of COMMS library.