From b8148f216a8c3ca990243d1f2208bd3a62ee9d9c Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Thu, 25 Jun 2026 15:27:41 +0200 Subject: server: encode base64 embeddings directly into the response buffer --- tools/server/base64.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/server/base64.h') diff --git a/tools/server/base64.h b/tools/server/base64.h index 88d88b3..2e77e2d 100644 --- a/tools/server/base64.h +++ b/tools/server/base64.h @@ -3,8 +3,18 @@ #include -/* Standard base64 (with '=' padding) of n bytes. Returns a NUL-terminated heap - * string the caller frees; die-on-OOM, so it never returns NULL. */ +/* Standard base64 (with '=' padding). */ + +/* Number of base64 characters for n input bytes, excluding any NUL. Aborts + * (die-on-OOM) if n is so large the length would overflow. */ +size_t base64_encoded_len(size_t n); + +/* Encode n bytes of src as base64 into dst, writing exactly base64_encoded_len(n) + * bytes and no NUL terminator; dst must have room for that many bytes. */ +void base64_encode_to(char *dst, const unsigned char *src, size_t n); + +/* Convenience wrapper: returns a NUL-terminated heap string the caller frees; + * die-on-OOM, so it never returns NULL. */ char *base64_encode(const unsigned char *src, size_t n); #endif /* FFWD_BASE64_H */ -- cgit v1.3.1