lz4s.c
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2014, Ben Charrow
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 ********************************************************************/
34 
35 #include "roslz4/lz4s.h"
36 
37 #include "xxhash.h"
38 
39 #include <stdint.h>
40 #include <string.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 #if 0
45 #define DEBUG(...) fprintf(stderr, __VA_ARGS__)
46 #else
47 #define DEBUG(...)
48 #endif
49 
50 // Make sure the LZ4 library has the function we need
51 // Note that the later versions of LZ4 contain a different macro that does this version math, but the earlier
52 // versions lack it.
53 #define LZ4_VERSION (LZ4_VERSION_MAJOR * 100 * 100 + LZ4_VERSION_MINOR * 100 + LZ4_VERSION_RELEASE)
54 #if LZ4_VERSION >= 10701
55 #define LZ4_COMPRESS_DEFAULT LZ4_compress_default
56 #else
57 #define LZ4_COMPRESS_DEFAULT LZ4_compress_limitedOutput
58 #endif
59 
60 // magic numbers
61 const uint32_t kMagicNumber = 0x184D2204;
62 const uint32_t kEndOfStream = 0x00000000;
63 
64 // Bitmasks
65 const uint8_t k1Bits = 0x01;
66 const uint8_t k2Bits = 0x03;
67 const uint8_t k3Bits = 0x07;
68 const uint8_t k4Bits = 0x0F;
69 const uint8_t k8Bits = 0xFF;
70 
71 uint32_t readUInt32(unsigned char *buffer) {
72  return ((buffer[0] << 0) | (buffer[1] << 8) |
73  (buffer[2] << 16) | (buffer[3] << 24));
74 }
75 
76 void writeUInt32(unsigned char *buffer, uint32_t val) {
77  buffer[0] = val & 0xFF;
78  buffer[1] = (val >> 8) & 0xFF;
79  buffer[2] = (val >> 16) & 0xFF;
80  buffer[3] = (val >> 24) & 0xFF;
81 }
82 
83 int min(int a, int b) {
84  return a < b ? a : b;
85 }
86 
87 /*========================== Low level compression ==========================*/
88 
89 typedef struct {
93 
94  char *buffer;
97 
98  int finished; // 1 if done compressing/decompressing; 0 otherwise
99 
100  void* xxh32_state;
101 
102  // Compression state
104 
105  // Decompression state
106  char header[10];
107  uint32_t block_size; // Size of current block
108  int block_size_read; // # of bytes read for current block_size
109  int block_uncompressed; // 1 if block is uncompressed, 0 otherwise
110  uint32_t stream_checksum; // Storage for checksum
111  int stream_checksum_read; // # of bytes read for stream_checksum
112 } stream_state;
113 
114 void advanceInput(roslz4_stream *str, int nbytes) {
115  str->input_next += nbytes;
116  str->input_left -= nbytes;
117  str->total_in += nbytes;
118 }
119 
120 void advanceOutput(roslz4_stream *str, int nbytes) {
121  str->output_next += nbytes;
122  str->output_left -= nbytes;
123  str->total_out += nbytes;
124 }
125 
126 void fillUInt32(roslz4_stream *str, uint32_t *dest_val, int *offset) {
127  char *dest = (char*) dest_val;
128  int to_copy = min(4 - *offset, str->input_left);
129  memcpy(dest + *offset, str->input_next, to_copy);
130  advanceInput(str, to_copy);
131  *offset += to_copy;
132 }
133 
135  if (str->output_left < 7) {
136  return ROSLZ4_OUTPUT_SMALL; // Output must have 7 bytes
137  }
138 
139  stream_state *state = str->state;
140  writeUInt32((unsigned char*) str->output_next, kMagicNumber);
141  int version = 1;
142  char *out = str->output_next;
143  *(out+4) = ((unsigned)version & k2Bits) << 6;
144  *(out+4) |= ((unsigned)state->block_independence_flag & k1Bits) << 5;
145  *(out+4) |= ((unsigned)state->block_checksum_flag & k1Bits) << 4;
146  *(out+4) |= ((unsigned)state->stream_checksum_flag & k1Bits) << 2;
147  *(out+5) = ((unsigned)str->block_size_id & k3Bits) << 4;
148 
149  // Checksum: 2nd byte of hash of header flags
150  unsigned char checksum = (XXH32(str->output_next + 4, 2, 0) >> 8) & k8Bits;
151  *(str->output_next+6) = checksum;
152 
153  advanceOutput(str, 7);
154  DEBUG("writeHeader() Put 7 bytes in output\n");
155 
156  return ROSLZ4_OK;
157 }
158 
160  if (str->output_left < 8) {
161  return ROSLZ4_OUTPUT_SMALL;
162  }
163 
164  stream_state *state = str->state;
165  state->finished = 1;
166  writeUInt32((unsigned char*) str->output_next, kEndOfStream);
167  advanceOutput(str, 4);
168 
169  uint32_t stream_checksum = XXH32_digest(state->xxh32_state);
170  writeUInt32((unsigned char*) str->output_next, stream_checksum);
171  advanceOutput(str, 4);
172  state->xxh32_state = NULL;
173 
174  DEBUG("writeEOS() Wrote 8 bytes to output %i\n", str->output_left);
175  return ROSLZ4_STREAM_END;
176 }
177 
178 // If successfull, number of bytes written to output
179 // If error, LZ4 return code
181  stream_state *state = str->state;
182  uint32_t uncomp_size = state->buffer_offset;
183  if (state->buffer_offset == 0) {
184  return 0; // No data to flush
185  } else if (str->output_left - 4 < uncomp_size) {
186  DEBUG("bufferToOutput() Not enough space left in output\n");
187  return ROSLZ4_OUTPUT_SMALL;
188  }
189 
190  DEBUG("bufferToOutput() Flushing %i bytes, %i left in output\n",
191  state->buffer_offset, str->output_left);
192 
193  // Shrink output by 1 to detect if data is not compressible
194  uint32_t comp_size = LZ4_COMPRESS_DEFAULT(state->buffer,
195  str->output_next + 4,
196  (int) state->buffer_offset,
197  (int) uncomp_size - 1);
198  uint32_t wrote;
199  if (comp_size > 0) {
200  DEBUG("bufferToOutput() Compressed to %i bytes\n", comp_size);
201  // Write compressed data size
202  wrote = 4 + comp_size;
203  writeUInt32((unsigned char*)str->output_next, comp_size);
204  } else {
205  // Write uncompressed data
206  DEBUG("bufferToOutput() Can't compress, copying input\n");
207  memcpy(str->output_next + 4, state->buffer, uncomp_size);
208  // Write uncompressed data size. Signal data is uncompressed with high
209  // order bit; won't confuse decompression because max block size is < 2GB
210  wrote = 4 + uncomp_size;
211  writeUInt32((unsigned char*) str->output_next, uncomp_size | 0x80000000);
212  }
213 
214  advanceOutput(str, wrote);
215  state->buffer_offset -= uncomp_size;
216 
217  DEBUG("bufferToOutput() Ate %i from buffer, wrote %i to output (%i)\n",
218  uncomp_size, wrote, str->output_left);
219  return wrote;
220 }
221 
222 // Copy as much data as possible from input to internal buffer
223 // Return number of bytes written if successful, LZ4 error code on error
225  stream_state *state = str->state;
226  if (str->input_left == 0 ||
227  state->buffer_size == state->buffer_offset) {
228  return 0;
229  }
230  int buffer_left = state->buffer_size - state->buffer_offset;
231  int to_copy = min(str->input_left, buffer_left);
232 
233  int ret = XXH32_update(state->xxh32_state, str->input_next, to_copy);
234  if (ret == XXH_ERROR) { return ROSLZ4_ERROR; }
235 
236  memcpy(state->buffer + state->buffer_offset, str->input_next, to_copy);
237  advanceInput(str, to_copy);
238  state->buffer_offset += to_copy;
239 
240  DEBUG("inputToBuffer() Wrote % 5i bytes to buffer (size=% 5i)\n",
241  to_copy, state->buffer_offset);
242  return to_copy;
243 }
244 
246  stream_state *state = (stream_state*) malloc(sizeof(stream_state));
247  if (state == NULL) {
248  return ROSLZ4_MEMORY_ERROR; // Allocation of state failed
249  }
250  str->state = state;
251 
252  str->block_size_id = -1;
253  state->block_independence_flag = 1;
254  state->block_checksum_flag = 0;
255  state->stream_checksum_flag = 1;
256 
257  state->finished = 0;
258 
259  state->xxh32_state = XXH32_init(0);
260  state->stream_checksum = 0;
261  state->stream_checksum_read = 0;
262 
263  state->wrote_header = 0;
264 
265  state->buffer_offset = 0;
266  state->buffer_size = 0;
267  state->buffer = NULL;
268 
269  state->block_size = 0;
270  state->block_size_read = 0;
271  state->block_uncompressed = 0;
272 
273  str->total_in = 0;
274  str->total_out = 0;
275 
276  return ROSLZ4_OK;
277 }
278 
279 int streamResizeBuffer(roslz4_stream *str, int block_size_id) {
280  stream_state *state = str->state;
281  if (!(4 <= block_size_id && block_size_id <= 7)) {
282  return ROSLZ4_PARAM_ERROR; // Invalid block size
283  }
284 
285  str->block_size_id = block_size_id;
286  state->buffer_offset = 0;
288  state->buffer = (char*) malloc(sizeof(char) * state->buffer_size);
289  if (state->buffer == NULL) {
290  return ROSLZ4_MEMORY_ERROR; // Allocation of buffer failed
291  }
292  return ROSLZ4_OK;
293 }
294 
296  stream_state *state = str->state;
297  if (state != NULL) {
298  if (state->buffer != NULL) {
299  free(state->buffer);
300  }
301  if (state->xxh32_state != NULL) {
302  XXH32_digest(state->xxh32_state);
303  }
304  free(state);
305  str->state = NULL;
306  }
307 }
308 
309 int roslz4_blockSizeFromIndex(int block_id) {
310  return (1 << (8 + (2 * block_id)));
311 }
312 
313 int roslz4_compressStart(roslz4_stream *str, int block_size_id) {
314  int ret = streamStateAlloc(str);
315  if (ret < 0) { return ret; }
316  return streamResizeBuffer(str, block_size_id);
317 }
318 
319 int roslz4_compress(roslz4_stream *str, int action) {
320  int ret;
321  stream_state *state = str->state;
322  if (action != ROSLZ4_RUN && action != ROSLZ4_FINISH) {
323  return ROSLZ4_PARAM_ERROR; // Unrecognized compression action
324  } else if (state->finished) {
325  return ROSLZ4_ERROR; // Cannot call action on finished stream
326  }
327 
328  if (!state->wrote_header) {
329  ret = writeHeader(str);
330  if (ret < 0) { return ret; }
331  state->wrote_header = 1;
332  }
333 
334  // Copy input to internal buffer, compressing when full or finishing stream
335  int read = 0, wrote = 0;
336  do {
337  read = inputToBuffer(str);
338  if (read < 0) { return read; }
339 
340  wrote = 0;
341  if (action == ROSLZ4_FINISH || state->buffer_offset == state->buffer_size) {
342  wrote = bufferToOutput(str);
343  if (wrote < 0) { return wrote; }
344  }
345  } while (read > 0 || wrote > 0);
346 
347  // Signal end of stream if finishing up, otherwise done
348  if (action == ROSLZ4_FINISH) {
349  return writeEOS(str);
350  } else {
351  return ROSLZ4_OK;
352  }
353 }
354 
356  streamStateFree(str);
357 }
358 
359 /*========================= Low level decompression =========================*/
360 
362  return streamStateAlloc(str);
363  // Can't allocate internal buffer, block size is unknown until header is read
364 }
365 
366 // Return 1 if header is present, 0 if more data is needed,
367 // LZ4 error code (< 0) if error
369  stream_state *state = str->state;
370  if (str->total_in >= 7) {
371  return 1;
372  }
373  // Populate header buffer
374  int to_copy = min(7 - str->total_in, str->input_left);
375  memcpy(state->header + str->total_in, str->input_next, to_copy);
376  advanceInput(str, to_copy);
377  if (str->total_in < 7) {
378  return 0;
379  }
380 
381  // Parse header buffer
382  unsigned char *header = (unsigned char*) state->header;
383  uint32_t magic_number = readUInt32(header);
384  if (magic_number != kMagicNumber) {
385  return ROSLZ4_DATA_ERROR; // Stream does not start with magic number
386  }
387  // Check descriptor flags
388  int version = (header[4] >> 6) & k2Bits;
389  int block_independence_flag = (header[4] >> 5) & k1Bits;
390  int block_checksum_flag = (header[4] >> 4) & k1Bits;
391  int stream_size_flag = (header[4] >> 3) & k1Bits;
392  int stream_checksum_flag = (header[4] >> 2) & k1Bits;
393  int reserved1 = (header[4] >> 1) & k1Bits;
394  int preset_dictionary_flag = (header[4] >> 0) & k1Bits;
395 
396  int reserved2 = (header[5] >> 7) & k1Bits;
397  int block_max_id = (header[5] >> 4) & k3Bits;
398  int reserved3 = (header[5] >> 0) & k4Bits;
399 
400  // LZ4 standard requirements
401  if (version != 1) {
402  return ROSLZ4_DATA_ERROR; // Wrong version number
403  }
404  if (reserved1 != 0 || reserved2 != 0 || reserved3 != 0) {
405  return ROSLZ4_DATA_ERROR; // Reserved bits must be 0
406  }
407  if (!(4 <= block_max_id && block_max_id <= 7)) {
408  return ROSLZ4_DATA_ERROR; // Invalid block size
409  }
410 
411  // Implementation requirements
412  if (stream_size_flag != 0) {
413  return ROSLZ4_DATA_ERROR; // Stream size not supported
414  }
415  if (preset_dictionary_flag != 0) {
416  return ROSLZ4_DATA_ERROR; // Dictionary not supported
417  }
418  if (block_independence_flag != 1) {
419  return ROSLZ4_DATA_ERROR; // Block dependence not supported
420  }
421  if (block_checksum_flag != 0) {
422  return ROSLZ4_DATA_ERROR; // Block checksums not supported
423  }
424  if (stream_checksum_flag != 1) {
425  return ROSLZ4_DATA_ERROR; // Must have stream checksum
426  }
427 
428  int header_checksum = (XXH32(header + 4, 2, 0) >> 8) & k8Bits;
429  int stored_header_checksum = (header[6] >> 0) & k8Bits;
430  if (header_checksum != stored_header_checksum) {
431  return ROSLZ4_DATA_ERROR; // Header checksum doesn't match
432  }
433 
434  int ret = streamResizeBuffer(str, block_max_id);
435  if (ret == ROSLZ4_OK) {
436  return 1;
437  } else {
438  return ret;
439  }
440 }
441 
442 // Read block size, return 1 if value is stored in state->block_size 0 otherwise
444  stream_state *state = str->state;
445  if (state->block_size_read < 4) {
446  fillUInt32(str, &state->block_size, &state->block_size_read);
447  if (state->block_size_read == 4) {
448  state->block_size = readUInt32((unsigned char*)&state->block_size);
449  state->block_uncompressed = ((unsigned)state->block_size >> 31) & k1Bits;
450  state->block_size &= 0x7FFFFFFF;
451  DEBUG("readBlockSize() Block size = %i uncompressed = %i\n",
452  state->block_size, state->block_uncompressed);
453  return 1;
454  } else {
455  return 0;
456  }
457  }
458  return 1;
459 }
460 
461 // Copy at most one blocks worth of data from input to internal buffer.
462 // Return 1 if whole block has been read, 0 if not, LZ4 error otherwise
464  stream_state *state = str->state;
465  if (state->block_size_read != 4 || state->block_size == kEndOfStream) {
466  return ROSLZ4_ERROR;
467  }
468 
469  int block_left = state->block_size - state->buffer_offset;
470  int to_copy = min(str->input_left, block_left);
471  memcpy(state->buffer + state->buffer_offset, str->input_next, to_copy);
472  advanceInput(str, to_copy);
473  state->buffer_offset += to_copy;
474  DEBUG("readBlock() Read %i bytes from input (block = %i/%i)\n",
475  to_copy, state->buffer_offset, state->block_size);
476  return state->buffer_offset == state->block_size;
477 }
478 
480  stream_state *state = str->state;
481  if (state->block_size_read != 4 || state->block_size != state->buffer_offset) {
482  // Internal error: Can't decompress block, it's not in buffer
483  return ROSLZ4_ERROR;
484  }
485 
486  if (state->block_uncompressed) {
487  if (str->output_left >= state->block_size) {
488  memcpy(str->output_next, state->buffer, state->block_size);
489  int ret = XXH32_update(state->xxh32_state, str->output_next,
490  state->block_size);
491  if (ret == XXH_ERROR) { return ROSLZ4_ERROR; }
492  advanceOutput(str, state->block_size);
493  state->block_size_read = 0;
494  state->buffer_offset = 0;
495  return ROSLZ4_OK;
496  } else {
497  return ROSLZ4_OUTPUT_SMALL;
498  }
499  } else {
500  int decomp_size;
501  decomp_size = LZ4_decompress_safe(state->buffer, str->output_next,
502  state->block_size, str->output_left);
503  if (decomp_size < 0) {
504  if (str->output_left >= state->buffer_size) {
505  return ROSLZ4_DATA_ERROR; // Must be a problem with the data stream
506  } else {
507  // Data error or output is small; increase output to disambiguate
508  return ROSLZ4_OUTPUT_SMALL;
509  }
510  } else {
511  int ret = XXH32_update(state->xxh32_state, str->output_next, decomp_size);
512  if (ret == XXH_ERROR) { return ROSLZ4_ERROR; }
513  advanceOutput(str, decomp_size);
514  state->block_size_read = 0;
515  state->buffer_offset = 0;
516  return ROSLZ4_OK;
517  }
518  }
519 }
520 
522  stream_state *state = str->state;
523  fillUInt32(str, &state->stream_checksum, &state->stream_checksum_read);
524  if (state->stream_checksum_read == 4) {
525  state->finished = 1;
526  state->stream_checksum = readUInt32((unsigned char*)&state->stream_checksum);
527  uint32_t checksum = XXH32_digest(state->xxh32_state);
528  state->xxh32_state = NULL;
529  if (checksum == state->stream_checksum) {
530  return ROSLZ4_STREAM_END;
531  } else {
532  return ROSLZ4_DATA_ERROR;
533  }
534  }
535  return ROSLZ4_OK;
536 }
537 
539  stream_state *state = str->state;
540  if (state->finished) {
541  return ROSLZ4_ERROR; // Already reached end of stream
542  }
543 
544  // Return if header isn't present or error was encountered
545  int ret = processHeader(str);
546  if (ret <= 0) {
547  return ret;
548  }
549 
550  // Read in blocks and decompress them as long as there's data to be processed
551  while (str->input_left > 0) {
552  ret = readBlockSize(str);
553  if (ret == 0) { return ROSLZ4_OK; }
554 
555  if (state->block_size == kEndOfStream) {
556  return readChecksum(str);
557  }
558 
559  ret = readBlock(str);
560  if (ret == 0) { return ROSLZ4_OK; }
561  else if (ret < 0) { return ret; }
562 
563  ret = decompressBlock(str);
564  if (ret < 0) { return ret; }
565  }
566  return ROSLZ4_OK;
567 }
568 
570  streamStateFree(str);
571 }
572 
573 /*=================== Oneshot compression / decompression ===================*/
574 
575 int roslz4_buffToBuffCompress(char *input, unsigned int input_size,
576  char *output, unsigned int *output_size,
577  int block_size_id) {
578  roslz4_stream stream;
579  stream.input_next = input;
580  stream.input_left = input_size;
581  stream.output_next = output;
582  stream.output_left = *output_size;
583 
584  int ret;
585  ret = roslz4_compressStart(&stream, block_size_id);
586  if (ret != ROSLZ4_OK) {
587  roslz4_compressEnd(&stream);
588  return ret;
589  }
590 
591  while (stream.input_left > 0 && ret != ROSLZ4_STREAM_END) {
592  ret = roslz4_compress(&stream, ROSLZ4_FINISH);
593  if (ret == ROSLZ4_ERROR || ret == ROSLZ4_OUTPUT_SMALL) {
594  roslz4_compressEnd(&stream);
595  return ret;
596  }
597  }
598 
599  *output_size = *output_size - stream.output_left;
600  roslz4_compressEnd(&stream);
601 
602  if (stream.input_left == 0 && ret == ROSLZ4_STREAM_END) {
603  return ROSLZ4_OK; // Success
604  } else {
605  return ROSLZ4_ERROR; // User did not provide exact buffer
606  }
607 }
608 
609 int roslz4_buffToBuffDecompress(char *input, unsigned int input_size,
610  char *output, unsigned int *output_size) {
611  roslz4_stream stream;
612  stream.input_next = input;
613  stream.input_left = input_size;
614  stream.output_next = output;
615  stream.output_left = *output_size;
616 
617  int ret;
618  ret = roslz4_decompressStart(&stream);
619  if (ret != ROSLZ4_OK) { return ret; }
620 
621  while (stream.input_left > 0 && ret != ROSLZ4_STREAM_END) {
622  ret = roslz4_decompress(&stream);
623  if (ret < 0) {
624  roslz4_decompressEnd(&stream);
625  return ret;
626  }
627  }
628 
629  *output_size = *output_size - stream.output_left;
630  roslz4_decompressEnd(&stream);
631 
632  if (stream.input_left == 0 && ret == ROSLZ4_STREAM_END) {
633  return ROSLZ4_OK; // Success
634  } else {
635  return ROSLZ4_ERROR; // User did not provide exact buffer
636  }
637 }
const int ROSLZ4_MEMORY_ERROR
Definition: lz4s.h:45
U32 XXH32(const void *input, int len, U32 seed)
Definition: xxhash.c:265
void * xxh32_state
Definition: lz4s.c:100
int buffer_offset
Definition: lz4s.c:96
U32 XXH32_digest(void *state_in)
Definition: xxhash.c:468
const uint8_t k1Bits
Definition: lz4s.c:65
int writeEOS(roslz4_stream *str)
Definition: lz4s.c:159
void advanceOutput(roslz4_stream *str, int nbytes)
Definition: lz4s.c:120
void * XXH32_init(U32 seed)
Definition: xxhash.c:331
void advanceInput(roslz4_stream *str, int nbytes)
Definition: lz4s.c:114
int writeHeader(roslz4_stream *str)
Definition: lz4s.c:134
int stream_checksum_read
Definition: lz4s.c:111
int total_out
Definition: lz4s.h:65
int block_size_id
Definition: lz4s.h:67
uint32_t readUInt32(unsigned char *buffer)
Definition: lz4s.c:71
const int ROSLZ4_OUTPUT_SMALL
Definition: lz4s.h:48
void roslz4_decompressEnd(roslz4_stream *str)
Definition: lz4s.c:569
int block_independence_flag
Definition: lz4s.c:90
void streamStateFree(roslz4_stream *str)
Definition: lz4s.c:295
int finished
Definition: lz4s.c:98
int total_in
Definition: lz4s.h:64
const uint8_t k2Bits
Definition: lz4s.c:66
int roslz4_compress(roslz4_stream *str, int action)
Definition: lz4s.c:319
void roslz4_compressEnd(roslz4_stream *str)
Definition: lz4s.c:355
int processHeader(roslz4_stream *str)
Definition: lz4s.c:368
char * buffer
Definition: lz4s.c:94
const int ROSLZ4_STREAM_END
Definition: lz4s.h:51
int roslz4_buffToBuffCompress(char *input, unsigned int input_size, char *output, unsigned int *output_size, int block_size_id)
Definition: lz4s.c:575
int input_left
Definition: lz4s.h:59
int readBlockSize(roslz4_stream *str)
Definition: lz4s.c:443
int block_size_read
Definition: lz4s.c:108
const uint8_t k8Bits
Definition: lz4s.c:69
int streamStateAlloc(roslz4_stream *str)
Definition: lz4s.c:245
void fillUInt32(roslz4_stream *str, uint32_t *dest_val, int *offset)
Definition: lz4s.c:126
const uint8_t k3Bits
Definition: lz4s.c:67
const int ROSLZ4_PARAM_ERROR
Definition: lz4s.h:46
char * output_next
Definition: lz4s.h:61
void * state
Definition: lz4s.h:70
int readBlock(roslz4_stream *str)
Definition: lz4s.c:463
int roslz4_decompressStart(roslz4_stream *str)
Definition: lz4s.c:361
char * input_next
Definition: lz4s.h:58
int bufferToOutput(roslz4_stream *str)
Definition: lz4s.c:180
int buffer_size
Definition: lz4s.c:95
void writeUInt32(unsigned char *buffer, uint32_t val)
Definition: lz4s.c:76
const int ROSLZ4_DATA_ERROR
Definition: lz4s.h:47
const int ROSLZ4_OK
Definition: lz4s.h:50
int block_checksum_flag
Definition: lz4s.c:91
uint32_t block_size
Definition: lz4s.c:107
#define LZ4_COMPRESS_DEFAULT
Definition: lz4s.c:57
XXH_errorcode XXH32_update(void *state_in, const void *input, int len)
Definition: xxhash.c:403
const uint32_t kEndOfStream
Definition: lz4s.c:62
int decompressBlock(roslz4_stream *str)
Definition: lz4s.c:479
const int ROSLZ4_FINISH
Definition: lz4s.h:55
int block_uncompressed
Definition: lz4s.c:109
const uint32_t kMagicNumber
Definition: lz4s.c:61
const int ROSLZ4_ERROR
Definition: lz4s.h:49
int min(int a, int b)
Definition: lz4s.c:83
int readChecksum(roslz4_stream *str)
Definition: lz4s.c:521
int streamResizeBuffer(roslz4_stream *str, int block_size_id)
Definition: lz4s.c:279
int inputToBuffer(roslz4_stream *str)
Definition: lz4s.c:224
int wrote_header
Definition: lz4s.c:103
int roslz4_decompress(roslz4_stream *str)
Definition: lz4s.c:538
#define DEBUG(...)
Definition: lz4s.c:47
const int ROSLZ4_RUN
Definition: lz4s.h:54
int stream_checksum_flag
Definition: lz4s.c:92
int output_left
Definition: lz4s.h:62
int roslz4_compressStart(roslz4_stream *str, int block_size_id)
Definition: lz4s.c:313
char header[10]
Definition: lz4s.c:106
int roslz4_blockSizeFromIndex(int block_id)
Definition: lz4s.c:309
const uint8_t k4Bits
Definition: lz4s.c:68
int roslz4_buffToBuffDecompress(char *input, unsigned int input_size, char *output, unsigned int *output_size)
Definition: lz4s.c:609
uint32_t stream_checksum
Definition: lz4s.c:110


roslz4
Author(s): Ben Charrow
autogenerated on Sun Feb 3 2019 03:29:46