JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
base64.h File Reference

High-level Base64 and Base64URL serialization interface for the JH Toolkit. More...

#include <cstdint>
#include <cstddef>
#include <string>
#include <vector>
#include <stdexcept>
#include "jh/pods/string_view.h"
#include "jh/pods/bytes_view.h"
#include "jh/macros/header_begin.h"
#include "jh/macros/header_end.h"

Go to the source code of this file.

Namespaces

namespace  jh::serio
 Aggregated entry point for serialization and codec utilities.
namespace  jh::serio::base64
 Implements standard Base64 (RFC 4648 §4) encoding and decoding.
namespace  jh::serio::base64url
 Implements Base64URL (RFC 4648 §5) — the URL-safe variant of Base64.

Functions

std::string jh::serio::base64::encode (const std::uint8_t *data, std::size_t len)
 Encode raw binary data into a Base64 string.
std::vector< std::uint8_t > jh::serio::base64::decode (const std::string &input)
 Decode a Base64 string into a byte vector.
jh::pod::bytes_view jh::serio::base64::decode (const std::string &input, std::vector< std::uint8_t > &output_buffer)
 Decode a Base64-encoded string into raw bytes.
jh::pod::string_view jh::serio::base64::decode (const std::string &input, std::string &output_buffer)
 Decode a Base64-encoded string into textual data.
std::string jh::serio::base64url::encode (const std::uint8_t *data, std::size_t len, bool pad=false)
 Encode raw binary data into a Base64URL string.
std::vector< std::uint8_t > jh::serio::base64url::decode (const std::string &input)
 Decode a Base64URL string into a byte vector.
jh::pod::bytes_view jh::serio::base64url::decode (const std::string &input, std::vector< std::uint8_t > &output_buffer)
 Decode a Base64URL-encoded string into raw bytes.
jh::pod::string_view jh::serio::base64url::decode (const std::string &input, std::string &output_buffer)
 Decode a Base64URL-encoded string into textual data.

Detailed Description

High-level Base64 and Base64URL serialization interface for the JH Toolkit.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header provides a modern, type-safe, and constexpr-enabled Base64 / Base64URL codec implementation. It is part of the JH Toolkit Serialization I/O module (shortened as jh::serio), and serves as the first officially supported serialization format within the toolkit.

Design overview

  • Implements Base64 (RFC 4648 §4) and Base64URL (RFC 4648 §5).
  • Cross-language interoperable binary-to-text serialization format.
  • All encoding/decoding logic relies on constexpr-verified lookup tables.
  • All interfaces perform pre-validation and throw clear std::runtime_error on error.
  • Fully portable across compilers and platforms.

Usage

std::vector<std::uint8_t> raw = {0x01, 0x02, 0x03};
std::string encoded = jh::serio::base64::encode(raw.data(), raw.size());
auto decoded = jh::serio::base64::decode(encoded);
std::string encode(const std::uint8_t *data, std::size_t len)
Encode raw binary data into a Base64 string.
std::vector< std::uint8_t > decode(const std::string &input)
Decode a Base64 string into a byte vector.
Note
This header participates in the Dual-Mode Header system of the JH Toolkit.
  • Linked through jh::jh-toolkit — the module behaves as a header-only implementation compiled in user translation units.
  • Linked through jh::jh-toolkit-static — the module uses a precompiled implementation built with aggressive optimization (typically -O3).
This design allows fast incremental builds while preserving the option of using a fully optimized static implementation.
Version
1.4.1
Date
2025