OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
buffer_serializer.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_SERIALIZATION_BUFFER_SERIALIZER_H_
7#define OPENCBDC_TX_SRC_SERIALIZATION_BUFFER_SERIALIZER_H_
8
9#include "serializer.hpp"
11
12namespace cbdc {
14 class buffer_serializer final : public cbdc::serializer {
15 public:
18 explicit buffer_serializer(cbdc::buffer& pkt);
19
22 explicit operator bool() const final;
23
26 void advance_cursor(size_t len) final;
27
29 void reset() final;
30
33 [[nodiscard]] auto end_of_buffer() const -> bool final;
34
42 auto write(const void* data, size_t len) -> bool final;
43
50 auto read(void* data, size_t len) -> bool final;
51
52 private:
53 cbdc::buffer& m_pkt;
54 size_t m_cursor{};
55 bool m_valid{true};
56 };
57}
58
59#endif
Serializer implementation for buffer.
void advance_cursor(size_t len) final
Moves the cursor forward by the given number of bytes.
auto read(void *data, size_t len) -> bool final
Read the given number of bytes from the buffer from the current cursor position into the given memory...
auto write(const void *data, size_t len) -> bool final
Write the given bytes into the buffer from the current cursor position.
auto end_of_buffer() const -> bool final
Indicates whether the cursor is at or beyond the end of the buffer.
void reset() final
Resets the cursor to the start of the buffer.
buffer_serializer(cbdc::buffer &pkt)
Constructor.
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Interface for serializing objects into and out of raw bytes representations.