Implementation:1ay1 Agentty Base64 Codec
| Knowledge Sources | |
|---|---|
| Domains | Encoding |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Standard RFC 4648 base64 codec (`+`/`/` alphabet, `=` padding) used at the Anthropic-API write boundary and persistence-save boundary.
Description
The agentty::util::base64 module is the standard RFC 4648 base64 codec — NOT base64url. Uses `+` and `/` for the 62/63 codes and `=` padding to a multiple of 4. Used at the Anthropic-API write boundary (image content blocks expect standard base64) and at the persistence-save boundary (on-disk thread JSON carries raw image bytes losslessly).
Kept distinct from `auth.hpp`'s `base64url_no_pad` which uses the URL-safe alphabet (`-_`) and no padding for OAuth/PKCE — Anthropic's image API rejects that.
Usage
Import this when you need to: base64-encode image bytes for the Anthropic API, encode/decode base64 for persistence, or handle standard base64 (not URL-safe).
Code Reference
Source Location
- Repository: 1ay1_Agentty
- File: include/agentty/util/base64.hpp
- Lines: 1-30
Signature
namespace agentty::util {
[[nodiscard]] std::string base64_encode(const unsigned char* data, std::size_t len);
[[nodiscard]] inline std::string base64_encode(std::string_view bytes);
// Returns empty string on malformed input. Skips whitespace;
// tolerates missing padding (rounds up to a multiple of 4).
[[nodiscard]] std::string base64_decode(std::string_view encoded);
}
Import
#include "agentty/util/base64.hpp"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data/len | unsigned char*, size_t | Yes (encode) | Raw bytes to encode |
| encoded | std::string_view | Yes (decode) | Base64 string to decode |
Outputs
| Name | Type | Description |
|---|---|---|
| base64_encode() | std::string | Standard base64 (+/, = padded) |
| base64_decode() | std::string | Raw bytes; empty on malformed input |
Usage Examples
Encode Image for Anthropic API
#include "agentty/util/base64.hpp"
std::string image_bytes = read_file("screenshot.png");
auto b64 = agentty::util::base64_encode(image_bytes);
// Use in Anthropic image content block:
// {"type": "image", "source": {"type": "base64", "media_type": "image/png",
// "data": "<b64>"}}