Go to the documentation of this file.
9 #ifndef EAGINE_SERIALIZE_BLOCK_SINK_HPP
10 #define EAGINE_SERIALIZE_BLOCK_SINK_HPP
12 #include "../memory/span_algo.hpp"
14 #include <type_traits>
44 return head(_dst, _done);
51 return skip(_dst, _done);
65 if(dst.size() < blk.size()) {
66 copy(
head(blk, dst.size()), dst);
78 if(_dst.
size() < blk.size()) {
87 _save_points.push_back(_done);
93 EAGINE_MAYBE_UNUSED(th);
94 _save_points.pop_back();
99 EAGINE_MAYBE_UNUSED(th);
100 _done = _save_points.back();
101 _save_points.pop_back();
111 std::vector<span_size_t> _save_points{};
116 #endif // EAGINE_SERIALIZE_BLOCK_SINK_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto write(memory::const_block blk) -> serialization_errors final
Writes a block of data into this sink.
Definition: block_sink.hpp:63
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
Serialization data sink backed by a pre-allocated memory block.
Definition: block_sink.hpp:23
Abstract base class for serialization data sinks.
Definition: data_sink.hpp:24
auto done() const noexcept -> memory::block
Returns the part of the backing block already written to.
Definition: block_sink.hpp:43
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27
constexpr block_data_sink() noexcept=default
Default constructor.
std::uintptr_t transaction_handle
Alias for type indentifying sink transaction that can be rolled back.
Definition: data_sink.hpp:60
auto begin_work() -> transaction_handle final
Begins a write transaction on this data sink.
Definition: block_sink.hpp:86
void commit(transaction_handle th) final
Commits writes done as a part of transaction identified by argument.
Definition: block_sink.hpp:91
virtual auto write(memory::const_block data) -> result=0
Writes a block of data into this sink.
auto finalize() -> serialization_errors override
Does additional finalization, like compression after serialization operation.
Definition: block_sink.hpp:104
auto replace_with(memory::const_block blk) -> serialization_errors
Replaces the content of the backing block with the content of the argument.
Definition: block_sink.hpp:77
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
@ incomplete_write
Incomplete write, remaining data should be written later.
auto remaining_size() -> span_size_t final
Returns the size of the free part of the backing block.
Definition: block_sink.hpp:57
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the span.
Definition: span.hpp:246
void rollback(transaction_handle th) final
Rolls-back writes done as a part of transaction identified by argument.
Definition: block_sink.hpp:97
void reset(memory::block dst)
Resets the backing block.
Definition: block_sink.hpp:35
@ too_much_data
Too much data to fit into serialization data sink.
auto free() const noexcept -> memory::block
Returns the free part of the backing block.
Definition: block_sink.hpp:50
block_data_sink(memory::block dst) noexcept
Constructor setting the backing block.
Definition: block_sink.hpp:30