Zserio C++17 runtime library
1.3.0
Built for Zserio 2.20.0
Loading...
Searching...
No Matches
BitFieldUtil.cpp
Go to the documentation of this file.
1
#include "
zserio/BitFieldUtil.h
"
2
#include "
zserio/CppRuntimeException.h
"
3
4
namespace
zserio
5
{
6
7
static
void
checkBitFieldLength(
size_t
length)
8
{
9
if
(length == 0 || length > 64)
10
{
11
throw
CppRuntimeException(
"Asking for bound of bitfield with invalid length "
) << length <<
"!"
;
12
}
13
}
14
15
int64_t
getBitFieldLowerBound
(
size_t
length
,
bool
isSigned)
16
{
17
checkBitFieldLength(
length
);
18
19
if
(isSigned)
20
{
21
return
-
static_cast<
int64_t
>
((
UINT64_C
(1) << (
length
- 1)) - 1) - 1;
22
}
23
else
24
{
25
return
0;
26
}
27
}
28
29
uint64_t
getBitFieldUpperBound
(
size_t
length
,
bool
isSigned)
30
{
31
checkBitFieldLength(
length
);
32
33
if
(isSigned)
34
{
35
return
(
UINT64_C
(1) << (
length
- 1)) - 1;
36
}
37
else
38
{
39
return
length
== 64 ?
UINT64_MAX
: ((
UINT64_C
(1) <<
length
) - 1);
40
}
41
}
42
43
}
// namespace zserio
BitFieldUtil.h
CppRuntimeException.h
zserio::View
Definition
Traits.h:15
zserio
Definition
AllocatorHolder.h:8
zserio::getBitFieldLowerBound
int64_t getBitFieldLowerBound(size_t length, bool isSigned)
Definition
BitFieldUtil.cpp:15
zserio::getBitFieldUpperBound
uint64_t getBitFieldUpperBound(size_t length, bool isSigned)
Definition
BitFieldUtil.cpp:29
zserio
BitFieldUtil.cpp
Generated by
1.9.8