10 #include <boost/assert.hpp>
16 offline_EventStorage_v5::string_to_type(
const std::string&
type){
20 }
else if(
type==
"unknown"){
22 }
else if(
type==
"none"){
24 }
else if(
type==
"zlib"){
54 std::string
zmsg(
const z_stream& strm){
55 std::string
zmsg(
"None");
63 void offline_EventStorage_v5::zlibcompress(offline_EventStorage_v5::CompressionBuffer& compressed,
66 const struct iovec_const*
iov,
70 if(compressed.buffersize() < totalsize*1.1){
71 compressed.realloc(totalsize*1.1);
79 int ret = ::deflateInit(&strm,
level);
87 uint32_t available = compressed.buffersize();
88 strm.avail_out = available;
89 strm.next_out =
reinterpret_cast<Bytef*
>(compressed.handle());
93 strm.next_in =
static_cast<const Bytef*
>(
iov[
i].iov_base);
94 strm.avail_in =
iov[
i].iov_len;
101 if(ret == Z_STREAM_ERROR){
110 compsize += available;
113 compressed.grow(2*compressed.buffersize());
114 available = compressed.buffersize()/2;
115 strm.avail_out = available;
116 strm.next_out =
static_cast<Bytef*
>(compressed.handle()) +available;
121 compsize += (available-strm.avail_out);
122 ret = ::deflateEnd(&strm);
132 if(tobeadded>0 && tobeadded<
sizeof(
uint32_t)){
134 if(tobeadded>(compressed.buffersize()-compsize)){
136 compressed.grow(compsize+tobeadded);
139 ::bzero(
static_cast<Bytef*
>(compressed.handle())+compsize,tobeadded);
140 compsize += tobeadded;
143 compressedsize = compsize;
147 offline_EventStorage_v5::zlibdecompress(offline_EventStorage_v5::CompressionBuffer& decompressed,
149 const void * compressed,
155 if(decompressed.buffersize() < compsize*3){
156 decompressed.realloc(compsize*3);
161 bufsize = decompressed.buffersize();
163 ret = ::uncompress(
reinterpret_cast<Bytef*
>(decompressed.handle()),
165 static_cast<const Bytef*
>(compressed),
169 decompressedsize = bufsize;
171 }
else if(ret == Z_DATA_ERROR){
172 ::memcpy(decompressed.handle(), compressed, compsize);
173 decompressedsize = compsize;
177 "Zlib decompression failed with Z_DATA_ERROR",
181 }
else if(ret == Z_MEM_ERROR){
183 ERS_LOG(
"Zlib decompressed failed with MEM_ERROR. Code: " << ret);
184 ERS_ASSERT(ret != Z_MEM_ERROR);
185 }
else if(ret == Z_BUF_ERROR){
187 decompressed.realloc(decompressed.buffersize()*2);