aboutsummaryrefslogblamecommitdiffstats
path: root/src/InMemoryBackend.cpp
blob: 4649da08c7aea4a85058e7aec2f0c24510e6c1ab (plain) (tree)
1
2
3
4
5
6


                            


            









                                                                                          
                                                 

                          
 
#include "InMemoryBackend.h"

#include <picosha2.h>

namespace nt
{
    std::string InMemoryBackend::Put(std::vector<uint8_t> value)
    {
        const std::string hash = picosha2::hash256_hex_string(value.begin(), value.end());
        kv_.emplace(hash, std::move(value));
        return hash;
    }

    std::optional<std::vector<uint8_t>> InMemoryBackend::Get(const std::string& hash)
    {
        auto it = kv_.find(hash);
        if (it == kv_.end()) return std::nullopt;
        return it->second;
    }
}