Summary: This diff splits single node and distributed storage from each other. Currently all of the storage code is copied into two directories (one single node, one distributed). The logic used in the storage implementation isn't touched, it will be refactored in following diffs. To clean the working directory after this diff you should execute: ``` rm database/state_delta.capnp rm database/state_delta.hpp rm storage/concurrent_id_mapper_rpc_messages.capnp rm storage/concurrent_id_mapper_rpc_messages.hpp ``` Reviewers: teon.banek, buda, msantl Reviewed By: teon.banek, msantl Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D1625
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace storage {
|
|
|
|
/**
|
|
* Buffer used for serialization of disk properties. The buffer
|
|
* implements a template parameter Buffer interface from BaseEncoder
|
|
* and Decoder classes for bolt serialization.
|
|
*/
|
|
class PODBuffer {
|
|
public:
|
|
PODBuffer() = default;
|
|
explicit PODBuffer(const std::string &s) {
|
|
buffer = std::vector<uint8_t>{s.begin(), s.end()};
|
|
}
|
|
|
|
/**
|
|
* Writes data to buffer
|
|
*
|
|
* @param data - Pointer to data to be written.
|
|
* @param len - Data length.
|
|
*/
|
|
void Write(const uint8_t *data, size_t len) {
|
|
for (size_t i = 0; i < len; ++i) buffer.push_back(data[i]);
|
|
}
|
|
|
|
/**
|
|
* Reads raw data from buffer.
|
|
*
|
|
* @param data - pointer to where data should be stored.
|
|
* @param len - data length
|
|
* @return - True if successful, False otherwise.
|
|
*/
|
|
bool Read(uint8_t *data, size_t len) {
|
|
if (len > buffer.size()) return false;
|
|
memcpy(data, buffer.data(), len);
|
|
buffer.erase(buffer.begin(), buffer.begin() + len);
|
|
return true;
|
|
}
|
|
|
|
std::vector<uint8_t> buffer;
|
|
};
|
|
|
|
} // namespace storage
|