MCPcopy Create free account
hub / github.com/MihailRis/voxelcore / base64_encode

Method base64_encode

src/util/stringutil.cpp:236–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236std::string util::base64_encode(const ubyte* data, size_t size) {
237 std::stringstream ss;
238
239 size_t fullsegments = (size/3)*3;
240
241 size_t i = 0;
242 for (; i < fullsegments; i+=3) {
243 char output[] = "====";
244 base64_encode_(data+i, output);
245 ss << output;
246 }
247
248 ubyte ending[3] {};
249 for (; i < size; i++) {
250 ending[i-fullsegments] = data[i];
251 }
252 size_t trailing = size-fullsegments;
253 {
254 char output[] = "====";
255 output[0] = B64ABC[(ending[0] & 0b11111100) >> 2];
256 output[1] = B64ABC[((ending[0] & 0b11) << 4) |
257 ((ending[1] & 0b11110000) >> 4)];
258 if (trailing > 1)
259 output[2] = B64ABC[((ending[1] & 0b1111) << 2) |
260 ((ending[2] & 0b11000000) >> 6)];
261 if (trailing > 2)
262 output[3] = B64ABC[ending[2] & 0b111111];
263 ss << output;
264 }
265 return ss.str();
266}
267
268std::string util::mangleid(uint64_t value) {
269 // todo: use base64

Callers

nothing calls this directly

Calls 2

base64_encode_Function · 0.85
strMethod · 0.80

Tested by

no test coverage detected