Coverage Report

Created: 2023-12-13 14:58

src/zserio/SizeConvertUtil.cpp
Line
Count
Source
1
#include <cstddef>
2
#include <limits>
3
4
#include "zserio/CppRuntimeException.h"
5
#include "zserio/SizeConvertUtil.h"
6
#include "zserio/RuntimeArch.h"
7
8
namespace zserio
9
{
10
11
uint32_t convertSizeToUInt32(size_t value)
12
5.74k
{
13
5.74k
#ifdef ZSERIO_RUNTIME_64BIT
14
5.74k
    if (value > static_cast<size_t>(std::numeric_limits<uint32_t>::max()))
15
2
    {
16
2
        throw CppRuntimeException("SizeConvertUtil: size_t value '") << value <<
17
2
                "' is out of bounds for conversion to uint32_t type!";
18
2
    }
19
5.74k
#endif
20
21
5.74k
    return static_cast<uint32_t>(value);
22
5.74k
}
23
24
size_t convertUInt64ToSize(uint64_t value)
25
11
{
26
#ifndef ZSERIO_RUNTIME_64BIT
27
    if (value > static_cast<uint64_t>(std::numeric_limits<size_t>::max()))
28
    {
29
        throw CppRuntimeException("SizeConvertUtil: uint64_t value '") << value <<
30
                "' is out of bounds for conversion to size_t type!";
31
    }
32
#endif
33
34
11
    return static_cast<size_t>(value);
35
11
}
36
37
} // namespace zserio