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