diff --git a/velox/common/encode/Base64.cpp b/velox/common/encode/Base64.cpp index 30520880745a3..e866e6ea99d9f 100644 --- a/velox/common/encode/Base64.cpp +++ b/velox/common/encode/Base64.cpp @@ -156,8 +156,9 @@ static_assert( // "kBase64UrlReverseIndexTable has incorrect entries."); // Implementation of Base64 encoding and decoding functions. +// static template -/* static */ std::string Base64::encodeImpl( +std::string Base64::encodeImpl( const T& data, const Base64::Charset& charset, bool include_pad) { @@ -184,24 +185,25 @@ size_t Base64::calculateEncodedSize(size_t size, bool withPadding) { } // static -void Base64::encode(std::string_view data, char* output) { - encodeImpl(data, kBase64Charset, true, output); +Status Base64::encode(std::string_view data, char* output) { + return encodeImpl(data, kBase64Charset, true, output); } // static -void Base64::encodeUrl(std::string_view data, char* output) { - encodeImpl(data, kBase64UrlCharset, true, output); +Status Base64::encodeUrl(std::string_view data, char* output) { + return encodeImpl(data, kBase64UrlCharset, true, output); } +// static template -/* static */ void Base64::encodeImpl( +Status Base64::encodeImpl( const T& data, const Base64::Charset& charset, bool include_pad, char* out) { auto len = data.size(); if (len == 0) { - return; + return Status::OK(); } auto wp = out; @@ -241,6 +243,7 @@ template } } } + return Status::OK(); } // static @@ -249,7 +252,7 @@ std::string Base64::encode(std::string_view text) { } // static -std::string Base64::encode(std::string_view data, size_t len) { +std::string Base64::encode(std::string_view data, size_t /*len*/) { return encodeImpl(data, kBase64Charset, true); } diff --git a/velox/common/encode/Base64.h b/velox/common/encode/Base64.h index 0500bc75852cf..aeac7275a3686 100644 --- a/velox/common/encode/Base64.h +++ b/velox/common/encode/Base64.h @@ -24,6 +24,7 @@ #include #include "velox/common/base/GTestMacros.h" +#include "velox/common/base/Status.h" namespace facebook::velox::encoding { @@ -56,7 +57,7 @@ class Base64 { /// Encodes the specified number of characters from the 'data' and writes the /// result to the 'output'. The output must have enough space, e.g. as /// returned by the calculateEncodedSize(). - static void encode(std::string_view data, char* output); + static Status encode(std::string_view data, char* output); /// Decodes the specified encoded text. static std::string decode(std::string_view encoded); @@ -75,7 +76,7 @@ class Base64 { /// Encodes the specified number of characters from the 'data' and writes the /// result to the 'output' using URL encoding. The output must have enough /// space as returned by the calculateEncodedSize(). - static void encodeUrl(std::string_view data, char* output); + static Status encodeUrl(std::string_view data, char* output); /// Encodes the specified IOBuf data using URL encoding. static std::string encodeUrl(const folly::IOBuf* data); @@ -130,7 +131,7 @@ class Base64 { // Encodes the specified data using the provided charset. template - static void encodeImpl( + static Status encodeImpl( const T& data, const Charset& charset, bool include_pad, diff --git a/velox/functions/prestosql/BinaryFunctions.h b/velox/functions/prestosql/BinaryFunctions.h index 6bb141408c0ca..a6d1096ee4585 100644 --- a/velox/functions/prestosql/BinaryFunctions.h +++ b/velox/functions/prestosql/BinaryFunctions.h @@ -274,13 +274,12 @@ template struct ToBase64Function { VELOX_DEFINE_FUNCTION_TYPES(T); - FOLLY_ALWAYS_INLINE void call( - out_type& result, - const arg_type& input) { + FOLLY_ALWAYS_INLINE Status + call(out_type& result, const arg_type& input) { std::string_view inputString( reinterpret_cast(input.data()), input.size()); result.resize(encoding::Base64::calculateEncodedSize(input.size())); - encoding::Base64::encode(inputString, result.data()); + return encoding::Base64::encode(inputString, result.data()); } }; @@ -318,13 +317,12 @@ template struct ToBase64UrlFunction { VELOX_DEFINE_FUNCTION_TYPES(T); - FOLLY_ALWAYS_INLINE void call( - out_type& result, - const arg_type& input) { + FOLLY_ALWAYS_INLINE Status + call(out_type& result, const arg_type& input) { std::string_view inputString( reinterpret_cast(input.data()), input.size()); result.resize(encoding::Base64::calculateEncodedSize(input.size())); - encoding::Base64::encodeUrl(inputString, result.data()); + return encoding::Base64::encodeUrl(inputString, result.data()); } };