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

Function base64_decode

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

Source from the content-addressed store, hash-verified

60}
61
62fl::vector<fl::u8> base64_decode(const fl::string& encoded) {
63 fl::vector<fl::u8> out;
64 if (encoded.empty()) return out;
65
66 fl::size len = encoded.size();
67
68 // Validate length is multiple of 4
69 if (len % 4 != 0) return out;
70
71 fl::size out_len = (len / 4) * 3;
72 if (len >= 1 && encoded[len - 1] == '=') out_len--;
73 if (len >= 2 && encoded[len - 2] == '=') out_len--;
74 out.reserve(out_len);
75
76 for (fl::size i = 0; i < len; i += 4) {
77 int a = base64_char_index(encoded[i]);
78 int b = base64_char_index(encoded[i + 1]);
79 int c = (encoded[i + 2] == '=') ? 0 : base64_char_index(encoded[i + 2]);
80 int d = (encoded[i + 3] == '=') ? 0 : base64_char_index(encoded[i + 3]);
81
82 if (a < 0 || b < 0 || c < 0 || d < 0) {
83 return fl::vector<fl::u8>(); // invalid character
84 }
85
86 fl::u32 triple = (fl::u32(a) << 18) | (fl::u32(b) << 12) |
87 (fl::u32(c) << 6) | fl::u32(d);
88
89 out.push_back((triple >> 16) & 0xFF);
90 if (encoded[i + 2] != '=') {
91 out.push_back((triple >> 8) & 0xFF);
92 }
93 if (encoded[i + 3] != '=') {
94 out.push_back(triple & 0xFF);
95 }
96 }
97
98 return out;
99}
100
101} // namespace fl

Callers 2

convertMethod · 0.85
FL_TEST_FILEFunction · 0.85

Calls 6

base64_char_indexFunction · 0.85
u32Enum · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected