8#ifndef GRIDFORMAT_COMPRESSION_DECOMPRESS_HPP_
9#define GRIDFORMAT_COMPRESSION_DECOMPRESS_HPP_
13#include <gridformat/common/exceptions.hpp>
14#include <gridformat/common/serialization.hpp>
19namespace GridFormat::Compression {
25template<std::
integral HeaderType, Concepts::BlockDecompressor Decompressor>
28 const Decompressor& block_decompressor) {
29 using Byte =
typename Decompressor::ByteType;
31 const auto last_block_size = blocks.residual_block_size > 0 ? blocks.residual_block_size : blocks.block_size;
32 const auto out_size = blocks.block_size*(blocks.number_of_blocks-1) + last_block_size;
34 std::size_t in_offset = 0;
35 std::size_t out_offset = 0;
36 Serialization out{out_size};
38 const auto* in_data = in.template as_span_of<const Byte>().data();
39 auto* out_data = out.template as_span_of<Byte>().data();
40 std::ranges::for_each(std::views::iota(HeaderType{0}, blocks.number_of_blocks), [&] (HeaderType i) {
41 const auto out_block_size = (i == blocks.number_of_blocks - 1) ? last_block_size : blocks.block_size;
44 std::span{in_data + in_offset, blocks.compressed_block_sizes[i]},
45 std::span{out_data + out_offset, out_block_size}
48 in_offset += blocks.compressed_block_sizes[i];
49 out_offset += out_block_size;
51 if (out_offset != out.size())
53 "Unexpected number of bytes written: " + std::to_string(out_offset) +
" vs. " + std::to_string(out.size())
Common classes used in the context of data compression.
Concepts related to data compression.
void decompress(Serialization &in, const CompressedBlocks< HeaderType > &blocks, const Decompressor &block_decompressor)
Decompress compressed data.
Definition: decompress.hpp:26