MCPcopy Create free account
hub / github.com/FastLED/FastLED / base64_encode

Function base64_encode

src/fl/remote/rpc/base64.cpp.hpp:22–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20} // namespace
21
22fl::string base64_encode(fl::span<const fl::u8> data) {
23 fl::string out;
24 if (data.empty()) return out;
25
26 fl::size encoded_len = 4 * ((data.size() + 2) / 3);
27 out.reserve(encoded_len);
28
29 fl::size i = 0;
30 fl::size len = data.size();
31
32 while (i + 2 < len) {
33 fl::u32 triple = (fl::u32(data[i]) << 16) |
34 (fl::u32(data[i + 1]) << 8) |
35 fl::u32(data[i + 2]);
36 out += kBase64Chars[(triple >> 18) & 0x3F];
37 out += kBase64Chars[(triple >> 12) & 0x3F];
38 out += kBase64Chars[(triple >> 6) & 0x3F];
39 out += kBase64Chars[triple & 0x3F];
40 i += 3;
41 }
42
43 // Handle remaining bytes
44 if (i < len) {
45 fl::u32 triple = fl::u32(data[i]) << 16;
46 if (i + 1 < len) {
47 triple |= fl::u32(data[i + 1]) << 8;
48 }
49 out += kBase64Chars[(triple >> 18) & 0x3F];
50 out += kBase64Chars[(triple >> 12) & 0x3F];
51 if (i + 1 < len) {
52 out += kBase64Chars[(triple >> 6) & 0x3F];
53 } else {
54 out += '=';
55 }
56 out += '=';
57 }
58
59 return out;
60}
61
62fl::vector<fl::u8> base64_decode(const fl::string& encoded) {
63 fl::vector<fl::u8> out;

Callers 3

convertMethod · 0.85
FL_TEST_FILEFunction · 0.85
FL_TEST_FILEFunction · 0.85

Calls 4

u32Enum · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected