2018-06-12 17:29:22 +08:00
|
|
|
#pragma once
|
|
|
|
|
Extract communication to static library
Summary:
Session specifics have been move out of the Bolt `executing` state, and
are accessed via pure virtual Session type. Our server is templated on
the session and we are setting the concrete type, so there should be no
virtual call overhead. Abstract Session is used to indicate the
interface, this could have also been templated, but the explicit
interface definition makes it clearer.
Specific session implementation for running Memgraph is now implemented
in memgraph_bolt, which instantiates the concrete session type. This may
not be 100% appropriate place, but Memgraph specific session isn't
needed anywhere else.
Bolt/communication tests now use a dummy session and depend only on
communication, which significantly improves test run times.
All these changes make the communication a library which doesn't depend
on storage nor the database. Only shared connection points, which aren't
part of the base communication library are:
* glue/conversion -- which converts between storage and bolt types, and
* communication/result_stream_faker -- templated, but used in tests and query/repl
Depends on D1453
Reviewers: mferencevic, buda, mtomic, msantl
Reviewed By: mferencevic, mtomic
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D1456
2018-07-10 22:18:19 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-06-12 17:29:22 +08:00
|
|
|
|
|
|
|
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
|