35#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_COMPRESSDATA_H
36#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_COMPRESSDATA_H
58 "LittleEndian",
"BigWordEndian",
71template <
class T>
int ZlibEncode(std::vector<T> &in, std::string &out)
78 unsigned char *input = (
unsigned char *)(&in[0]);
84 ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
86 ASSERTL0(ret == Z_OK,
"Error initializing Zlib.");
88 strm.avail_in = (
unsigned int)in.size() *
sizeof(T) /
sizeof(
char);
94 strm.avail_out =
CHUNK;
95 strm.next_out = (
unsigned char *)(&
buffer[0]);
97 ret = deflate(&strm, Z_FINISH);
101 ASSERTL0(ret != Z_STREAM_ERROR,
"Zlib stream error");
103 have =
CHUNK - strm.avail_out;
104 out +=
buffer.substr(0, have);
105 }
while (strm.avail_out == 0);
108 ASSERTL0(strm.avail_in == 0,
"Not all input was used.");
111 ASSERTL0(ret == Z_STREAM_END,
"Stream not finished");
114 (
void)deflateEnd(&strm);
123 std::string &compressedDataString, std::string &base64string);
144template <
class T>
int ZlibDecode(std::string &in, std::vector<T> &out)
153 strm.zalloc = Z_NULL;
155 strm.opaque = Z_NULL;
157 strm.next_in = Z_NULL;
158 ret = inflateInit(&strm);
159 ASSERTL0(ret == Z_OK,
"Error initializing zlib decompression.");
161 strm.avail_in = (
unsigned int)in.size();
162 strm.next_in = (
unsigned char *)(&in[0]);
166 strm.avail_out =
CHUNK;
167 strm.next_out = (
unsigned char *)(&
buffer[0]);
169 ret = inflate(&strm, Z_NO_FLUSH);
171 ASSERTL0(ret != Z_STREAM_ERROR,
"Stream error occured.");
180 (
void)inflateEnd(&strm);
184 have =
CHUNK - strm.avail_out;
185 output +=
buffer.substr(0, have);
186 }
while (strm.avail_out == 0);
188 (
void)inflateEnd(&strm);
190 if (ret == Z_STREAM_END)
192 T *readFieldData = (T *)output.c_str();
194 (
unsigned int)output.size() *
sizeof(*output.c_str()) /
sizeof(T);
195 out.assign(readFieldData, readFieldData + len);
209 std::string &base64string, std::string &compressedDataString);
#define ASSERTL0(condition, msg)
#define LIB_UTILITIES_EXPORT
void Base64StrToBinaryStr(std::string &base64string, std::string &compressedDataString)
std::string GetBitSizeStr(void)
int ZlibDecode(std::string &in, std::vector< T > &out)
int ZlibEncode(std::vector< T > &in, std::string &out)
int ZlibDecodeFromBase64Str(std::string &in64, std::vector< T > &out)
void BinaryStrToBase64Str(std::string &compressedDataString, std::string &base64string)
std::string GetCompressString(void)
int ZlibEncodeToBase64Str(std::vector< T > &in, std::string &out64)
const std::string EndianTypeMap[]
EndianType Endianness(void)