1#ifndef CODEX_BASE64_BASE64_H
2#define CODEX_BASE64_BASE64_H
9using namespace std::literals;
17consteval char lut_idx(std::string_view lut,
char c) {
18 const auto p = lut.data();
19 const auto n =
static_cast<char>(lut.size());
20 return static_cast<char>(std::distance(
p, std::find(
p,
p +
n,
c)));
31 std::array<char, std::numeric_limits<unsigned char>::max()> ret = {};
32 for(std::size_t i = 0; i < ret.size(); ++i)
33 ret[i] =
lut_idx(lut,
static_cast<char>(i));
45 static constexpr auto lut =
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"sv;
60 static void encode(std::string_view src,
char *dst);
66 static char *
decode(std::string_view src,
char *dst);
consteval auto gen_rlut(std::string_view lut)
Creates an array that contains the position of every byte in lut.
Definition base64.hpp:30
consteval char lut_idx(std::string_view lut, char c)
Performs a reverse look-up.
Definition base64.hpp:17
Encodes and decodes byte streams using base64.
Definition base64.hpp:41
static char * decode(std::string_view src, char *dst)
Decodes a byte stream.
Definition base64.cpp:74
static constexpr auto rlut
Reverse look-up table for encoding, maps every possible character value to a byte or zero.
Definition base64.hpp:51
static void encode(std::string_view src, char *dst)
Encodes a byte stream.
Definition base64.cpp:59
static constexpr auto lut
Look-up table for encoding, maps input 6-bit values to output characters.
Definition base64.hpp:45
#define p()
Definition std2.c:11
consteval auto gen_rlut(std::string_view lut)
Creates an array that contains the position of every byte in lut.
Definition base64.hpp:30