OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
ostream_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_OSTREAM_SERIALIZER_H_
7#define OPENCBDC_TX_SRC_SERIALIZATION_OSTREAM_SERIALIZER_H_
8
10
11#include <ostream>
12
13namespace cbdc {
16 public:
19 explicit ostream_serializer(std::ostream& s);
20
23 [[nodiscard]] auto end_of_buffer() const -> bool final;
24
27 void advance_cursor(size_t len) final;
28
30 void reset() final;
31
39 auto write(const void* data, size_t len) -> bool final;
40
43 auto read(void* data, size_t len) -> bool final;
44
45 private:
46 std::ostream& m_str;
47
48 using off_type = std::remove_reference_t<decltype(m_str)>::off_type;
49 };
50}
51
52#endif
Implementation of serializer for writing to a std::ostream.
auto write(const void *data, size_t len) -> bool final
Attempts to write the given number of bytes from the given memory location to the stream's current po...
void advance_cursor(size_t len) final
Moves the stream forward without writing to the stream.
ostream_serializer(std::ostream &s)
Constructor.
void reset() final
Seeks the stream position to the beginning.
auto end_of_buffer() const -> bool final
Indicates whether the serializer has reached the end of the stream.
auto read(void *data, size_t len) -> bool final
Not implemented for ostream.
Implementation of serializer for std::ios.