MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / ByteStreamToBase32

Function ByteStreamToBase32

libi2pd/Base.cpp:261–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259 }
260
261 std::string ByteStreamToBase32 (const uint8_t * inBuf, size_t len)
262 {
263 std::string out;
264 out.reserve ((len * 8 + 4) / 5);
265 size_t pos = 1;
266 unsigned int bits = 8, tmp = inBuf[0];
267 while (bits > 0 || pos < len)
268 {
269 if (bits < 5)
270 {
271 if (pos < len)
272 {
273 tmp <<= 8;
274 tmp |= inBuf[pos] & 0xFF;
275 pos++;
276 bits += 8;
277 }
278 else // last byte
279 {
280 tmp <<= (5 - bits);
281 bits = 5;
282 }
283 }
284
285 bits -= 5;
286 int ind = (tmp >> bits) & 0x1F;
287 out.push_back ((ind < 26) ? (ind + 'a') : ((ind - 26) + '2'));
288 }
289 return out;
290 }
291}
292}

Callers 2

ToB33Method · 0.85
ToBase32Function · 0.85

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected