25 #if !defined (_RLD_COMPRESSION_H_)
26 #define _RLD_COMPRESSION_H_
51 bool compress =
true);
65 void write (
const void* data,
size_t length);
91 size_t read (
void* data,
size_t length);
140 void output (
bool forced =
false);
156 size_t total_compressed;
163 template <
typename T >
166 uint8_t bytes[
sizeof (T)];
168 int b =
sizeof (T) - 1;
171 bytes[b--] = (uint8_t) v;
174 comp.
write (bytes,
sizeof (T));
180 template <
typename T >
183 uint8_t bytes[
sizeof (T)];
186 if (comp.
read (bytes, sizeof (T)) !=
sizeof (T))
187 throw rld::error (
"Reading of value failed",
"compression");
188 while (b <
sizeof (T))
190 v = (v << 8) | ((T) bytes[b++]);
199 const uint64_t value) {
200 rld::compress::write < uint64_t > (comp, value);
205 const uint32_t value) {
206 rld::compress::write < uint32_t > (comp, value);
211 const std::string& str) {
212 comp.
write (str.c_str (), str.size ());
218 value = rld::compress::read < uint64_t > (comp);
224 value = rld::compress::read < uint32_t > (comp);