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:241–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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