lz4frame.c
Go to the documentation of this file.
1 /*
2 LZ4 auto-framing library
3 Copyright (C) 2011-2016, Yann Collet.
4 
5 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 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 disclaimer
15 in the documentation and/or other materials provided with the
16 distribution.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 You can contact the author at :
31 - LZ4 homepage : http://www.lz4.org
32 - LZ4 source repository : https://github.com/lz4/lz4
33 */
34 
35 /* LZ4F is a stand-alone API to create LZ4-compressed Frames
36 * in full conformance with specification v1.5.0
37 * All related operations, including memory management, are handled by the library.
38 * */
39 
40 
41 /*-************************************
42 * Compiler Options
43 **************************************/
44 #ifdef _MSC_VER /* Visual Studio */
45 # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
46 #endif
47 
48 
49 /*-************************************
50 * Memory routines
51 **************************************/
52 #include <stdlib.h> /* malloc, calloc, free */
53 #define ALLOCATOR(s) calloc(1,s)
54 #define FREEMEM free
55 #include <string.h> /* memset, memcpy, memmove */
56 #define MEM_INIT memset
57 
58 
59 /*-************************************
60 * Includes
61 **************************************/
62 #include "lz4frame_static.h"
63 #include "lz4.h"
64 #include "lz4hc.h"
65 #define XXH_STATIC_LINKING_ONLY
66 #include "xxhash.h"
67 
68 
69 /*-************************************
70 * Common Utils
71 **************************************/
72 #define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
73 
74 
75 /*-************************************
76 * Basic Types
77 **************************************/
78 #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
79 # include <stdint.h>
80  typedef uint8_t BYTE;
81  typedef uint16_t U16;
82  typedef uint32_t U32;
83  typedef int32_t S32;
84  typedef uint64_t U64;
85 #else
86  typedef unsigned char BYTE;
87  typedef unsigned short U16;
88  typedef unsigned int U32;
89  typedef signed int S32;
90  typedef unsigned long long U64;
91 #endif
92 
93 
94 /* unoptimized version; solves endianess & alignment issues */
95 static U32 LZ4F_readLE32 (const void* src)
96 {
97  const BYTE* const srcPtr = (const BYTE*)src;
98  U32 value32 = srcPtr[0];
99  value32 += (srcPtr[1]<<8);
100  value32 += (srcPtr[2]<<16);
101  value32 += ((U32)srcPtr[3])<<24;
102  return value32;
103 }
104 
105 static void LZ4F_writeLE32 (void* dst, U32 value32)
106 {
107  BYTE* const dstPtr = (BYTE*)dst;
108  dstPtr[0] = (BYTE)value32;
109  dstPtr[1] = (BYTE)(value32 >> 8);
110  dstPtr[2] = (BYTE)(value32 >> 16);
111  dstPtr[3] = (BYTE)(value32 >> 24);
112 }
113 
114 static U64 LZ4F_readLE64 (const void* src)
115 {
116  const BYTE* const srcPtr = (const BYTE*)src;
117  U64 value64 = srcPtr[0];
118  value64 += ((U64)srcPtr[1]<<8);
119  value64 += ((U64)srcPtr[2]<<16);
120  value64 += ((U64)srcPtr[3]<<24);
121  value64 += ((U64)srcPtr[4]<<32);
122  value64 += ((U64)srcPtr[5]<<40);
123  value64 += ((U64)srcPtr[6]<<48);
124  value64 += ((U64)srcPtr[7]<<56);
125  return value64;
126 }
127 
128 static void LZ4F_writeLE64 (void* dst, U64 value64)
129 {
130  BYTE* const dstPtr = (BYTE*)dst;
131  dstPtr[0] = (BYTE)value64;
132  dstPtr[1] = (BYTE)(value64 >> 8);
133  dstPtr[2] = (BYTE)(value64 >> 16);
134  dstPtr[3] = (BYTE)(value64 >> 24);
135  dstPtr[4] = (BYTE)(value64 >> 32);
136  dstPtr[5] = (BYTE)(value64 >> 40);
137  dstPtr[6] = (BYTE)(value64 >> 48);
138  dstPtr[7] = (BYTE)(value64 >> 56);
139 }
140 
141 
142 /*-************************************
143 * Constants
144 **************************************/
145 #define KB *(1<<10)
146 #define MB *(1<<20)
147 #define GB *(1<<30)
148 
149 #define _1BIT 0x01
150 #define _2BITS 0x03
151 #define _3BITS 0x07
152 #define _4BITS 0x0F
153 #define _8BITS 0xFF
154 
155 #define LZ4F_MAGIC_SKIPPABLE_START 0x184D2A50U
156 #define LZ4F_MAGICNUMBER 0x184D2204U
157 #define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U
158 #define LZ4F_BLOCKSIZEID_DEFAULT LZ4F_max64KB
159 
160 static const size_t minFHSize = 7;
161 static const size_t maxFHSize = LZ4F_HEADER_SIZE_MAX; /* 15 */
162 static const size_t BHSize = 4;
163 
164 
165 /*-************************************
166 * Structures and local types
167 **************************************/
168 typedef struct LZ4F_cctx_s
169 {
173  size_t maxBlockSize;
177  size_t tmpInSize;
180  void* lz4CtxPtr;
181  U32 lz4CtxLevel; /* 0: unallocated; 1: LZ4_stream_t; 3: LZ4_streamHC_t */
182 } LZ4F_cctx_t;
183 
184 
185 /*-************************************
186 * Error management
187 **************************************/
188 #define LZ4F_GENERATE_STRING(STRING) #STRING,
190 
191 
193 {
194  return (code > (LZ4F_errorCode_t)(-LZ4F_ERROR_maxCode));
195 }
196 
198 {
199  static const char* codeError = "Unspecified error code";
200  if (LZ4F_isError(code)) return LZ4F_errorStrings[-(int)(code)];
201  return codeError;
202 }
203 
204 LZ4F_errorCodes LZ4F_getErrorCode(size_t functionResult)
205 {
206  if (!LZ4F_isError(functionResult)) return LZ4F_OK_NoError;
207  return (LZ4F_errorCodes)(-(ptrdiff_t)functionResult);
208 }
209 
211 {
212  /* A compilation error here means sizeof(ptrdiff_t) is not large enough */
213  LZ4_STATIC_ASSERT(sizeof(ptrdiff_t) >= sizeof(size_t));
214  return (LZ4F_errorCode_t)-(ptrdiff_t)code;
215 }
216 
217 unsigned LZ4F_getVersion(void) { return LZ4F_VERSION; }
218 
219 
220 /*-************************************
221 * Private functions
222 **************************************/
223 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
224 
225 static size_t LZ4F_getBlockSize(unsigned blockSizeID)
226 {
227  static const size_t blockSizes[4] = { 64 KB, 256 KB, 1 MB, 4 MB };
228 
229  if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
230  blockSizeID -= 4;
231  if (blockSizeID > 3) return err0r(LZ4F_ERROR_maxBlockSize_invalid);
232  return blockSizes[blockSizeID];
233 }
234 
235 static BYTE LZ4F_headerChecksum (const void* header, size_t length)
236 {
237  U32 const xxh = XXH32(header, length, 0);
238  return (BYTE)(xxh >> 8);
239 }
240 
241 
242 /*-************************************
243 * Simple-pass compression functions
244 **************************************/
246  const size_t srcSize)
247 {
248  LZ4F_blockSizeID_t proposedBSID = LZ4F_max64KB;
249  size_t maxBlockSize = 64 KB;
250  while (requestedBSID > proposedBSID) {
251  if (srcSize <= maxBlockSize)
252  return proposedBSID;
253  proposedBSID = (LZ4F_blockSizeID_t)((int)proposedBSID + 1);
254  maxBlockSize <<= 2;
255  }
256  return requestedBSID;
257 }
258 
259 /* LZ4F_compressBound() :
260  * Provides dstCapacity given a srcSize to guarantee operation success in worst case situations.
261  * prefsPtr is optional : if NULL is provided, preferences will be set to cover worst case scenario.
262  * Result is always the same for a srcSize and prefsPtr, so it can be relied upon to size reusable buffers.
263  * When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() operations.
264  */
265 static size_t LZ4F_compressBound_internal(size_t srcSize,
266  const LZ4F_preferences_t* preferencesPtr,
267  size_t alreadyBuffered)
268 {
269  LZ4F_preferences_t prefsNull;
270  memset(&prefsNull, 0, sizeof(prefsNull));
271  prefsNull.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; /* worst case */
272  { const LZ4F_preferences_t* const prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
273  U32 const flush = prefsPtr->autoFlush | (srcSize==0);
274  LZ4F_blockSizeID_t const bid = prefsPtr->frameInfo.blockSizeID;
275  size_t const blockSize = LZ4F_getBlockSize(bid);
276  size_t const maxBuffered = blockSize - 1;
277  size_t const bufferedSize = MIN(alreadyBuffered, maxBuffered);
278  size_t const maxSrcSize = srcSize + bufferedSize;
279  unsigned const nbFullBlocks = (unsigned)(maxSrcSize / blockSize);
280  size_t const partialBlockSize = (srcSize - (srcSize==0)) & (blockSize-1); /* 0 => -1 == MAX => blockSize-1 */
281  size_t const lastBlockSize = flush ? partialBlockSize : 0;
282  unsigned const nbBlocks = nbFullBlocks + (lastBlockSize>0);
283 
284  size_t const blockHeaderSize = 4; /* default, without block CRC option (which cannot be generated with current API) */
285  size_t const frameEnd = 4 + (prefsPtr->frameInfo.contentChecksumFlag*4);
286 
287  return (blockHeaderSize * nbBlocks) + (blockSize * nbFullBlocks) + lastBlockSize + frameEnd;;
288  }
289 }
290 
291 size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
292 {
294  size_t const headerSize = maxFHSize; /* max header size, including magic number and frame content size */
295 
296  if (preferencesPtr!=NULL) prefs = *preferencesPtr;
297  else memset(&prefs, 0, sizeof(prefs));
298  prefs.autoFlush = 1;
299 
300  return headerSize + LZ4F_compressBound_internal(srcSize, &prefs, 0);;
301 }
302 
303 
313 size_t LZ4F_compressFrame(void* dstBuffer, size_t dstCapacity, const void* srcBuffer, size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
314 {
315  LZ4F_cctx_t cctxI;
316  LZ4_stream_t lz4ctx;
318  LZ4F_compressOptions_t options;
319  BYTE* const dstStart = (BYTE*) dstBuffer;
320  BYTE* dstPtr = dstStart;
321  BYTE* const dstEnd = dstStart + dstCapacity;
322 
323  memset(&cctxI, 0, sizeof(cctxI));
324  memset(&options, 0, sizeof(options));
325 
326  cctxI.version = LZ4F_VERSION;
327  cctxI.maxBufferSize = 5 MB; /* mess with real buffer size to prevent dynamic allocation; works because autoflush==1 & stableSrc==1 */
328 
329  if (preferencesPtr!=NULL)
330  prefs = *preferencesPtr;
331  else
332  memset(&prefs, 0, sizeof(prefs));
333  if (prefs.frameInfo.contentSize != 0)
334  prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */
335 
336  if (prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
337  cctxI.lz4CtxPtr = &lz4ctx;
338  cctxI.lz4CtxLevel = 1;
339  } /* otherwise : will be created within LZ4F_compressBegin */
340 
342  prefs.autoFlush = 1;
343  if (srcSize <= LZ4F_getBlockSize(prefs.frameInfo.blockSizeID))
344  prefs.frameInfo.blockMode = LZ4F_blockIndependent; /* no need for linked blocks */
345 
346  options.stableSrc = 1;
347 
348  if (dstCapacity < LZ4F_compressFrameBound(srcSize, &prefs)) /* condition to guarantee success */
349  return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
350 
351  { size_t const headerSize = LZ4F_compressBegin(&cctxI, dstBuffer, dstCapacity, &prefs); /* write header */
352  if (LZ4F_isError(headerSize)) return headerSize;
353  dstPtr += headerSize; /* header size */ }
354 
355  { size_t const cSize = LZ4F_compressUpdate(&cctxI, dstPtr, dstEnd-dstPtr, srcBuffer, srcSize, &options);
356  if (LZ4F_isError(cSize)) return cSize;
357  dstPtr += cSize; }
358 
359  { size_t const tailSize = LZ4F_compressEnd(&cctxI, dstPtr, dstEnd-dstPtr, &options); /* flush last block, and generate suffix */
360  if (LZ4F_isError(tailSize)) return tailSize;
361  dstPtr += tailSize; }
362 
363  if (prefs.compressionLevel >= LZ4HC_CLEVEL_MIN) /* Ctx allocation only for lz4hc */
364  FREEMEM(cctxI.lz4CtxPtr);
365 
366  return (dstPtr - dstStart);
367 }
368 
369 
370 /*-*********************************
371 * Advanced compression functions
372 ***********************************/
373 
383 {
384  LZ4F_cctx_t* const cctxPtr = (LZ4F_cctx_t*)ALLOCATOR(sizeof(LZ4F_cctx_t));
385  if (cctxPtr==NULL) return err0r(LZ4F_ERROR_allocation_failed);
386 
387  cctxPtr->version = version;
388  cctxPtr->cStage = 0; /* Next stage : write header */
389 
390  *LZ4F_compressionContextPtr = (LZ4F_compressionContext_t)cctxPtr;
391 
392  return LZ4F_OK_NoError;
393 }
394 
395 
397 {
398  LZ4F_cctx_t* const cctxPtr = (LZ4F_cctx_t*)LZ4F_compressionContext;
399 
400  if (cctxPtr != NULL) { /* null pointers can be safely provided to this function, like free() */
401  FREEMEM(cctxPtr->lz4CtxPtr);
402  FREEMEM(cctxPtr->tmpBuff);
403  FREEMEM(LZ4F_compressionContext);
404  }
405 
406  return LZ4F_OK_NoError;
407 }
408 
409 
416 size_t LZ4F_compressBegin(LZ4F_cctx* cctxPtr, void* dstBuffer, size_t dstCapacity, const LZ4F_preferences_t* preferencesPtr)
417 {
418  LZ4F_preferences_t prefNull;
419  BYTE* const dstStart = (BYTE*)dstBuffer;
420  BYTE* dstPtr = dstStart;
421  BYTE* headerStart;
422  size_t requiredBuffSize;
423 
424  if (dstCapacity < maxFHSize) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
425  if (cctxPtr->cStage != 0) return err0r(LZ4F_ERROR_GENERIC);
426  memset(&prefNull, 0, sizeof(prefNull));
427  if (preferencesPtr == NULL) preferencesPtr = &prefNull;
428  cctxPtr->prefs = *preferencesPtr;
429 
430  /* Ctx Management */
431  { U32 const tableID = (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */
432  if (cctxPtr->lz4CtxLevel < tableID) {
433  FREEMEM(cctxPtr->lz4CtxPtr);
434  if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
435  cctxPtr->lz4CtxPtr = (void*)LZ4_createStream();
436  else
437  cctxPtr->lz4CtxPtr = (void*)LZ4_createStreamHC();
438  if (cctxPtr->lz4CtxPtr == NULL) return err0r(LZ4F_ERROR_allocation_failed);
439  cctxPtr->lz4CtxLevel = tableID;
440  }
441  }
442 
443  /* Buffer Management */
446 
447  requiredBuffSize = cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 128 KB);
448  if (preferencesPtr->autoFlush)
449  requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB; /* just needs dict */
450 
451  if (cctxPtr->maxBufferSize < requiredBuffSize) {
452  cctxPtr->maxBufferSize = 0;
453  FREEMEM(cctxPtr->tmpBuff);
454  cctxPtr->tmpBuff = (BYTE*)ALLOCATOR(requiredBuffSize);
455  if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed);
456  cctxPtr->maxBufferSize = requiredBuffSize;
457  }
458  cctxPtr->tmpIn = cctxPtr->tmpBuff;
459  cctxPtr->tmpInSize = 0;
460  XXH32_reset(&(cctxPtr->xxh), 0);
461  if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
462  LZ4_resetStream((LZ4_stream_t*)(cctxPtr->lz4CtxPtr));
463  else
465 
466  /* Magic Number */
468  dstPtr += 4;
469  headerStart = dstPtr;
470 
471  /* FLG Byte */
472  *dstPtr++ = (BYTE)(((1 & _2BITS) << 6) /* Version('01') */
473  + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5) /* Block mode */
474  + ((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2) /* Frame checksum */
475  + ((cctxPtr->prefs.frameInfo.contentSize > 0) << 3)); /* Frame content size */
476  /* BD Byte */
477  *dstPtr++ = (BYTE)((cctxPtr->prefs.frameInfo.blockSizeID & _3BITS) << 4);
478  /* Optional Frame content size field */
479  if (cctxPtr->prefs.frameInfo.contentSize) {
480  LZ4F_writeLE64(dstPtr, cctxPtr->prefs.frameInfo.contentSize);
481  dstPtr += 8;
482  cctxPtr->totalInSize = 0;
483  }
484  /* CRC Byte */
485  *dstPtr = LZ4F_headerChecksum(headerStart, dstPtr - headerStart);
486  dstPtr++;
487 
488  cctxPtr->cStage = 1; /* header written, now request input data block */
489 
490  return (dstPtr - dstStart);
491 }
492 
493 
494 /* LZ4F_compressBound() :
495  * @ return size of Dst buffer given a srcSize to handle worst case situations.
496  * The LZ4F_frameInfo_t structure is optional : if NULL, preferences will be set to cover worst case situations.
497  * This function cannot fail.
498  */
499 size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
500 {
501  return LZ4F_compressBound_internal(srcSize, preferencesPtr, (size_t)-1);
502 }
503 
504 
505 typedef int (*compressFunc_t)(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level);
506 
507 static size_t LZ4F_compressBlock(void* dst, const void* src, size_t srcSize, compressFunc_t compress, void* lz4ctx, int level)
508 {
509  /* compress a single block */
510  BYTE* const cSizePtr = (BYTE*)dst;
511  U32 cSize = (U32)compress(lz4ctx, (const char*)src, (char*)(cSizePtr+4), (int)(srcSize), (int)(srcSize-1), level);
512  LZ4F_writeLE32(cSizePtr, cSize);
513  if (cSize == 0) { /* compression failed */
514  cSize = (U32)srcSize;
515  LZ4F_writeLE32(cSizePtr, cSize | LZ4F_BLOCKUNCOMPRESSED_FLAG);
516  memcpy(cSizePtr+4, src, srcSize);
517  }
518  return cSize + 4;
519 }
520 
521 
522 static int LZ4F_localLZ4_compress_limitedOutput_withState(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level)
523 {
524  int const acceleration = (level < -1) ? -level : 1;
525  return LZ4_compress_fast_extState(ctx, src, dst, srcSize, dstCapacity, acceleration);
526 }
527 
528 static int LZ4F_localLZ4_compress_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstCapacity, int level)
529 {
530  int const acceleration = (level < -1) ? -level : 1;
531  return LZ4_compress_fast_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstCapacity, acceleration);
532 }
533 
534 static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level)
535 {
536  (void) level;
537  return LZ4_compress_HC_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize);
538 }
539 
541 {
542  if (level < LZ4HC_CLEVEL_MIN) {
545  }
546  if (blockMode == LZ4F_blockIndependent) return LZ4_compress_HC_extStateHC;
548 }
549 
550 static int LZ4F_localSaveDict(LZ4F_cctx_t* cctxPtr)
551 {
552  if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
553  return LZ4_saveDict ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB);
554  return LZ4_saveDictHC ((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB);
555 }
556 
558 
568 size_t LZ4F_compressUpdate(LZ4F_cctx* cctxPtr, void* dstBuffer, size_t dstCapacity, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* compressOptionsPtr)
569 {
570  LZ4F_compressOptions_t cOptionsNull;
571  size_t const blockSize = cctxPtr->maxBlockSize;
572  const BYTE* srcPtr = (const BYTE*)srcBuffer;
573  const BYTE* const srcEnd = srcPtr + srcSize;
574  BYTE* const dstStart = (BYTE*)dstBuffer;
575  BYTE* dstPtr = dstStart;
576  LZ4F_lastBlockStatus lastBlockCompressed = notDone;
578 
579 
580  if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
581  if (dstCapacity < LZ4F_compressBound_internal(srcSize, &(cctxPtr->prefs), cctxPtr->tmpInSize)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
582  memset(&cOptionsNull, 0, sizeof(cOptionsNull));
583  if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
584 
585  /* complete tmp buffer */
586  if (cctxPtr->tmpInSize > 0) { /* some data already within tmp buffer */
587  size_t const sizeToCopy = blockSize - cctxPtr->tmpInSize;
588  if (sizeToCopy > srcSize) {
589  /* add src to tmpIn buffer */
590  memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, srcSize);
591  srcPtr = srcEnd;
592  cctxPtr->tmpInSize += srcSize;
593  /* still needs some CRC */
594  } else {
595  /* complete tmpIn block and then compress it */
596  lastBlockCompressed = fromTmpBuffer;
597  memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, sizeToCopy);
598  srcPtr += sizeToCopy;
599 
600  dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, blockSize, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
601 
602  if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += blockSize;
603  cctxPtr->tmpInSize = 0;
604  }
605  }
606 
607  while ((size_t)(srcEnd - srcPtr) >= blockSize) {
608  /* compress full block */
609  lastBlockCompressed = fromSrcBuffer;
610  dstPtr += LZ4F_compressBlock(dstPtr, srcPtr, blockSize, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
611  srcPtr += blockSize;
612  }
613 
614  if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) {
615  /* compress remaining input < blockSize */
616  lastBlockCompressed = fromSrcBuffer;
617  dstPtr += LZ4F_compressBlock(dstPtr, srcPtr, srcEnd - srcPtr, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
618  srcPtr = srcEnd;
619  }
620 
621  /* preserve dictionary if necessary */
622  if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) {
623  if (compressOptionsPtr->stableSrc) {
624  cctxPtr->tmpIn = cctxPtr->tmpBuff;
625  } else {
626  int const realDictSize = LZ4F_localSaveDict(cctxPtr);
627  if (realDictSize==0) return err0r(LZ4F_ERROR_GENERIC);
628  cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize;
629  }
630  }
631 
632  /* keep tmpIn within limits */
633  if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily LZ4F_blockLinked && lastBlockCompressed==fromTmpBuffer */
634  && !(cctxPtr->prefs.autoFlush))
635  {
636  int const realDictSize = LZ4F_localSaveDict(cctxPtr);
637  cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize;
638  }
639 
640  /* some input data left, necessarily < blockSize */
641  if (srcPtr < srcEnd) {
642  /* fill tmp buffer */
643  size_t const sizeToCopy = srcEnd - srcPtr;
644  memcpy(cctxPtr->tmpIn, srcPtr, sizeToCopy);
645  cctxPtr->tmpInSize = sizeToCopy;
646  }
647 
649  XXH32_update(&(cctxPtr->xxh), srcBuffer, srcSize);
650 
651  cctxPtr->totalInSize += srcSize;
652  return dstPtr - dstStart;
653 }
654 
655 
664 size_t LZ4F_flush(LZ4F_cctx* cctxPtr, void* dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t* compressOptionsPtr)
665 {
666  BYTE* const dstStart = (BYTE*)dstBuffer;
667  BYTE* dstPtr = dstStart;
668  compressFunc_t compress;
669 
670  if (cctxPtr->tmpInSize == 0) return 0; /* nothing to flush */
671  if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
672  if (dstCapacity < (cctxPtr->tmpInSize + 4)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall); /* +4 : block header(4) */
673  (void)compressOptionsPtr; /* not yet useful */
674 
675  /* select compression function */
676  compress = LZ4F_selectCompression(cctxPtr->prefs.frameInfo.blockMode, cctxPtr->prefs.compressionLevel);
677 
678  /* compress tmp buffer */
679  dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, cctxPtr->tmpInSize, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
680  if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize;
681  cctxPtr->tmpInSize = 0;
682 
683  /* keep tmpIn within limits */
684  if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) { /* necessarily LZ4F_blockLinked */
685  int realDictSize = LZ4F_localSaveDict(cctxPtr);
686  cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize;
687  }
688 
689  return dstPtr - dstStart;
690 }
691 
692 
702 size_t LZ4F_compressEnd(LZ4F_cctx* cctxPtr, void* dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t* compressOptionsPtr)
703 {
704  BYTE* const dstStart = (BYTE*)dstBuffer;
705  BYTE* dstPtr = dstStart;
706 
707  size_t const flushSize = LZ4F_flush(cctxPtr, dstBuffer, dstMaxSize, compressOptionsPtr);
708  if (LZ4F_isError(flushSize)) return flushSize;
709  dstPtr += flushSize;
710 
711  LZ4F_writeLE32(dstPtr, 0);
712  dstPtr+=4; /* endMark */
713 
715  U32 const xxh = XXH32_digest(&(cctxPtr->xxh));
716  LZ4F_writeLE32(dstPtr, xxh);
717  dstPtr+=4; /* content Checksum */
718  }
719 
720  cctxPtr->cStage = 0; /* state is now re-usable (with identical preferences) */
721  cctxPtr->maxBufferSize = 0; /* reuse HC context */
722 
723  if (cctxPtr->prefs.frameInfo.contentSize) {
724  if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize)
725  return err0r(LZ4F_ERROR_frameSize_wrong);
726  }
727 
728  return dstPtr - dstStart;
729 }
730 
731 
732 /*-***************************************************
733 * Frame Decompression
734 *****************************************************/
735 
736 struct LZ4F_dctx_s {
741  size_t maxBlockSize;
744  size_t tmpInSize;
745  size_t tmpInTarget;
747  const BYTE* dict;
748  size_t dictSize;
750  size_t tmpOutSize;
751  size_t tmpOutStart;
754 }; /* typedef'd to LZ4F_dctx in lz4frame.h */
755 
756 
763 LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx** LZ4F_decompressionContextPtr, unsigned versionNumber)
764 {
765  LZ4F_dctx* const dctxPtr = (LZ4F_dctx*)ALLOCATOR(sizeof(LZ4F_dctx));
766  if (dctxPtr==NULL) return err0r(LZ4F_ERROR_GENERIC);
767 
768  dctxPtr->version = versionNumber;
769  *LZ4F_decompressionContextPtr = dctxPtr;
770  return LZ4F_OK_NoError;
771 }
772 
774 {
775  LZ4F_errorCode_t result = LZ4F_OK_NoError;
776  if (dctxPtr != NULL) { /* can accept NULL input, like free() */
777  result = (LZ4F_errorCode_t)dctxPtr->dStage;
778  FREEMEM(dctxPtr->tmpIn);
779  FREEMEM(dctxPtr->tmpOutBuffer);
780  FREEMEM(dctxPtr);
781  }
782  return result;
783 }
784 
785 
786 /*==--- Streaming Decompression operations ---==*/
787 
788 typedef enum {
799 } dStage_t;
800 
802 {
803  dctx->dStage = dstage_getHeader;
804 }
805 
806 
811 static size_t LZ4F_headerSize(const void* src, size_t srcSize)
812 {
813  /* minimal srcSize to determine header size */
814  if (srcSize < 5) return err0r(LZ4F_ERROR_frameHeader_incomplete);
815 
816  /* special case : skippable frames */
817  if ((LZ4F_readLE32(src) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) return 8;
818 
819  /* control magic number */
820  if (LZ4F_readLE32(src) != LZ4F_MAGICNUMBER) return err0r(LZ4F_ERROR_frameType_unknown);
821 
822  /* Frame Header Size */
823  { BYTE const FLG = ((const BYTE*)src)[4];
824  U32 const contentSizeFlag = (FLG>>3) & _1BIT;
825  return contentSizeFlag ? maxFHSize : minFHSize;
826  }
827 }
828 
829 
838 static size_t LZ4F_decodeHeader(LZ4F_dctx* dctxPtr, const void* src, size_t srcSize)
839 {
840  unsigned blockMode, contentSizeFlag, contentChecksumFlag, blockSizeID;
841  size_t frameHeaderSize;
842  const BYTE* srcPtr = (const BYTE*)src;
843 
844  /* need to decode header to get frameInfo */
845  if (srcSize < minFHSize) return err0r(LZ4F_ERROR_frameHeader_incomplete); /* minimal frame header size */
846  memset(&(dctxPtr->frameInfo), 0, sizeof(dctxPtr->frameInfo));
847 
848  /* special case : skippable frames */
849  if ((LZ4F_readLE32(srcPtr) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) {
851  if (src == (void*)(dctxPtr->header)) {
852  dctxPtr->tmpInSize = srcSize;
853  dctxPtr->tmpInTarget = 8;
854  dctxPtr->dStage = dstage_storeSFrameSize;
855  return srcSize;
856  } else {
857  dctxPtr->dStage = dstage_getSFrameSize;
858  return 4;
859  }
860  }
861 
862  /* control magic number */
863  if (LZ4F_readLE32(srcPtr) != LZ4F_MAGICNUMBER) return err0r(LZ4F_ERROR_frameType_unknown);
864  dctxPtr->frameInfo.frameType = LZ4F_frame;
865 
866  /* Flags */
867  { U32 const FLG = srcPtr[4];
868  U32 const version = (FLG>>6) & _2BITS;
869  U32 const blockChecksumFlag = (FLG>>4) & _1BIT;
870  blockMode = (FLG>>5) & _1BIT;
871  contentSizeFlag = (FLG>>3) & _1BIT;
872  contentChecksumFlag = (FLG>>2) & _1BIT;
873  /* validate */
874  if (((FLG>>0)&_2BITS) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bits */
875  if (version != 1) return err0r(LZ4F_ERROR_headerVersion_wrong); /* Version Number, only supported value */
876  if (blockChecksumFlag != 0) return err0r(LZ4F_ERROR_blockChecksum_unsupported); /* Not supported for the time being */
877  }
878 
879  /* Frame Header Size */
880  frameHeaderSize = contentSizeFlag ? maxFHSize : minFHSize;
881 
882  if (srcSize < frameHeaderSize) {
883  /* not enough input to fully decode frame header */
884  if (srcPtr != dctxPtr->header)
885  memcpy(dctxPtr->header, srcPtr, srcSize);
886  dctxPtr->tmpInSize = srcSize;
887  dctxPtr->tmpInTarget = frameHeaderSize;
888  dctxPtr->dStage = dstage_storeHeader;
889  return srcSize;
890  }
891 
892  { U32 const BD = srcPtr[5];
893  blockSizeID = (BD>>4) & _3BITS;
894  /* validate */
895  if (((BD>>7)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bit */
896  if (blockSizeID < 4) return err0r(LZ4F_ERROR_maxBlockSize_invalid); /* 4-7 only supported values for the time being */
897  if (((BD>>0)&_4BITS) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bits */
898  }
899 
900  /* check header */
901  { BYTE const HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5);
902  if (HC != srcPtr[frameHeaderSize-1]) return err0r(LZ4F_ERROR_headerChecksum_invalid); }
903 
904  /* save */
905  dctxPtr->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode;
906  dctxPtr->frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)contentChecksumFlag;
907  dctxPtr->frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID;
908  dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID);
909  if (contentSizeFlag)
910  dctxPtr->frameRemainingSize = dctxPtr->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6);
911 
912  dctxPtr->dStage = dstage_init;
913 
914  return frameHeaderSize;
915 }
916 
917 
934  const void* srcBuffer, size_t* srcSizePtr)
935 {
936  if (dctxPtr->dStage > dstage_storeHeader) { /* assumption : dstage_* header enum at beginning of range */
937  /* frameInfo already decoded */
938  size_t o=0, i=0;
939  *srcSizePtr = 0;
940  *frameInfoPtr = dctxPtr->frameInfo;
941  /* returns : recommended nb of bytes for LZ4F_decompress() */
942  return LZ4F_decompress(dctxPtr, NULL, &o, NULL, &i, NULL);
943  } else {
944  if (dctxPtr->dStage == dstage_storeHeader) {
945  /* frame decoding already started, in the middle of header => automatic fail */
946  *srcSizePtr = 0;
947  return err0r(LZ4F_ERROR_frameDecoding_alreadyStarted);
948  } else {
949  size_t decodeResult;
950  size_t const hSize = LZ4F_headerSize(srcBuffer, *srcSizePtr);
951  if (LZ4F_isError(hSize)) { *srcSizePtr=0; return hSize; }
952  if (*srcSizePtr < hSize) {
953  *srcSizePtr=0;
954  return err0r(LZ4F_ERROR_frameHeader_incomplete);
955  }
956 
957  decodeResult = LZ4F_decodeHeader(dctxPtr, srcBuffer, hSize);
958  if (LZ4F_isError(decodeResult)) {
959  *srcSizePtr = 0;
960  } else {
961  *srcSizePtr = decodeResult;
962  decodeResult = BHSize; /* block header size */
963  }
964  *frameInfoPtr = dctxPtr->frameInfo;
965  return decodeResult;
966  } }
967 }
968 
969 
970 /* trivial redirector, for common prototype */
971 static int LZ4F_decompress_safe (const char* src,
972  char* dst,
973  int compressedSize,
974  int dstCapacity,
975  const char* dictStart,
976  int dictSize)
977 {
978  (void)dictStart; (void)dictSize;
979  return LZ4_decompress_safe (src, dst, compressedSize, dstCapacity);
980 }
981 
982 
983 static void LZ4F_updateDict(LZ4F_dctx* dctxPtr, const BYTE* dstPtr, size_t dstSize, const BYTE* dstPtr0, unsigned withinTmp)
984 {
985  if (dctxPtr->dictSize==0)
986  dctxPtr->dict = (const BYTE*)dstPtr; /* priority to dictionary continuity */
987 
988  if (dctxPtr->dict + dctxPtr->dictSize == dstPtr) { /* dictionary continuity */
989  dctxPtr->dictSize += dstSize;
990  return;
991  }
992 
993  if (dstPtr - dstPtr0 + dstSize >= 64 KB) { /* dstBuffer large enough to become dictionary */
994  dctxPtr->dict = (const BYTE*)dstPtr0;
995  dctxPtr->dictSize = dstPtr - dstPtr0 + dstSize;
996  return;
997  }
998 
999  if ((withinTmp) && (dctxPtr->dict == dctxPtr->tmpOutBuffer)) {
1000  /* assumption : dctxPtr->dict + dctxPtr->dictSize == dctxPtr->tmpOut + dctxPtr->tmpOutStart */
1001  dctxPtr->dictSize += dstSize;
1002  return;
1003  }
1004 
1005  if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
1006  size_t const preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
1007  size_t copySize = 64 KB - dctxPtr->tmpOutSize;
1008  const BYTE* const oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
1009  if (dctxPtr->tmpOutSize > 64 KB) copySize = 0;
1010  if (copySize > preserveSize) copySize = preserveSize;
1011 
1012  memcpy(dctxPtr->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize);
1013 
1014  dctxPtr->dict = dctxPtr->tmpOutBuffer;
1015  dctxPtr->dictSize = preserveSize + dctxPtr->tmpOutStart + dstSize;
1016  return;
1017  }
1018 
1019  if (dctxPtr->dict == dctxPtr->tmpOutBuffer) { /* copy dst into tmp to complete dict */
1020  if (dctxPtr->dictSize + dstSize > dctxPtr->maxBufferSize) { /* tmp buffer not large enough */
1021  size_t const preserveSize = 64 KB - dstSize; /* note : dstSize < 64 KB */
1022  memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize);
1023  dctxPtr->dictSize = preserveSize;
1024  }
1025  memcpy(dctxPtr->tmpOutBuffer + dctxPtr->dictSize, dstPtr, dstSize);
1026  dctxPtr->dictSize += dstSize;
1027  return;
1028  }
1029 
1030  /* join dict & dest into tmp */
1031  { size_t preserveSize = 64 KB - dstSize; /* note : dstSize < 64 KB */
1032  if (preserveSize > dctxPtr->dictSize) preserveSize = dctxPtr->dictSize;
1033  memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize);
1034  memcpy(dctxPtr->tmpOutBuffer + preserveSize, dstPtr, dstSize);
1035  dctxPtr->dict = dctxPtr->tmpOutBuffer;
1036  dctxPtr->dictSize = preserveSize + dstSize;
1037  }
1038 }
1039 
1040 
1041 
1059 size_t LZ4F_decompress(LZ4F_dctx* dctxPtr,
1060  void* dstBuffer, size_t* dstSizePtr,
1061  const void* srcBuffer, size_t* srcSizePtr,
1062  const LZ4F_decompressOptions_t* decompressOptionsPtr)
1063 {
1064  LZ4F_decompressOptions_t optionsNull;
1065  const BYTE* const srcStart = (const BYTE*)srcBuffer;
1066  const BYTE* const srcEnd = srcStart + *srcSizePtr;
1067  const BYTE* srcPtr = srcStart;
1068  BYTE* const dstStart = (BYTE*)dstBuffer;
1069  BYTE* const dstEnd = dstStart + *dstSizePtr;
1070  BYTE* dstPtr = dstStart;
1071  const BYTE* selectedIn = NULL;
1072  unsigned doAnotherStage = 1;
1073  size_t nextSrcSizeHint = 1;
1074 
1075 
1076  memset(&optionsNull, 0, sizeof(optionsNull));
1077  if (decompressOptionsPtr==NULL) decompressOptionsPtr = &optionsNull;
1078  *srcSizePtr = 0;
1079  *dstSizePtr = 0;
1080 
1081  /* behaves like a state machine */
1082 
1083  while (doAnotherStage) {
1084 
1085  switch(dctxPtr->dStage)
1086  {
1087 
1088  case dstage_getHeader:
1089  if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */
1090  LZ4F_errorCode_t const hSize = LZ4F_decodeHeader(dctxPtr, srcPtr, srcEnd-srcPtr); /* will change dStage appropriately */
1091  if (LZ4F_isError(hSize)) return hSize;
1092  srcPtr += hSize;
1093  break;
1094  }
1095  dctxPtr->tmpInSize = 0;
1096  if (srcEnd-srcPtr == 0) return minFHSize; /* 0-size input */
1097  dctxPtr->tmpInTarget = minFHSize; /* minimum to attempt decode */
1098  dctxPtr->dStage = dstage_storeHeader;
1099  /* fall-through */
1100 
1101  case dstage_storeHeader:
1102  { size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1103  if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1104  memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1105  dctxPtr->tmpInSize += sizeToCopy;
1106  srcPtr += sizeToCopy;
1107  if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) {
1108  nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize; /* rest of header + nextBlockHeader */
1109  doAnotherStage = 0; /* not enough src data, ask for some more */
1110  break;
1111  }
1112  { LZ4F_errorCode_t const hSize = LZ4F_decodeHeader(dctxPtr, dctxPtr->header, dctxPtr->tmpInTarget); /* will change dStage appropriately */
1113  if (LZ4F_isError(hSize)) return hSize;
1114  }
1115  break;
1116  }
1117 
1118  case dstage_init:
1119  if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0);
1120  /* internal buffers allocation */
1121  { size_t const bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB);
1122  if (bufferNeeded > dctxPtr->maxBufferSize) { /* tmp buffers too small */
1123  dctxPtr->maxBufferSize = 0; /* ensure allocation will be re-attempted on next entry*/
1124  FREEMEM(dctxPtr->tmpIn);
1125  dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize);
1126  if (dctxPtr->tmpIn == NULL) return err0r(LZ4F_ERROR_allocation_failed);
1127  FREEMEM(dctxPtr->tmpOutBuffer);
1128  dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(bufferNeeded);
1129  if (dctxPtr->tmpOutBuffer== NULL) return err0r(LZ4F_ERROR_allocation_failed);
1130  dctxPtr->maxBufferSize = bufferNeeded;
1131  } }
1132  dctxPtr->tmpInSize = 0;
1133  dctxPtr->tmpInTarget = 0;
1134  dctxPtr->dict = dctxPtr->tmpOutBuffer;
1135  dctxPtr->dictSize = 0;
1136  dctxPtr->tmpOut = dctxPtr->tmpOutBuffer;
1137  dctxPtr->tmpOutStart = 0;
1138  dctxPtr->tmpOutSize = 0;
1139 
1140  dctxPtr->dStage = dstage_getCBlockSize;
1141  /* fall-through */
1142 
1143  case dstage_getCBlockSize:
1144  if ((size_t)(srcEnd - srcPtr) >= BHSize) {
1145  selectedIn = srcPtr;
1146  srcPtr += BHSize;
1147  } else {
1148  /* not enough input to read cBlockSize field */
1149  dctxPtr->tmpInSize = 0;
1150  dctxPtr->dStage = dstage_storeCBlockSize;
1151  }
1152 
1153  if (dctxPtr->dStage == dstage_storeCBlockSize) /* can be skipped */
1155  { size_t sizeToCopy = BHSize - dctxPtr->tmpInSize;
1156  if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1157  memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1158  srcPtr += sizeToCopy;
1159  dctxPtr->tmpInSize += sizeToCopy;
1160  if (dctxPtr->tmpInSize < BHSize) { /* not enough input for cBlockSize */
1161  nextSrcSizeHint = BHSize - dctxPtr->tmpInSize;
1162  doAnotherStage = 0;
1163  break;
1164  }
1165  selectedIn = dctxPtr->tmpIn;
1166  }
1167 
1168  /* case dstage_decodeCBlockSize: */ /* no more direct access, to remove scan-build warning */
1169  { size_t const nextCBlockSize = LZ4F_readLE32(selectedIn) & 0x7FFFFFFFU;
1170  if (nextCBlockSize==0) { /* frameEnd signal, no more CBlock */
1171  dctxPtr->dStage = dstage_getSuffix;
1172  break;
1173  }
1174  if (nextCBlockSize > dctxPtr->maxBlockSize)
1175  return err0r(LZ4F_ERROR_maxBlockSize_invalid);
1176  dctxPtr->tmpInTarget = nextCBlockSize;
1177  if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
1178  dctxPtr->dStage = dstage_copyDirect;
1179  break;
1180  }
1181  dctxPtr->dStage = dstage_getCBlock;
1182  if (dstPtr==dstEnd) {
1183  nextSrcSizeHint = nextCBlockSize + BHSize;
1184  doAnotherStage = 0;
1185  }
1186  break;
1187  }
1188 
1189  case dstage_copyDirect: /* uncompressed block */
1190  { size_t sizeToCopy = dctxPtr->tmpInTarget;
1191  if ((size_t)(srcEnd-srcPtr) < sizeToCopy) sizeToCopy = srcEnd - srcPtr;
1192  if ((size_t)(dstEnd-dstPtr) < sizeToCopy) sizeToCopy = dstEnd - dstPtr;
1193  memcpy(dstPtr, srcPtr, sizeToCopy);
1194  if (dctxPtr->frameInfo.contentChecksumFlag)
1195  XXH32_update(&(dctxPtr->xxh), srcPtr, sizeToCopy);
1196  if (dctxPtr->frameInfo.contentSize)
1197  dctxPtr->frameRemainingSize -= sizeToCopy;
1198 
1199  /* dictionary management */
1200  if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1201  LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 0);
1202 
1203  srcPtr += sizeToCopy;
1204  dstPtr += sizeToCopy;
1205  if (sizeToCopy == dctxPtr->tmpInTarget) { /* all copied */
1206  dctxPtr->dStage = dstage_getCBlockSize;
1207  break;
1208  }
1209  dctxPtr->tmpInTarget -= sizeToCopy; /* still need to copy more */
1210  nextSrcSizeHint = dctxPtr->tmpInTarget + BHSize;
1211  doAnotherStage = 0;
1212  break;
1213  }
1214 
1215  case dstage_getCBlock: /* entry from dstage_decodeCBlockSize */
1216  if ((size_t)(srcEnd-srcPtr) < dctxPtr->tmpInTarget) {
1217  dctxPtr->tmpInSize = 0;
1218  dctxPtr->dStage = dstage_storeCBlock;
1219  break;
1220  }
1221  selectedIn = srcPtr;
1222  srcPtr += dctxPtr->tmpInTarget;
1223  dctxPtr->dStage = dstage_decodeCBlock;
1224  break;
1225 
1226  case dstage_storeCBlock:
1227  { size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1228  if (sizeToCopy > (size_t)(srcEnd-srcPtr)) sizeToCopy = srcEnd-srcPtr;
1229  memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1230  dctxPtr->tmpInSize += sizeToCopy;
1231  srcPtr += sizeToCopy;
1232  if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) { /* need more input */
1233  nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize;
1234  doAnotherStage=0;
1235  break;
1236  }
1237  selectedIn = dctxPtr->tmpIn;
1238  dctxPtr->dStage = dstage_decodeCBlock;
1239  }
1240  /* fall-through */
1241 
1242  case dstage_decodeCBlock:
1243  if ((size_t)(dstEnd-dstPtr) < dctxPtr->maxBlockSize) /* not enough place into dst : decode into tmpOut */
1245  else
1247  break;
1248 
1250  { int (*decoder)(const char*, char*, int, int, const char*, int);
1251  int decodedSize;
1252 
1253  if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked)
1255  else
1256  decoder = LZ4F_decompress_safe;
1257 
1258  decodedSize = decoder((const char*)selectedIn, (char*)dstPtr,
1259  (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize,
1260  (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
1261  if (decodedSize < 0) return err0r(LZ4F_ERROR_GENERIC); /* decompression failed */
1262  if (dctxPtr->frameInfo.contentChecksumFlag)
1263  XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize);
1264  if (dctxPtr->frameInfo.contentSize)
1265  dctxPtr->frameRemainingSize -= decodedSize;
1266 
1267  /* dictionary management */
1268  if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1269  LZ4F_updateDict(dctxPtr, dstPtr, decodedSize, dstStart, 0);
1270 
1271  dstPtr += decodedSize;
1272  dctxPtr->dStage = dstage_getCBlockSize;
1273  break;
1274  }
1275 
1277  /* not enough place into dst : decode into tmpOut */
1278  { int (*decoder)(const char*, char*, int, int, const char*, int);
1279  int decodedSize;
1280 
1281  if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked)
1283  else
1284  decoder = LZ4F_decompress_safe;
1285 
1286  /* ensure enough place for tmpOut */
1287  if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked) {
1288  if (dctxPtr->dict == dctxPtr->tmpOutBuffer) {
1289  if (dctxPtr->dictSize > 128 KB) {
1290  memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB);
1291  dctxPtr->dictSize = 64 KB;
1292  }
1293  dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + dctxPtr->dictSize;
1294  } else { /* dict not within tmp */
1295  size_t reservedDictSpace = dctxPtr->dictSize;
1296  if (reservedDictSpace > 64 KB) reservedDictSpace = 64 KB;
1297  dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + reservedDictSpace;
1298  }
1299  }
1300 
1301  /* Decode */
1302  decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut,
1303  (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize,
1304  (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
1305  if (decodedSize < 0)
1306  return err0r(LZ4F_ERROR_decompressionFailed); /* decompression failed */
1307  if (dctxPtr->frameInfo.contentChecksumFlag)
1308  XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize);
1309  if (dctxPtr->frameInfo.contentSize)
1310  dctxPtr->frameRemainingSize -= decodedSize;
1311  dctxPtr->tmpOutSize = decodedSize;
1312  dctxPtr->tmpOutStart = 0;
1313  dctxPtr->dStage = dstage_flushOut;
1314  break;
1315  }
1316 
1317  case dstage_flushOut: /* flush decoded data from tmpOut to dstBuffer */
1318  { size_t sizeToCopy = dctxPtr->tmpOutSize - dctxPtr->tmpOutStart;
1319  if (sizeToCopy > (size_t)(dstEnd-dstPtr)) sizeToCopy = dstEnd-dstPtr;
1320  memcpy(dstPtr, dctxPtr->tmpOut + dctxPtr->tmpOutStart, sizeToCopy);
1321 
1322  /* dictionary management */
1323  if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1324  LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 1);
1325 
1326  dctxPtr->tmpOutStart += sizeToCopy;
1327  dstPtr += sizeToCopy;
1328 
1329  /* end of flush ? */
1330  if (dctxPtr->tmpOutStart == dctxPtr->tmpOutSize) {
1331  dctxPtr->dStage = dstage_getCBlockSize;
1332  break;
1333  }
1334  nextSrcSizeHint = BHSize;
1335  doAnotherStage = 0; /* still some data to flush */
1336  break;
1337  }
1338 
1339  case dstage_getSuffix:
1340  { size_t const suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4;
1341  if (dctxPtr->frameRemainingSize)
1342  return err0r(LZ4F_ERROR_frameSize_wrong); /* incorrect frame size decoded */
1343  if (suffixSize == 0) { /* frame completed */
1344  nextSrcSizeHint = 0;
1345  dctxPtr->dStage = dstage_getHeader;
1346  doAnotherStage = 0;
1347  break;
1348  }
1349  if ((srcEnd - srcPtr) < 4) { /* not enough size for entire CRC */
1350  dctxPtr->tmpInSize = 0;
1351  dctxPtr->dStage = dstage_storeSuffix;
1352  } else {
1353  selectedIn = srcPtr;
1354  srcPtr += 4;
1355  }
1356  }
1357 
1358  if (dctxPtr->dStage == dstage_storeSuffix) /* can be skipped */
1359  case dstage_storeSuffix:
1360  {
1361  size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
1362  if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1363  memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1364  srcPtr += sizeToCopy;
1365  dctxPtr->tmpInSize += sizeToCopy;
1366  if (dctxPtr->tmpInSize < 4) { /* not enough input to read complete suffix */
1367  nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
1368  doAnotherStage=0;
1369  break;
1370  }
1371  selectedIn = dctxPtr->tmpIn;
1372  }
1373 
1374  /* case dstage_checkSuffix: */ /* no direct call, to avoid scan-build warning */
1375  { U32 const readCRC = LZ4F_readLE32(selectedIn);
1376  U32 const resultCRC = XXH32_digest(&(dctxPtr->xxh));
1377  if (readCRC != resultCRC) return err0r(LZ4F_ERROR_contentChecksum_invalid);
1378  nextSrcSizeHint = 0;
1379  dctxPtr->dStage = dstage_getHeader;
1380  doAnotherStage = 0;
1381  break;
1382  }
1383 
1384  case dstage_getSFrameSize:
1385  if ((srcEnd - srcPtr) >= 4) {
1386  selectedIn = srcPtr;
1387  srcPtr += 4;
1388  } else {
1389  /* not enough input to read cBlockSize field */
1390  dctxPtr->tmpInSize = 4;
1391  dctxPtr->tmpInTarget = 8;
1392  dctxPtr->dStage = dstage_storeSFrameSize;
1393  }
1394 
1395  if (dctxPtr->dStage == dstage_storeSFrameSize)
1397  {
1398  size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1399  if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1400  memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1401  srcPtr += sizeToCopy;
1402  dctxPtr->tmpInSize += sizeToCopy;
1403  if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) {
1404  /* not enough input to get full sBlockSize; wait for more */
1405  nextSrcSizeHint = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1406  doAnotherStage = 0;
1407  break;
1408  }
1409  selectedIn = dctxPtr->header + 4;
1410  }
1411 
1412  /* case dstage_decodeSFrameSize: */ /* no direct access */
1413  { size_t const SFrameSize = LZ4F_readLE32(selectedIn);
1414  dctxPtr->frameInfo.contentSize = SFrameSize;
1415  dctxPtr->tmpInTarget = SFrameSize;
1416  dctxPtr->dStage = dstage_skipSkippable;
1417  break;
1418  }
1419 
1420  case dstage_skipSkippable:
1421  { size_t skipSize = dctxPtr->tmpInTarget;
1422  if (skipSize > (size_t)(srcEnd-srcPtr)) skipSize = srcEnd-srcPtr;
1423  srcPtr += skipSize;
1424  dctxPtr->tmpInTarget -= skipSize;
1425  doAnotherStage = 0;
1426  nextSrcSizeHint = dctxPtr->tmpInTarget;
1427  if (nextSrcSizeHint) break;
1428  dctxPtr->dStage = dstage_getHeader;
1429  break;
1430  }
1431  }
1432  }
1433 
1434  /* preserve dictionary within tmp if necessary */
1435  if ( (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1436  &&(dctxPtr->dict != dctxPtr->tmpOutBuffer)
1437  &&(!decompressOptionsPtr->stableDst)
1438  &&((unsigned)(dctxPtr->dStage-1) < (unsigned)(dstage_getSuffix-1))
1439  )
1440  {
1441  if (dctxPtr->dStage == dstage_flushOut) {
1442  size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
1443  size_t copySize = 64 KB - dctxPtr->tmpOutSize;
1444  const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
1445  if (dctxPtr->tmpOutSize > 64 KB) copySize = 0;
1446  if (copySize > preserveSize) copySize = preserveSize;
1447 
1448  memcpy(dctxPtr->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize);
1449 
1450  dctxPtr->dict = dctxPtr->tmpOutBuffer;
1451  dctxPtr->dictSize = preserveSize + dctxPtr->tmpOutStart;
1452  } else {
1453  size_t newDictSize = dctxPtr->dictSize;
1454  const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize;
1455  if ((newDictSize) > 64 KB) newDictSize = 64 KB;
1456 
1457  memcpy(dctxPtr->tmpOutBuffer, oldDictEnd - newDictSize, newDictSize);
1458 
1459  dctxPtr->dict = dctxPtr->tmpOutBuffer;
1460  dctxPtr->dictSize = newDictSize;
1461  dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + newDictSize;
1462  }
1463  }
1464 
1465  *srcSizePtr = (srcPtr - srcStart);
1466  *dstSizePtr = (dstPtr - dstStart);
1467  return nextSrcSizeHint;
1468 }
size_t LZ4F_compressEnd(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t *compressOptionsPtr)
Definition: lz4frame.c:702
size_t maxBufferSize
Definition: lz4frame.c:174
size_t tmpOutStart
Definition: lz4frame.c:751
LZ4_stream_t * LZ4_createStream(void)
Definition: lz4.c:926
#define FREEMEM
Definition: lz4frame.c:54
unsigned char BYTE
Definition: lz4frame.c:86
LZ4F_contentChecksum_t
Definition: lz4frame.h:135
static BYTE LZ4F_headerChecksum(const void *header, size_t length)
Definition: lz4frame.c:235
LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_dctx *dctxPtr, LZ4F_frameInfo_t *frameInfoPtr, const void *srcBuffer, size_t *srcSizePtr)
Definition: lz4frame.c:933
GLint level
size_t LZ4F_compressBegin(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:416
static const size_t minFHSize
Definition: lz4frame.c:160
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
static LZ4F_blockSizeID_t LZ4F_optimalBSID(const LZ4F_blockSizeID_t requestedBSID, const size_t srcSize)
Definition: lz4frame.c:245
unsigned int U32
Definition: lz4.c:147
unsigned LZ4F_isError(LZ4F_errorCode_t code)
Definition: lz4frame.c:192
LZ4F_contentChecksum_t contentChecksumFlag
Definition: lz4frame.h:162
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
Definition: lz4frame.c:763
static size_t LZ4F_headerSize(const void *src, size_t srcSize)
Definition: lz4frame.c:811
LZ4F_errorCodes
#define _1BIT
Definition: lz4frame.c:149
#define _2BITS
Definition: lz4frame.c:150
U32 cStage
Definition: lz4frame.c:172
#define LZ4F_BLOCKSIZEID_DEFAULT
Definition: lz4frame.c:158
BYTE * tmpBuff
Definition: lz4frame.c:175
static int LZ4F_localLZ4_compress_limitedOutput_withState(void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level)
Definition: lz4frame.c:522
LZ4F_frameType_t frameType
Definition: lz4frame.h:163
void * lz4CtxPtr
Definition: lz4frame.c:180
#define _4BITS
Definition: lz4frame.c:152
#define ALLOCATOR(s)
Definition: lz4frame.c:53
dStage_t
Definition: lz4frame.c:788
void LZ4_resetStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
Definition: lz4hc.c:617
size_t LZ4F_compressUpdate(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *compressOptionsPtr)
Definition: lz4frame.c:568
GLenum GLenum dst
Definition: glext.h:1751
U32 dStage
Definition: lz4frame.c:739
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition: lz4/xxhash.c:366
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctxPtr)
Definition: lz4frame.c:773
unsigned short uint16_t
Definition: stdint.h:79
int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
Definition: lz4.c:1262
#define LZ4F_MAGICNUMBER
Definition: lz4frame.c:156
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:670
std_msgs::Header * header(M &m)
returns Header<M>::pointer(m);
size_t LZ4F_errorCode_t
Definition: lz4frame.h:94
GLenum src
Definition: glext.h:1751
unsigned long long U64
Definition: lz4.c:149
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
Definition: lz4/xxhash.c:485
unsigned char uint8_t
Definition: stdint.h:78
size_t maxBufferSize
Definition: lz4frame.c:742
LZ4_streamHC_t * LZ4_createStreamHC(void)
Definition: lz4hc.c:612
LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_compressionContext_t *LZ4F_compressionContextPtr, unsigned version)
Definition: lz4frame.c:382
BYTE header[16]
Definition: lz4frame.c:753
static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int level)
Definition: lz4frame.c:540
size_t LZ4F_decompress(LZ4F_dctx *dctxPtr, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
Definition: lz4frame.c:1059
static int LZ4F_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity, const char *dictStart, int dictSize)
Definition: lz4frame.c:971
LZ4F_errorCodes LZ4F_getErrorCode(size_t functionResult)
Definition: lz4frame.c:204
U64 totalInSize
Definition: lz4frame.c:178
#define LZ4F_MAGIC_SKIPPABLE_START
Definition: lz4frame.c:155
static U64 LZ4F_readLE64(const void *src)
Definition: lz4frame.c:114
int LZ4_decompress_safe_usingDict(const char *source, char *dest, int compressedSize, int maxOutputSize, const char *dictStart, int dictSize)
Definition: lz4.c:1393
unsigned char BYTE
Definition: lz4.c:145
LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_compressionContext)
Definition: lz4frame.c:396
struct XXH32_state_s XXH32_state_t
Definition: lz4/xxhash.h:170
#define _3BITS
Definition: lz4frame.c:151
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:499
#define LZ4F_BLOCKUNCOMPRESSED_FLAG
Definition: lz4frame.c:157
#define KB
Definition: lz4frame.c:145
unsigned int U32
Definition: lz4frame.c:88
#define MIN(a, b)
Definition: lz4frame.c:223
LZ4F_cctx * LZ4F_compressionContext_t
Definition: lz4frame.h:206
size_t LZ4F_flush(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *compressOptionsPtr)
Definition: lz4frame.c:664
static LZ4F_errorCode_t err0r(LZ4F_errorCodes code)
Definition: lz4frame.c:210
unsigned int uint32_t
Definition: stdint.h:80
LZ4F_blockSizeID_t blockSizeID
Definition: lz4frame.h:160
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
Definition: lz4.c:934
static void LZ4F_writeLE32(void *dst, U32 value32)
Definition: lz4frame.c:105
XXH32_state_t xxh
Definition: lz4frame.c:179
size_t tmpInSize
Definition: lz4frame.c:744
static int LZ4F_localSaveDict(LZ4F_cctx_t *cctxPtr)
Definition: lz4frame.c:550
static U32 LZ4F_readLE32(const void *src)
Definition: lz4frame.c:95
unsigned __int64 uint64_t
Definition: stdint.h:90
#define LZ4F_GENERATE_STRING(STRING)
Definition: lz4frame.c:188
static const size_t maxFHSize
Definition: lz4frame.c:161
const BYTE * dict
Definition: lz4frame.c:747
U32 lz4CtxLevel
Definition: lz4frame.c:181
static const size_t BHSize
Definition: lz4frame.c:162
size_t maxBlockSize
Definition: lz4frame.c:173
const char * LZ4F_getErrorName(LZ4F_errorCode_t code)
Definition: lz4frame.c:197
struct LZ4F_cctx_s LZ4F_cctx_t
#define LZ4F_VERSION
Definition: lz4frame.h:215
size_t tmpInTarget
Definition: lz4frame.c:745
unsigned short U16
Definition: lz4frame.c:87
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.h:173
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4hc.c:694
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:291
LZ4LIB_API char int compressedSize
Definition: lz4.h:456
static int LZ4F_localLZ4_compress_limitedOutput_continue(void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level)
Definition: lz4frame.c:528
size_t maxBlockSize
Definition: lz4frame.c:741
LZ4F_blockSizeID_t
Definition: lz4frame.h:113
size_t LZ4F_compressFrame(void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:313
static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void *ctx, const char *src, char *dst, int srcSize, int dstSize, int level)
Definition: lz4frame.c:534
unsigned long long U64
Definition: lz4frame.c:90
#define LZ4F_HEADER_SIZE_MAX
Definition: lz4frame.h:231
static size_t LZ4F_compressBound_internal(size_t srcSize, const LZ4F_preferences_t *preferencesPtr, size_t alreadyBuffered)
Definition: lz4frame.c:265
LZ4F_preferences_t prefs
Definition: lz4frame.c:170
static void LZ4F_updateDict(LZ4F_dctx *dctxPtr, const BYTE *dstPtr, size_t dstSize, const BYTE *dstPtr0, unsigned withinTmp)
Definition: lz4frame.c:983
unsigned autoFlush
Definition: lz4frame.h:175
static const char * LZ4F_errorStrings[]
Definition: lz4frame.c:189
size_t tmpInSize
Definition: lz4frame.c:177
#define MB
Definition: lz4frame.c:146
LZ4F_lastBlockStatus
Definition: lz4frame.c:557
XXH32_state_t xxh
Definition: lz4frame.c:752
unsigned long long contentSize
Definition: lz4frame.h:164
#define LZ4HC_CLEVEL_MIN
Definition: lz4hc.h:47
void LZ4F_resetDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:801
U32 version
Definition: lz4frame.c:171
U32 version
Definition: lz4frame.c:738
LZ4F_blockMode_t blockMode
Definition: lz4frame.h:161
size_t dictSize
Definition: lz4frame.c:748
BYTE * tmpIn
Definition: lz4frame.c:743
static size_t LZ4F_compressBlock(void *dst, const void *src, size_t srcSize, compressFunc_t compress, void *lz4ctx, int level)
Definition: lz4frame.c:507
BYTE * tmpOut
Definition: lz4frame.c:749
static size_t LZ4F_getBlockSize(unsigned blockSizeID)
Definition: lz4frame.c:225
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition: lz4/xxhash.c:437
static size_t LZ4F_decodeHeader(LZ4F_dctx *dctxPtr, const void *src, size_t srcSize)
Definition: lz4frame.c:838
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
Definition: lz4/xxhash.c:321
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition: lz4hc.c:570
#define NULL
Definition: tinycthread.c:47
int i
GLenum GLuint GLenum GLsizei length
LZ4F_blockMode_t
Definition: lz4frame.h:128
signed int int32_t
Definition: stdint.h:77
signed int S32
Definition: lz4frame.c:89
#define LZ4_STATIC_ASSERT(c)
Definition: lz4frame.c:72
unsigned LZ4F_getVersion(void)
Definition: lz4frame.c:217
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.c:737
int(* compressFunc_t)(void *ctx, const char *src, char *dst, int srcSize, int dstSize, int level)
Definition: lz4frame.c:505
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
Definition: lz4.c:1073
GLuint64EXT * result
Definition: glext.h:10921
static void LZ4F_writeLE64(void *dst, U64 value64)
Definition: lz4frame.c:128
BYTE * tmpIn
Definition: lz4frame.c:176
size_t tmpOutSize
Definition: lz4frame.c:750
U64 frameRemainingSize
Definition: lz4frame.c:740
BYTE * tmpOutBuffer
Definition: lz4frame.c:746
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:998
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)
Definition: lz4hc.c:713


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21