aboutsummaryrefslogblamecommitdiffstats
path: root/include/InMemoryBackend.h
blob: 55472a8e46824dec4cc3d833c06a0d27afb4abbb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                            





                                                                          



            




                                                                                  


                                                                  

      
#pragma once

#include "Api.h"
#include "IStorageBackend.h"

#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

/**
 * @file InMemoryBackend.h
 * @brief In-process KV storage backend backed by an unordered_map.
 *
 * Intended for unit tests where SQLite is not appropriate.  Data does not
 * survive process exit and is not thread-safe.
 *
 * Relation membership is tracked by the Merkle class, not this backend.
 */

namespace nt
{
    class NT_API InMemoryBackend : public IStorageBackend
    {
    public:
        std::string Put(std::vector<uint8_t> value) override;
        std::optional<std::vector<uint8_t>> Get(const std::string& hash) override;

    private:
        std::unordered_map<std::string, std::vector<uint8_t>> kv_;
    };
}