Scroom  0.14
Scroom::MemoryBlobs::Detail Namespace Reference

Functions

PageList compressBlob (const uint8_t *in, size_t size, const PageProvider::Ptr &provider)
 
void decompressBlob (uint8_t *out, size_t size, PageList list, const PageProvider::Ptr &provider)
 

Function Documentation

◆ compressBlob()

PageList Scroom::MemoryBlobs::Detail::compressBlob ( const uint8_t *  in,
size_t  size,
const PageProvider::Ptr provider 
)
31  {
32  PageList result;
33  z_stream stream;
34  const size_t pageSize = provider->getPageSize();
35 
36  stream.next_in = const_cast<uint8_t*>(in); // NOLINT(cppcoreguidelines-pro-type-const-cast)
37  stream.avail_in = size;
38  stream.avail_out = 0;
39  stream.zalloc = Z_NULL;
40  stream.zfree = Z_NULL;
41  stream.opaque = Z_NULL;
42 
43  int r = deflateInit(&stream, Z_BEST_SPEED);
44  zlib_verify(r == Z_OK, "deflateInit", r, stream);
45 
46  do
47  {
48  verify(stream.avail_out == 0);
49 
50  Page::Ptr const currentPage = provider->getFreePage();
51  result.push_back(currentPage);
52 
53  RawPageData::Ptr const currentPageRaw = currentPage->get();
54 
55  stream.next_out = currentPageRaw.get();
56  stream.avail_out = pageSize;
57 
58  r = deflate(&stream, Z_FINISH);
59 
60  } while(r == Z_OK);
61 
62  zlib_verify(r == Z_STREAM_END, "deflate", r, stream);
63 
64  r = deflateEnd(&stream);
65  zlib_verify(r == Z_OK, "deflateEnd", r, stream);
66 
67  return result;
68  }

Referenced by BOOST_AUTO_TEST_CASE(), and Scroom::MemoryBlobs::Blob::compress().

Here is the caller graph for this function:

◆ decompressBlob()

void Scroom::MemoryBlobs::Detail::decompressBlob ( uint8_t *  out,
size_t  size,
PageList  list,
const PageProvider::Ptr provider 
)
71  {
72  z_stream stream;
73  const size_t pageSize = provider->getPageSize();
74 
75  stream.next_out = out;
76  stream.avail_out = size;
77  stream.avail_in = 0;
78  stream.zalloc = Z_NULL;
79  stream.zfree = Z_NULL;
80  stream.opaque = Z_NULL;
81 
82  int r = inflateInit(&stream);
83  zlib_verify(r == Z_OK, "inflateInit", r, stream);
84 
85  while(!list.empty() && r == Z_OK)
86  {
87  verify(stream.avail_in == 0);
88 
89  Page::Ptr const currentPage = list.front();
90  list.pop_front();
91 
92  RawPageData::Ptr const currentPageRaw = currentPage->get();
93 
94  stream.next_in = currentPageRaw.get();
95  stream.avail_in = pageSize;
96 
97  const int flush = (list.empty() ? Z_FINISH : Z_NO_FLUSH);
98 
99  r = inflate(&stream, flush);
100  }
101  zlib_verify(r == Z_OK || r == Z_STREAM_END, "inflate", r, stream);
102 
103  r = inflateEnd(&stream);
104  zlib_verify(r == Z_OK, "inflateEnd", r, stream);
105  }

Referenced by BOOST_AUTO_TEST_CASE(), and Scroom::MemoryBlobs::Blob::load().

Here is the caller graph for this function:
Scroom::MemoryBlocks::RawPageData::Ptr
boost::shared_ptr< uint8_t > Ptr
Definition: blockallocator.hh:23
verify
#define verify(expr)
Definition: assertions.hh:36
Scroom::MemoryBlocks::PageList
std::list< Page > PageList
Definition: blockallocator.hh:41
zlib_verify
#define zlib_verify(condition, function_name, r, stream)
Definition: blob-compression.cc:19
out
SampleIterator< uint8_t > out(output, 0, bps)