1#ifndef CODEX_BASE64_CMD_H
2#define CODEX_BASE64_CMD_H
17 std::invocable<T, std::string_view, char*>;
21 std::invoke_result_t<T, std::string_view, char*>,
27template<auto S, std::
integral T>
36template<std::
size_t N, std::
size_t D>
43template<auto S, std::
integral T>
45 {
return S * ((
n +
S - 1) /
S); }
47template<std::
size_t N, std::
size_t D>
49 {
return N * ((
n + D - 1) / D); }
54 stdin, stdout, 3, in, out,
55 [&in, &out, &
f](std::size_t
n) {
56 std::invoke(
f, std::string_view{in.data(),
n}, out.data());
64 stdin, stdout, 4, in, out,
65 [&in, &out, &
f](std::size_t
n) {
67 std::invoke(
f, std::string_view{in.data(),
n}, out.data());
69 return (std::cerr <<
"invalid input\n"), std::size_t{};
70 return static_cast<std::size_t
>(ret - out.data());
76 const bool encode = !argv[1];
77 if(!encode && strcmp(argv[1],
"-d") != 0) {
78 std::cerr <<
"invalid command: " << argv[1] <<
'\n';
84#define BASE64_MAIN(T) \
85 int main(int, const char **argv) { return !cmd_main<T>(argv); }
#define f(x)
Definition 5.c:2
bool process_blocks(FILE *in, FILE *out, std::size_t size, std::span< char > in_s, std::span< char > out_s, ProcessingFunc auto f)
Reads block of a specific size, processes them, and outputs.
Definition block.hpp:80
bool cmd_encode(EncodeFunc auto f)
Definition cmd.hpp:51
bool cmd_decode(DecodeFunc auto f)
Definition cmd.hpp:61
bool cmd_main(const char **argv, EncodeFunc auto ef, DecodeFunc auto df)
constexpr std::size_t output_size(std::size_t n)
Calculates the size of the buffer required for the output, rounding up.
Definition cmd.hpp:48
constexpr T round_to_block_size(T n)
Rounds an integral value to a given block size, always towards infinity.
Definition cmd.hpp:44
constexpr std::size_t BUF_SIZE
Number of 3- or 4-byte blocks in the input buffer.
Definition cmd.hpp:14
codex::refl::field_tuple_t< E > T
Definition soa.cpp:9
Definition reflexpr.cpp:168