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