diff --git a/services/backup/src/Tools.cpp b/services/backup/src/Tools.cpp index 33938ed57..80762b414 100644 --- a/services/backup/src/Tools.cpp +++ b/services/backup/src/Tools.cpp @@ -1,57 +1,71 @@ #include "Tools.h" #include "GlobalConstants.h" #include "GlobalTools.h" #include #include #include #include #include namespace comm { namespace network { namespace tools { std::string generateRandomString(std::size_t length) { const std::string CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; thread_local std::random_device generator; std::uniform_int_distribution<> distribution(0, CHARACTERS.size() - 1); std::string random_string; for (std::size_t i = 0; i < length; ++i) { random_string += CHARACTERS[distribution(generator)]; } return random_string; } std::string generateHolder( const std::string &blobHash, const std::string &backupID, const std::string &resourceID) { return backupID + ID_SEPARATOR + resourceID + ID_SEPARATOR + blobHash + ID_SEPARATOR + tools::generateUUID(); } std::string validateAttachmentHolders(const std::string &holders) { std::stringstream stream(holders); std::string item; std::string result; while (std::getline(stream, item, ATTACHMENT_DELIMITER)) { if (item.empty()) { throw std::runtime_error("empty holder detected"); } result += item; result += ATTACHMENT_DELIMITER; } if (result.empty()) { throw std::runtime_error("parse attachment holders failed"); } return result; } +int charPtrToInt(const char *str) { + unsigned int intValue; + std::stringstream strValue; + + strValue << str; + strValue >> intValue; + + return intValue; +} + +size_t getBlobPutField(blob::PutRequest::DataCase field) { + return static_cast(field); +} + } // namespace tools } // namespace network } // namespace comm diff --git a/services/backup/src/Tools.h b/services/backup/src/Tools.h index 619d66398..40893234c 100644 --- a/services/backup/src/Tools.h +++ b/services/backup/src/Tools.h @@ -1,20 +1,26 @@ #pragma once +#include + #include namespace comm { namespace network { namespace tools { std::string generateRandomString(std::size_t length = 20); std::string generateHolder( const std::string &blobHash, const std::string &backupID, const std::string &resourceID = ""); std::string validateAttachmentHolders(const std::string &holders); +int charPtrToInt(const char *str); + +size_t getBlobPutField(blob::PutRequest::DataCase field); + } // namespace tools } // namespace network } // namespace comm