From a8a167cb206f6c66e52ab4e92e0939e91b8dfed8 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Fri, 21 Feb 2025 16:18:47 +0100 Subject: ArtifactBlob: Convert to a class --- src/buildtool/common/artifact_blob.hpp | 55 ++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'src/buildtool/common/artifact_blob.hpp') diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index 57d99f7c..3fc4ba23 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -24,22 +24,51 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/utils/cpp/hash_combine.hpp" -struct ArtifactBlob final { - ArtifactBlob(ArtifactDigest digest, - std::string mydata, - bool is_exec) noexcept - : digest{std::move(digest)}, - data{std::make_shared(std::move(mydata))}, - is_exec{is_exec} {} +class ArtifactBlob final { + public: + explicit ArtifactBlob(ArtifactDigest digest, + std::string content, + bool is_exec) noexcept + : digest_{std::move(digest)}, + content_{std::make_shared(std::move(content))}, + is_executable_{is_exec} {} [[nodiscard]] auto operator==(ArtifactBlob const& other) const noexcept -> bool { - return digest == other.digest and is_exec == other.is_exec; + return digest_ == other.digest_ and + is_executable_ == other.is_executable_; } - ArtifactDigest digest; - std::shared_ptr data; - bool is_exec = false; + /// \brief Obtain the digest of the content. + [[nodiscard]] auto GetDigest() const noexcept -> ArtifactDigest const& { + return digest_; + } + + /// \brief Obtain the size of the content. + [[nodiscard]] auto GetContentSize() const noexcept -> std::size_t { + return content_->size(); + } + + /// \brief Read the content from source. + [[nodiscard]] auto ReadContent() const noexcept + -> std::shared_ptr { + return content_; + } + + /// \brief Set executable permission. + void SetExecutable(bool is_executable) noexcept { + is_executable_ = is_executable; + } + + /// \brief Obtain executable permission. + [[nodiscard]] auto IsExecutable() const noexcept -> bool { + return is_executable_; + } + + private: + ArtifactDigest digest_; + std::shared_ptr content_; + bool is_executable_; }; namespace std { @@ -48,8 +77,8 @@ struct hash { [[nodiscard]] auto operator()(ArtifactBlob const& blob) const noexcept -> std::size_t { std::size_t seed{}; - hash_combine(&seed, blob.digest); - hash_combine(&seed, blob.is_exec); + hash_combine(&seed, blob.GetDigest()); + hash_combine(&seed, blob.IsExecutable()); return seed; } }; -- cgit v1.2.3