OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
util/raft/serialization.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_RAFT_SERIALIZATION_H_
7#define OPENCBDC_TX_SRC_RAFT_SERIALIZATION_H_
8
10
11#include <libnuraft/buffer.hxx>
12
13namespace cbdc {
17 class nuraft_serializer final : public cbdc::serializer {
18 public:
21 explicit nuraft_serializer(nuraft::buffer& buf);
22
26 explicit operator bool() const final;
27
31 void advance_cursor(size_t len) final;
32
34 void reset() final;
35
39 [[nodiscard]] auto end_of_buffer() const -> bool final;
40
46 auto write(const void* data, size_t len) -> bool final;
47
54 auto read(void* data, size_t len) -> bool final;
55
56 private:
57 nuraft::buffer& m_buf;
58 bool m_valid{true};
59 };
60}
61
62#endif // OPENCBDC_TX_SRC_RAFT_SERIALIZATION_H_
Implements serializer for nuraft::buffer.
auto end_of_buffer() const -> bool final
Returns whether the cursor is currently at the end of the buffer.
void reset() final
Resets the cursor to the start of the buffer.
auto read(void *data, size_t len) -> bool final
Reads the given number of bytes from the current cursor in the buffer into the given destination.
auto write(const void *data, size_t len) -> bool final
Writes the given raw bytes to the buffer from the current position of the cursor.
void advance_cursor(size_t len) final
Moves the cursor inside the buffer forward by the given number of bytes.
nuraft_serializer(nuraft::buffer &buf)
Constructor.
Interface for serializing objects into and out of raw bytes representations.