Coverage Report

Created: 2026-10-19 14:15

src/zserio/BitSizeOfCalculator.h
Line
Count
Source
1
#ifndef ZSERIO_BITSIZEOF_CALCULATOR_H_INC
2
#define ZSERIO_BITSIZEOF_CALCULATOR_H_INC
3
4
#include <string>
5
6
#include "zserio/BitBuffer.h"
7
#include "zserio/BitPositionUtil.h"
8
#include "zserio/SizeConvertUtil.h"
9
#include "zserio/Span.h"
10
#include "zserio/StringView.h"
11
#include "zserio/Types.h"
12
13
namespace zserio
14
{
15
16
/**
17
 * Calculates bit size of Zserio varint16 type.
18
 *
19
 * \param value Varint16 value.
20
 *
21
 * \return Bit size of the current varint16 value.
22
 */
23
size_t bitSizeOfVarInt16(int16_t value);
24
25
/**
26
 * Calculates bit size of Zserio varint32 type.
27
 *
28
 * \param value Varint32 value.
29
 *
30
 * \return Bit size of the current varint32 value.
31
 */
32
size_t bitSizeOfVarInt32(int32_t value);
33
34
/**
35
 * Calculates bit size of Zserio varint64 type.
36
 *
37
 * \param value Varint64 value.
38
 *
39
 * \return Bit size of the current varint64 value.
40
 */
41
size_t bitSizeOfVarInt64(int64_t value);
42
43
/**
44
 * Calculates bit size of Zserio varuint16 type.
45
 *
46
 * \param value Varuint16 value.
47
 *
48
 * \return Bit size of the current varuint16 value.
49
 */
50
size_t bitSizeOfVarUInt16(uint16_t value);
51
52
/**
53
 * Calculates bit size of Zserio varuint32 type.
54
 *
55
 * \param value Varuint32 value.
56
 *
57
 * \return Bit size of the current varuint32 value.
58
 */
59
size_t bitSizeOfVarUInt32(uint32_t value);
60
61
/**
62
 * Calculates bit size of Zserio varuint64 type.
63
 *
64
 * \param value Varuint64 value.
65
 *
66
 * \return Bit size of the current varuint64 value.
67
 */
68
size_t bitSizeOfVarUInt64(uint64_t value);
69
70
/**
71
 * Calculates bit size of Zserio varint type.
72
 *
73
 * \param value Varint value.
74
 *
75
 * \return Bit size of the current varint value.
76
 */
77
size_t bitSizeOfVarInt(int64_t value);
78
79
/**
80
 * Calculates bit size of Zserio varuint type.
81
 *
82
 * \param value Varuint value.
83
 *
84
 * \return Bit size of the current varuint value.
85
 */
86
size_t bitSizeOfVarUInt(uint64_t value);
87
88
/**
89
 * Calculates bit size of Zserio varsize type.
90
 *
91
 * \param value Varsize value.
92
 *
93
 * \return Bit size of the current varsize value.
94
 */
95
size_t bitSizeOfVarSize(uint32_t value);
96
97
/**
98
 * Calculates bit size of bytes.
99
 *
100
 * \param bytesValue Span representing the bytes value.
101
 *
102
 * \return Bit size of the given bytes value.
103
 */
104
size_t bitSizeOfBytes(Span<const uint8_t> bytesValue);
105
106
/**
107
 * Calculates bit size of the string.
108
 *
109
 * \param stringValue String view for which to calculate bit size.
110
 *
111
 * \return Bit size of the given string.
112
 */
113
size_t bitSizeOfString(StringView stringValue);
114
115
/**
116
 * Calculates bit size of the bit buffer.
117
 *
118
 * \param bitBuffer Bit buffer for which to calculate bit size.
119
 *
120
 * \return Bit size of the given bit buffer.
121
 */
122
template <typename ALLOC>
123
size_t bitSizeOfBitBuffer(const BasicBitBuffer<ALLOC>& bitBuffer)
124
205
{
125
205
    const size_t bitBufferSize = bitBuffer.getBitSize();
126
127
    // bit buffer consists of varsize for bit size followed by the bits
128
205
    return bitSizeOfVarSize(convertSizeToUInt32(bitBufferSize)) + bitBufferSize;
129
205
}
130
131
} // namespace zserio
132
133
#endif // ifndef ZSERIO_BITSIZEOF_CALCULATOR_H_INC