OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
size_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_SIZE_SERIALIZER_H_
7#define OPENCBDC_TX_SRC_SERIALIZATION_SIZE_SERIALIZER_H_
8
9#include "serializer.hpp"
10
11namespace cbdc {
16 class size_serializer final : public serializer {
17 public:
18 size_serializer() = default;
19
23 explicit operator bool() const final;
24
27 void advance_cursor(size_t len) final;
28
30 void reset() final;
31
35 [[nodiscard]] auto end_of_buffer() const -> bool final;
36
41 auto write(const void* data, size_t len) -> bool final;
42
45 auto read(void* data, size_t len) -> bool final;
46
50 [[nodiscard]] auto size() const -> size_t;
51
52 private:
53 size_t m_cursor{};
54 };
55}
56
57#endif
Interface for serializing objects into and out of raw bytes representations.
Utility class for determining the size of a buffer needed to serialize a sequence of objects.
auto size() const -> size_t
Returns the number of bytes accumulated in the size counter during mock serialization.
auto read(void *data, size_t len) -> bool final
Read is not implemented for size serializer.
auto end_of_buffer() const -> bool final
Size serializer has no underlying buffer so this method always returns false.
void reset() final
Resets the size counter to zero.
void advance_cursor(size_t len) final
Increases the size counter by the given number of bytes.
auto write(const void *data, size_t len) -> bool final
Increases size counter by the given number of bytes.