All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lz4.h
1 /*
2  * LZ4 - Fast LZ compression algorithm
3  * Header File
4  * Copyright (C) 2011-2017, Yann Collet.
5 
6  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are
10  met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above
15  copyright notice, this list of conditions and the following disclaimer
16  in the documentation and/or other materials provided with the
17  distribution.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31  You can contact the author at :
32  - LZ4 homepage : http://www.lz4.org
33  - LZ4 source repository : https://github.com/lz4/lz4
34 */
35 
36 /* PXR - modification; remove C linkage.
37 #if defined (__cplusplus)
38 extern "C" {
39 #endif
40 */
41 
42 #ifndef LZ4_H_2983827168210
43 #define LZ4_H_2983827168210
44 
45 /* --- Dependency --- */
46 #include <stddef.h> /* size_t */
47 
48 /* PXR - modification; hoist this include out of namespace scope. */
49 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
50 #include <stdint.h>
51 #endif
52 
53 /* PXR - modification; add namespace. */
54 #include "pxr/pxr.h"
55 PXR_NAMESPACE_OPEN_SCOPE
56 namespace pxr_lz4 {
57 
81 /*^***************************************************************
82 * Export parameters
83 *****************************************************************/
84 /*
85 * LZ4_DLL_EXPORT :
86 * Enable exporting of functions when building a Windows DLL
87 * LZ4LIB_API :
88 * Control library symbols visibility.
89 */
90 #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
91 # define LZ4LIB_API __declspec(dllexport)
92 #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
93 # define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
94 #elif defined(__GNUC__) && (__GNUC__ >= 4)
95 # define LZ4LIB_API __attribute__ ((__visibility__ ("default")))
96 #else
97 # define LZ4LIB_API
98 #endif
99 
100 
101 /*------ Version ------*/
102 #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
103 #define LZ4_VERSION_MINOR 8 /* for new (non-breaking) interface capabilities */
104 #define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */
105 
106 #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
107 
108 #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
109 #define LZ4_QUOTE(str) #str
110 #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
111 #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
112 
113 LZ4LIB_API int LZ4_versionNumber (void);
114 LZ4LIB_API const char* LZ4_versionString (void);
117 /*-************************************
118 * Tuning parameter
119 **************************************/
127 #ifndef LZ4_MEMORY_USAGE
128 # define LZ4_MEMORY_USAGE 14
129 #endif
130 
131 /*-************************************
132 * Simple Functions
133 **************************************/
147 LZ4LIB_API int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize);
148 
158 LZ4LIB_API int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
159 
160 
161 /*-************************************
162 * Advanced Functions
163 **************************************/
164 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
165 #define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
166 
177 LZ4LIB_API int LZ4_compressBound(int inputSize);
178 
187 LZ4LIB_API int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration);
188 
189 
197 LZ4LIB_API int LZ4_sizeofState(void);
198 LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration);
199 
200 
212 LZ4LIB_API int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize);
213 
214 
226 LZ4LIB_API int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
227 
240 LZ4LIB_API int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize);
241 
242 
243 /*-*********************************************
244 * Streaming Compression Functions
245 ***********************************************/
246 typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
247 
252 LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
253 LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
254 
259 LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
260 
267 LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
268 
277 LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
278 
285 LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize);
286 
287 
288 /*-**********************************************
289 * Streaming Decompression Functions
290 * Bufferless synchronous API
291 ************************************************/
292 typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* incomplete type (defined later) */
293 
296 LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
297 LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
298 
304 LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
305 
322 LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize);
323 LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize);
324 
325 
331 LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize);
332 LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize);
333 
334 
335 /*^**********************************************
336  * !!!!!! STATIC LINKING ONLY !!!!!!
337  ***********************************************/
338 /*-************************************
339  * Private definitions
340  **************************************
341  * Do not use these definitions.
342  * They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
343  * Using these definitions will expose code to API and/or ABI break in future versions of the library.
344  **************************************/
345 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
346 #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
347 #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
348 
349 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
350 
351 typedef struct {
352  uint32_t hashTable[LZ4_HASH_SIZE_U32];
353  uint32_t currentOffset;
354  uint32_t initCheck;
355  const uint8_t* dictionary;
356  uint8_t* bufferStart; /* obsolete, used for slideInputBuffer */
357  uint32_t dictSize;
358 } LZ4_stream_t_internal;
359 
360 typedef struct {
361  const uint8_t* externalDict;
362  size_t extDictSize;
363  const uint8_t* prefixEnd;
364  size_t prefixSize;
365 } LZ4_streamDecode_t_internal;
366 
367 #else
368 
369 typedef struct {
370  unsigned int hashTable[LZ4_HASH_SIZE_U32];
371  unsigned int currentOffset;
372  unsigned int initCheck;
373  const unsigned char* dictionary;
374  unsigned char* bufferStart; /* obsolete, used for slideInputBuffer */
375  unsigned int dictSize;
376 } LZ4_stream_t_internal;
377 
378 typedef struct {
379  const unsigned char* externalDict;
380  size_t extDictSize;
381  const unsigned char* prefixEnd;
382  size_t prefixSize;
383 } LZ4_streamDecode_t_internal;
384 
385 #endif
386 
395 #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
396 #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
397 union LZ4_stream_u {
398  unsigned long long table[LZ4_STREAMSIZE_U64];
399  LZ4_stream_t_internal internal_donotuse;
400 } ; /* previously typedef'd to LZ4_stream_t */
401 
402 
411 #define LZ4_STREAMDECODESIZE_U64 4
412 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
413 union LZ4_streamDecode_u {
414  unsigned long long table[LZ4_STREAMDECODESIZE_U64];
415  LZ4_streamDecode_t_internal internal_donotuse;
416 } ; /* previously typedef'd to LZ4_streamDecode_t */
417 
418 
419 /*-************************************
420 * Obsolete Functions
421 **************************************/
422 
429 #ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
430 # define LZ4_DEPRECATED(message) /* disable deprecation warnings */
431 #else
432 # define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
433 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
434 # define LZ4_DEPRECATED(message) [[deprecated(message)]]
435 # elif (LZ4_GCC_VERSION >= 405) || defined(__clang__)
436 # define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
437 # elif (LZ4_GCC_VERSION >= 301)
438 # define LZ4_DEPRECATED(message) __attribute__((deprecated))
439 # elif defined(_MSC_VER)
440 # define LZ4_DEPRECATED(message) __declspec(deprecated(message))
441 # else
442 # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
443 # define LZ4_DEPRECATED(message)
444 # endif
445 #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
446 
447 /* Obsolete compression functions */
448 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress (const char* source, char* dest, int sourceSize);
449 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize);
450 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
451 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
452 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
453 LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
454 
455 /* Obsolete decompression functions */
456 LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast() instead") int LZ4_uncompress (const char* source, char* dest, int outputSize);
457 LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe() instead") int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
458 
459 /* Obsolete streaming functions; use new streaming interface whenever possible */
460 LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer);
461 LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void);
462 LZ4LIB_API LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer);
463 LZ4LIB_API LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state);
464 
465 /* Obsolete streaming decoding functions */
466 LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
467 LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
468 
469 /* PXR - modification, add namespace. */
470 } // pxr_lz4
471 PXR_NAMESPACE_CLOSE_SCOPE
472 
473 #endif /* LZ4_H_2983827168210 */
474 
475 
476 /* PXR - modification; remove C linkage.
477 #if defined (__cplusplus)
478 }
479 #endif
480 */