1#ifndef joedb_rpc_Client_declared
2#define joedb_rpc_Client_declared
22 const std::vector<Signature> &signatures;
32 lock->write((
const char *)h.data(), h.size() *
sizeof h[0]);
33 lock->read(buffer.
data, 9);
37 if (buffer.
read<
char>() !=
'H')
39 session_id = buffer.
read<int64_t>();
51 const int64_t max_message_size;
53 void throw_invalid_size()
62 const std::vector<Signature> &signatures,
63 std::chrono::milliseconds keep_alive_interval = std::chrono::milliseconds(0),
64 int64_t max_message_size = 1 << 24
67 signatures(signatures),
68 keep_alive(*this, keep_alive_interval),
69 max_message_size(max_message_size)
79 auto &signature = signatures[procedure_id];
83 const int64_t from = int64_t(signature.prolog.size());
84 const int64_t until = file.
get_size();
87 buffer.
write<
char>(
'C');
88 buffer.
write<int64_t>(procedure_id);
89 buffer.
write<int64_t>(until);
93 lock->write(file.
get_data().data() + from, until - from);
94 lock->read(buffer.
data, 9);
98 const char reply = buffer.
read<
char>();
102 const size_t from = file.
get_data().size();
103 const int64_t until = buffer.
read<int64_t>();
105 if (until < int64_t(from) || until > max_message_size)
106 throw_invalid_size();
108 file.
get_data().resize(
size_t(until));
109 lock->read(file.
get_data().data() + from, size_t(until) - from);
110 file.
pwrite((
const char *)&until, 8, 0);
111 file.
pwrite((
const char *)&until, 8, 8);
115 const int64_t n = buffer.
read<int64_t>();
117 if (n < 0 || n > max_message_size)
118 throw_invalid_size();
120 std::string error_message;
121 error_message.resize(n);
122 lock->read(error_message.data(), n);
char data[size+extra_size]
void pwrite(const char *buffer, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
std::array< uint32_t, 8 > Hash
Client(Channel &channel, const std::vector< Signature > &signatures, std::chrono::milliseconds keep_alive_interval=std::chrono::milliseconds(0), int64_t max_message_size=1<< 24)
void call(int64_t procedure_id, Memory_File &file)
SHA_256::Hash get_hash(const std::vector< Signature > &signatures)
Compute hash code for a collection of procedure signatures.