MCPcopy Create free account
hub / github.com/apache/arrow / gdv_fn_base64_encode_binary

Function gdv_fn_base64_encode_binary

cpp/src/gandiva/gdv_function_stubs.cc:236–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236GANDIVA_EXPORT
237const char* gdv_fn_base64_encode_binary(int64_t context, const char* in, int32_t in_len,
238 int32_t* out_len) {
239 if (in_len < 0) {
240 char err_msg[96];
241 snprintf(err_msg, sizeof(err_msg),
242 "BASE64: input length must be non-negative, got %d", in_len);
243 gdv_fn_context_set_error_msg(context, err_msg);
244 *out_len = 0;
245 return "";
246 }
247 if (in_len == 0) {
248 *out_len = 0;
249 return "";
250 }
251 // use arrow method to encode base64 string
252 std::string encoded_str = arrow::util::base64_encode(std::string_view(in, in_len));
253 *out_len = static_cast<int32_t>(encoded_str.length());
254 // allocate memory for response
255 char* ret = reinterpret_cast<char*>(
256 gdv_fn_context_arena_malloc(context, static_cast<int32_t>(*out_len)));
257 if (ret == nullptr) {
258 gdv_fn_context_set_error_msg(context, "Could not allocate memory");
259 *out_len = 0;
260 return "";
261 }
262 memcpy(ret, encoded_str.data(), *out_len);
263 return ret;
264}
265
266GANDIVA_EXPORT
267const char* gdv_fn_base64_decode_utf8(int64_t context, const char* in, int32_t in_len,

Callers 1

TESTFunction · 0.85

Calls 4

lengthMethod · 0.45
dataMethod · 0.45

Tested by 1

TESTFunction · 0.68