MCPcopy Create free account
hub / github.com/Tracktion/choc / decodeVariableLengthInt

Function decodeVariableLengthInt

choc/memory/choc_VariableLengthEncoding.h:105–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104template <typename IntegerType>
105IntegerType decodeVariableLengthInt (const void* encodedData, size_t availableSize, size_t& bytesUsed)
106{
107 typename std::make_unsigned<IntegerType>::type result = 0;
108 auto source = static_cast<const uint8_t*> (encodedData);
109 size_t size = 0;
110
111 for (uint32_t bit = 0;; bit += 7)
112 {
113 if (size == availableSize)
114 {
115 bytesUsed = 0;
116 return 0;
117 }
118
119 auto byte = source[size++];
120 result |= (static_cast<typename std::make_unsigned<IntegerType>::type> (byte & 127) << bit);
121
122 if (byte >> 7)
123 continue;
124
125 bytesUsed = size;
126 return static_cast<IntegerType> (result);
127 }
128}
129
130template <typename IntegerType>
131IntegerType zigzagEncode (IntegerType n)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected