FastLED 3.9.15
Loading...
Searching...
No Matches

◆ base64_encode()

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

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

22 {
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}
void reserve(fl::size newCapacity) FL_NOEXCEPT
constexpr bool empty() const FL_NOEXCEPT
Definition span.h:510
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458

References fl::span< T, Extent >::empty(), fl::basic_string::reserve(), and fl::span< T, Extent >::size().

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: