FastLED 3.10.8
Loading...
Searching...
No Matches

◆ base64_encode()

fl::string fl::base64_encode ( fl::span< const fl::u8 > data)

Definition at line 23 of file base64.cpp.hpp.

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

References FL_NO_EXCEPT, and fl::basic_string::reserve().

Referenced by fl::detail::TypeToJson< fl::vector< fl::u8 > >::convert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: