From fb8f096b51cb518f81f558d4e0580a3652d104c1 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Thu, 25 Jun 2026 14:26:34 +0200 Subject: server: drop the throwaway buffer in the base64 float path --- tools/server/encode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'tools/server/encode.c') diff --git a/tools/server/encode.c b/tools/server/encode.c index 1674774..90e8229 100644 --- a/tools/server/encode.c +++ b/tools/server/encode.c @@ -29,15 +29,11 @@ signed char quantize_int8_tanh(float x) { char *encode_embedding(const float *emb, int dims, const char *encoding) { if (!strcmp(encoding, "base64")) { /* OpenAI/DashScope (Qwen3): base64 of the raw little-endian float32 - * vector. Copy through a byte buffer instead of reinterpret-casting the - * float pointer; x86_64 and aarch64 are little-endian, so the bytes - * match the wire format with no swap. */ + * vector. x86_64 and aarch64 are little-endian, so the float bytes are + * already the wire format; read them directly through an unsigned char + * pointer. */ size_t nbytes = (size_t)dims * sizeof(float); - unsigned char *buf = xmalloc(nbytes); - memcpy(buf, emb, nbytes); - char *out = base64_encode(buf, nbytes); - free(buf); - return out; + return base64_encode((const unsigned char *)emb, nbytes); } if (!strcmp(encoding, "base64_binary")) { size_t bytes = (size_t)dims / 8; -- cgit v1.3.1