OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
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_SERIALIZER_H_
7#define OPENCBDC_TX_SRC_SERIALIZATION_SERIALIZER_H_
8
9#include <cstddef>
10
11namespace cbdc {
14 class serializer {
15 public:
16 virtual ~serializer() = default;
17 serializer(const serializer&) = delete;
18 auto operator=(const serializer&) = delete;
20 auto operator=(serializer&&) = delete;
21
24 virtual explicit operator bool() const = 0;
25
30 virtual void advance_cursor(size_t len) = 0;
31
33 virtual void reset() = 0;
34
37 [[nodiscard]] virtual auto end_of_buffer() const -> bool = 0;
38
45 virtual auto write(const void* data, size_t len) -> bool = 0;
46
54 virtual auto read(void* data, size_t len) -> bool = 0;
55
56 protected:
57 serializer() = default;
58 };
59}
60
61#endif
Interface for serializing objects into and out of raw bytes representations.
serializer(serializer &&)=delete
virtual ~serializer()=default
virtual void advance_cursor(size_t len)=0
Moves the serialization cursor forward by the given number of bytes.
virtual auto end_of_buffer() const -> bool=0
Indicates whether the cursor is at or beyond the end of the buffer.
auto operator=(const serializer &)=delete
serializer(const serializer &)=delete
virtual auto write(const void *data, size_t len) -> bool=0
Attempts to write the given raw data into the buffer starting at the current cursor position.
auto operator=(serializer &&)=delete
virtual void reset()=0
Resets the cursor to the start of the buffer.
virtual auto read(void *data, size_t len) -> bool=0
Attempts to read the requested number of bytes from the current cursor position into the given memory...