OGLplus  (0.59.0) a C++ wrapper for rendering APIs

packed_block_sink.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_SERIALIZE_PACKED_BLOCK_SINK_HPP
10 #define EAGINE_SERIALIZE_PACKED_BLOCK_SINK_HPP
11 
12 #include "../compression.hpp"
13 #include "block_sink.hpp"
14 
15 namespace eagine {
16 //------------------------------------------------------------------------------
22 public:
24  packed_block_data_sink() noexcept = default;
25 
28  data_compressor compressor,
29  memory::block dst) noexcept
30  : block_data_sink{dst}
31  , _compressor{std::move(compressor)} {}
32 
34  : packed_block_data_sink{{}, dst} {}
35 
36  packed_block_data_sink(data_compressor compressor) noexcept
37  : packed_block_data_sink{std::move(compressor), {}} {}
38 
39  auto finalize() -> serialization_errors final {
40  if(auto packed{
41  _compressor.compress(done(), data_compression_level::normal)}) {
42  return this->replace_with(packed);
43  }
45  }
46 
47 private:
48  data_compressor _compressor{};
49 };
50 //------------------------------------------------------------------------------
51 } // namespace eagine
52 
53 #endif // EAGINE_SERIALIZE_PACKED_BLOCK_SINK_HPP
auto finalize() -> serialization_errors final
Does additional finalization, like compression after serialization operation.
Definition: packed_block_sink.hpp:39
Common code is placed in this namespace.
Definition: eagine.hpp:21
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
auto done() const noexcept -> memory::block
Returns the part of the backing block already written to.
Definition: block_sink.hpp:43
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27
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
packed_block_data_sink(data_compressor compressor, memory::block dst) noexcept
Constructor setting the backing block and data compressor.
Definition: packed_block_sink.hpp:27
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
Packing serialization data sink backed by a pre-allocated memory block.
Definition: packed_block_sink.hpp:21
auto compress(memory::const_block input, const data_handler &handler, data_compression_level level) -> bool
Compress the input block, passing the packed data to handler.
Class implementing data compression and decompresson.
Definition: compression.hpp:37
packed_block_data_sink() noexcept=default
Default constructor.
@ backend_error
Internal error in the serialization backend.
@ normal
Normal compression level.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).