-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chang Guo
committed
Jan 10, 2024
1 parent
aa99e9e
commit 95ec36d
Showing
7 changed files
with
380 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Created by cguo51 on 1/8/24. | ||
// | ||
#include "adios2/toolkit/cache/KVCacheBase64.h" | ||
//namespace adios2 | ||
//{ | ||
std::string base64Encode(const std::vector<char> &data) | ||
{ | ||
BIO *bio, *b64; | ||
BUF_MEM *bptr; | ||
|
||
b64 = BIO_new(BIO_f_base64()); | ||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); | ||
bio = BIO_new(BIO_s_mem()); | ||
bio = BIO_push(b64, bio); | ||
|
||
BIO_write(bio, data.data(), static_cast<int>(data.size())); | ||
BIO_flush(bio); | ||
BIO_get_mem_ptr(bio, &bptr); | ||
|
||
std::string result(bptr->data, bptr->length); | ||
|
||
BIO_free_all(bio); | ||
|
||
return result; | ||
} | ||
|
||
std::vector<char> base64Decode(const std::string &encoded) | ||
{ | ||
BIO *bio, *b64; | ||
std::vector<char> result(encoded.size()); | ||
|
||
b64 = BIO_new(BIO_f_base64()); | ||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); | ||
bio = BIO_new_mem_buf(encoded.c_str(), static_cast<int>(encoded.size())); | ||
bio = BIO_push(b64, bio); | ||
|
||
int decodedLength = BIO_read(bio, result.data(), static_cast<int>(result.size())); | ||
result.resize(decodedLength); | ||
|
||
BIO_free_all(bio); | ||
|
||
return result; | ||
} | ||
|
||
template <typename T> | ||
void encodeVector(const std::vector<T> &vec, std::string &encodedString) | ||
{ | ||
std::vector<char> rawData(reinterpret_cast<const char *>(vec.data()), | ||
reinterpret_cast<const char *>(vec.data() + vec.size())); | ||
encodedString = base64Encode(rawData); | ||
} | ||
|
||
template <typename T> | ||
void decodeVector(const std::string &str, std::vector<T> &vec) | ||
{ | ||
std::vector<char> rawData = base64Decode(str); | ||
|
||
// Calculate the number of elements based on the total size of rawData | ||
size_t numElements = rawData.size() / sizeof(T); | ||
|
||
// Construct the result vector using the correct size | ||
vec(reinterpret_cast<const T *>(rawData.data()), | ||
reinterpret_cast<const T *>(rawData.data() + numElements * sizeof(T))); | ||
} | ||
//}; // adios2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Created by cguo51 on 1/8/24. | ||
// | ||
#ifndef ADIOS2_KVCACHEBASE64_H | ||
#define ADIOS2_KVCACHEBASE64_H | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <openssl/bio.h> | ||
#include <openssl/evp.h> | ||
#include <openssl/buffer.h> | ||
//namespace adios2 | ||
//{ | ||
|
||
std::string base64Encode(const std::vector<char>& data); | ||
|
||
std::vector<char> base64Decode(const std::string& encoded); | ||
|
||
template <typename T> | ||
void encodeVector(const std::vector<T>& vec, std::string& encodedString); | ||
|
||
template <typename T> | ||
void decodeVector(const std::string& str, std::vector<T>& vec); | ||
//}; // adios2 | ||
#endif // ADIOS2_KVCACHEBASE64_H |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.