From 0538aad8a2cd3c47100211250953ac1a4148739d Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 10 Oct 2024 21:02:42 +0200 Subject: [PATCH] included base64sve in benchmark --- CMakeLists.txt | 1 + src/base64sve/base64sve.cpp | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/base64sve/base64sve.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b4b3cd..8f30ca8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ aux_source_directory(./src/boost CTR_SOURCES) add_subdirectory(./libs/base64sve/) include_directories(libs/base64sve/lib/include) +AUX_SOURCE_DIRECTORY(./src/base64sve CTR_SOURCES) set_source_files_properties( ${CTR_SOURCES} PROPERTIES LANGUAGE CXX ) set_source_files_properties( ${C_SOURCES} PROPERTIES LANGUAGE C ) diff --git a/src/base64sve/base64sve.cpp b/src/base64sve/base64sve.cpp new file mode 100644 index 0000000..b23bbde --- /dev/null +++ b/src/base64sve/base64sve.cpp @@ -0,0 +1,55 @@ +#include +#include "../Base64SurveyRegistry.hpp" +#include "base64sve/lib/include/base64sve.h" + +struct BASE64SVE_Adapt +{ + + static constexpr inline size_t GetDecodeExpectedLen(size_t inLen) noexcept + { + return ((inLen + 3) / 4) * 3; + } + + static constexpr inline size_t GetEncodeLen(size_t inLen) noexcept + { + return ((inLen + 2) / 3) * 4; + } + + static std::string encode(void (*func)(void *in, char *out, size_t inlen), const std::string &bytes) + { + size_t encLen = GetEncodeLen(bytes.length()); + std::string encoded; + encoded.resize(encLen); + func((void *)&bytes[0], &encoded[0], bytes.length()); + // void base64_encode(void *input, char *output, size_t length); + + return encoded; + } + + static std::string decode(void (*func)(char *in, void *out, size_t inlen, size_t *decoded_length), const std::string &encoded) + { + std::string decoded; + decoded.resize(GetDecodeExpectedLen(encoded.length())); + size_t dLen = 0; + func((char *)&encoded[0], (int8_t *)&decoded[0], (size_t)encoded.length(), &dLen); + // void base64_decode(char *base64_data, void *output, size_t encoded_length, size_t *decoded_length); + decoded.resize(dLen); + return decoded; + } +}; + +struct base64sve +{ + std::string encode(const std::string &bytes) + { + return BASE64SVE_Adapt::encode(base64_encode, bytes); + } + + std::string decode(const std::string &base64) + { + return BASE64SVE_Adapt::decode(base64_decode, base64); + } +}; + +BASE64_REGISTER_ENCODER(base64sve); +BASE64_REGISTER_DECODER(base64sve); \ No newline at end of file