Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
wsdb_ipc_client_generated.cpp
Go to the documentation of this file.
1// AUTOGENERATED FILE - DO NOT EDIT
2
7
8#include <stdexcept>
9#include <tuple>
10
11namespace bb::wsdb {
12
13WsdbIpcClient::WsdbIpcClient(const std::string& socket_path)
14 : client_(ipc::IpcClient::create_socket(socket_path))
15{
16 if (!client_->connect()) {
17 throw std::runtime_error("Failed to connect to server at " + socket_path);
18 }
19}
20
22{
23 if (client_) {
24 client_->close();
25 }
26}
27
28template <typename Cmd> typename Cmd::Response WsdbIpcClient::send(Cmd&& cmd) const
29{
30 // Wrap command in WsdbCommand NamedUnion, then in a 1-element tuple (matches server expectations)
31 WsdbCommand command = std::forward<Cmd>(cmd);
32 auto wrapped = std::make_tuple(std::move(command));
33
34 // Serialize to msgpack
35 msgpack::sbuffer send_buffer;
36 msgpack::pack(send_buffer, wrapped);
37
38 // Send to server
39 constexpr uint64_t timeout_ns = 30'000'000'000ULL; // 30 seconds
40 if (!client_->send(send_buffer.data(), send_buffer.size(), timeout_ns)) {
41 throw std::runtime_error("Failed to send command to server");
42 }
43
44 // Receive response
45 auto response_span = client_->receive(timeout_ns);
46 if (response_span.empty()) {
47 throw std::runtime_error("Empty response from server");
48 }
49
50 // Deserialize response
51 auto unpacked = msgpack::unpack(reinterpret_cast<const char*>(response_span.data()), response_span.size());
52 auto response_obj = unpacked.get();
53
54 WsdbCommandResponse response;
55 response_obj.convert(response);
56
57 // Release the receive buffer
58 client_->release(response_span.size());
59
60 // Check for error response
61 return std::move(response).visit([](auto&& resp) -> typename Cmd::Response {
62 using RespType = std::decay_t<decltype(resp)>;
63
65 throw std::runtime_error("Server error: " + resp.message);
68 } else {
69 throw std::runtime_error("Unexpected response type from server");
70 }
71 });
72}
73
78
83
88
93
98
103
109
114
119
124
126{
127 send(std::move(cmd));
128}
129
134
139
144
149
154
159
164
169
174
179
184
189
194
199
204
209
214
216{
217 send(std::move(cmd));
218}
219
224
225} // namespace bb::wsdb
A wrapper around std::variant that provides msgpack serialization based on type names.
decltype(auto) visit(Visitor &&vis) &&
Cmd::Response send(Cmd &&cmd) const
std::unique_ptr< ipc::IpcClient > client_
void delete_fork(WsdbDeleteFork cmd)
void create_checkpoint(WsdbCreateCheckpoint cmd)
WsdbGetSiblingPath::Response get_sibling_path(WsdbGetSiblingPath cmd) const
WsdbGetBlockNumbersForLeafIndices::Response get_block_numbers_for_leaf_indices(WsdbGetBlockNumbersForLeafIndices cmd) const
WsdbBatchInsert::Response batch_insert(WsdbBatchInsert cmd) const
void copy_stores(WsdbCopyStores cmd) const
WsdbCreateFork::Response create_fork(WsdbCreateFork cmd)
void update_archive(WsdbUpdateArchive cmd) const
WsdbRemoveHistoricalBlocks::Response remove_historical_blocks(WsdbRemoveHistoricalBlocks cmd) const
WsdbUnwindBlocks::Response unwind_blocks(WsdbUnwindBlocks cmd)
void commit_checkpoint(WsdbCommitCheckpoint cmd)
WsdbFindLeafIndices::Response find_leaf_indices(WsdbFindLeafIndices cmd) const
WsdbFinalizeBlocks::Response finalize_blocks(WsdbFinalizeBlocks cmd) const
WsdbFindSiblingPaths::Response find_sibling_paths(WsdbFindSiblingPaths cmd) const
WsdbGetInitialStateReference::Response get_initial_state_reference() const
WsdbGetTreeInfo::Response get_tree_info(WsdbGetTreeInfo cmd) const
WsdbSyncBlock::Response sync_block(WsdbSyncBlock cmd)
WsdbSequentialInsert::Response sequential_insert(WsdbSequentialInsert cmd) const
WsdbIpcClient(const std::string &socket_path)
void commit_all_checkpoints(WsdbCommitAllCheckpoints cmd)
WsdbGetLeafValue::Response get_leaf_value(WsdbGetLeafValue cmd) const
void revert_checkpoint(WsdbRevertCheckpoint cmd)
WsdbGetStateReference::Response get_state_reference(WsdbGetStateReference cmd) const
WsdbFindLowLeaf::Response find_low_leaf(WsdbFindLowLeaf cmd) const
void append_leaves(WsdbAppendLeaves cmd) const
WsdbGetLeafPreimage::Response get_leaf_preimage(WsdbGetLeafPreimage cmd) const
WsdbGetStatus::Response get_status() const
void revert_all_checkpoints(WsdbRevertAllCheckpoints cmd)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
WsdbCommand NamedUnion, WsdbRequest context, and dispatch function.