NexusCPP  3.5.0
bslz4.h
Go to the documentation of this file.
1 /*
2  * LZ4 - Fast LZ compression algorithm
3  * Header File
4  * Copyright (C) 2011-present, 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 #if defined (__cplusplus)
36 extern "C" {
37 #endif
38 
39 #ifndef LZ4_H_2983827168210
40 #define LZ4_H_2983827168210
41 
42 /* --- Dependency --- */
43 #include <stddef.h> /* size_t */
44 
45 
76 /*^***************************************************************
77 * Export parameters
78 *****************************************************************/
79 /*
80 * LZ4_DLL_EXPORT :
81 * Enable exporting of functions when building a Windows DLL
82 * LZ4LIB_VISIBILITY :
83 * Control library symbols visibility.
84 */
85 #ifndef LZ4LIB_VISIBILITY
86 # if defined(__GNUC__) && (__GNUC__ >= 4)
87 # define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
88 # else
89 # define LZ4LIB_VISIBILITY
90 # endif
91 #endif
92  /*
93 #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
94 # define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
95 #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
96 # define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY
97 #else
98 # define LZ4LIB_API LZ4LIB_VISIBILITY
99 #endif
100 */
101 #define LZ4LIB_API
102 
103 /*------ Version ------*/
104 #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
105 #define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
106 #define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
107 
108 #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
109 
110 #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
111 #define LZ4_QUOTE(str) #str
112 #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
113 #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
114 
115 LZ4LIB_API int LZ4_versionNumber (void);
116 LZ4LIB_API const char* LZ4_versionString (void);
119 /*-************************************
120 * Tuning parameter
121 **************************************/
129 #ifndef LZ4_MEMORY_USAGE
130 # define LZ4_MEMORY_USAGE 14
131 #endif
132 
133 
134 /*-************************************
135 * Simple Functions
136 **************************************/
151 LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
152 
167 LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
168 
169 
170 /*-************************************
171 * Advanced Functions
172 **************************************/
173 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
174 #define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
175 
186 
195 LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
196 
197 
204 LZ4LIB_API int LZ4_sizeofState(void);
205 LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
206 
207 
231 LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
232 
233 
268 LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
269 
270 
271 /*-*********************************************
272 * Streaming Compression Functions
273 ***********************************************/
274 typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
275 
277 LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
278 
302 
314 LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
315 
339 LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
340 
348 LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
349 
350 
351 /*-**********************************************
352 * Streaming Decompression Functions
353 * Bufferless synchronous API
354 ************************************************/
355 typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
356 
363 
371 LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
372 
384 LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
385 #define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
386 
412 LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
413 
414 
423 LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
424 
425 #endif /* LZ4_H_2983827168210 */
426 
427 
428 /*^*************************************
429  * !!!!!! STATIC LINKING ONLY !!!!!!
430  ***************************************/
431 
432 /*-****************************************************************************
433  * Experimental section
434  *
435  * Symbols declared in this section must be considered unstable. Their
436  * signatures or semantics may change, or they may be removed altogether in the
437  * future. They are therefore only safe to depend on when the caller is
438  * statically linked against the library.
439  *
440  * To protect against unsafe usage, not only are the declarations guarded,
441  * the definitions are hidden by default
442  * when building LZ4 as a shared/dynamic library.
443  *
444  * In order to access these declarations,
445  * define LZ4_STATIC_LINKING_ONLY in your application
446  * before including LZ4's headers.
447  *
448  * In order to make their implementations accessible dynamically, you must
449  * define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
450  ******************************************************************************/
451 
452 #ifdef LZ4_STATIC_LINKING_ONLY
453 
454 #ifndef LZ4_STATIC_3504398509
455 #define LZ4_STATIC_3504398509
456 
457 #ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
458 #define LZ4LIB_STATIC_API LZ4LIB_API
459 #else
460 #define LZ4LIB_STATIC_API
461 #endif
462 
463 
474 LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
475 
502 LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream);
503 
504 
556 #define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
557 #define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize))
559 #ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
560 # define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
561 #endif
562 
563 #define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
564 #define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN)
566 #endif /* LZ4_STATIC_3504398509 */
567 #endif /* LZ4_STATIC_LINKING_ONLY */
568 
569 
570 
571 #ifndef LZ4_H_98237428734687
572 #define LZ4_H_98237428734687
573 
574 /*-************************************************************
575  * Private Definitions
576  **************************************************************
577  * Do not use these definitions directly.
578  * They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
579  * Accessing members will expose user code to API and/or ABI break in future versions of the library.
580  **************************************************************/
581 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
582 #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
583 #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
584 
585 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
586 # include <stdint.h>
587  typedef int8_t LZ4_i8;
588  typedef uint8_t LZ4_byte;
589  typedef uint16_t LZ4_u16;
590  typedef uint32_t LZ4_u32;
591 #else
592  typedef signed char LZ4_i8;
593  typedef unsigned char LZ4_byte;
594  typedef unsigned short LZ4_u16;
595  typedef unsigned int LZ4_u32;
596 #endif
597 
601  LZ4_u32 currentOffset;
602  LZ4_u32 tableType;
603  const LZ4_byte* dictionary;
605  LZ4_u32 dictSize;
606 };
607 
608 typedef struct {
609  const LZ4_byte* externalDict;
610  size_t extDictSize;
611  const LZ4_byte* prefixEnd;
612  size_t prefixSize;
614 
615 
626 #define LZ4_STREAMSIZE 16416 /* static size, for inter-version compatibility */
627 #define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*))
629  void* table[LZ4_STREAMSIZE_VOIDP];
631 }; /* previously typedef'd to LZ4_stream_t */
632 
633 
648 LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
649 
650 
658 #define LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) /*AS-400*/ )
659 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
661  unsigned long long table[LZ4_STREAMDECODESIZE_U64];
663 } ; /* previously typedef'd to LZ4_streamDecode_t */
664 
665 
666 
667 /*-************************************
668 * Obsolete Functions
669 **************************************/
670 
682 #ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
683 # define LZ4_DEPRECATED(message) /* disable deprecation warnings */
684 #else
685 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
686 # define LZ4_DEPRECATED(message) [[deprecated(message)]]
687 # elif defined(_MSC_VER)
688 # define LZ4_DEPRECATED(message) __declspec(deprecated(message))
689 # elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
690 # define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
691 # elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
692 # define LZ4_DEPRECATED(message) __attribute__((deprecated))
693 # else
694 # pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
695 # define LZ4_DEPRECATED(message) /* disabled */
696 # endif
697 #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
698 
700 LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
701 LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* src, char* dest, int srcSize, int maxOutputSize);
702 LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
703 LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
704 LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
705 LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
706 
708 LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
709 LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
710 
711 /* Obsolete streaming functions (since v1.7.0)
712  * degraded functionality; do not use!
713  *
714  * In order to perform streaming compression, these functions depended on data
715  * that is no longer tracked in the state. They have been preserved as well as
716  * possible: using them will still produce a correct output. However, they don't
717  * actually retain any history between compression calls. The compression ratio
718  * achieved will therefore be no better than compressing each chunk
719  * independently.
720  */
721 LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
722 LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
723 LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
724 LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
725 
727 LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
728 LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
729 
756 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
757 LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
758 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
759 LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
760 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
761 LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
762 
769 LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
770 
771 
772 #endif /* LZ4_H_98237428734687 */
773 
774 
775 #if defined (__cplusplus)
776 }
777 #endif
LZ4LIB_API LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
const LZ4_byte * externalDict
Definition: bslz4.h:609
LZ4LIB_API int LZ4_versionNumber(void)
char * dest
Definition: bslz4.h:700
LZ4LIB_API int LZ4_compress_default(const char *src, char *dst, int srcSize, int dstCapacity)
unsigned char LZ4_byte
Definition: bslz4.h:593
LZ4LIB_API int LZ4_compress_fast(const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
LZ4LIB_API int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
const char * source
Definition: bslz4.h:702
const LZ4_byte * dictionary
Definition: bslz4.h:603
LZ4LIB_API int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int maxDictSize)
signed char LZ4_i8
Definition: bslz4.h:592
size_t prefixSize
Definition: bslz4.h:612
char int originalSize
Definition: bslz4.h:728
Definition: bslz4.h:660
LZ4LIB_API int LZ4_compress_fast_extState(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
LZ4_u32 currentOffset
Definition: bslz4.h:601
const LZ4_stream_t_internal * dictCtx
Definition: bslz4.h:604
LZ4_u32 tableType
Definition: bslz4.h:602
char int outputSize
Definition: bslz4.h:708
char * inputBuffer
Definition: bslz4.h:723
#define LZ4_HASH_SIZE_U32
Definition: bslz4.h:583
LZ4LIB_API int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, int dictSize)
Definition: bslz4.h:608
char int srcSize
Definition: bslz4.h:700
#define LZ4_DEPRECATED(message)
Definition: bslz4.h:695
size_t extDictSize
Definition: bslz4.h:610
char * dst
Definition: bslz4.h:727
#define LZ4LIB_API
Definition: bslz4.h:101
LZ4_stream_t_internal internal_donotuse
Definition: bslz4.h:630
Definition: bslz4.h:599
LZ4LIB_API int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int srcSize, int dstCapacity)
LZ4LIB_API int LZ4_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity)
const char char int inputSize
Definition: bslz4.h:702
LZ4LIB_API int LZ4_decompress_fast(const char *src, char *dst, int originalSize)
LZ4LIB_API int LZ4_decompress_fast_usingDict(const char *src, char *dst, int originalSize, const char *dictStart, int dictSize)
char int int maxDstSize
Definition: bslz4.h:727
LZ4LIB_API LZ4_stream_t * LZ4_createStream(void)
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32]
Definition: bslz4.h:600
LZ4LIB_API int LZ4_decompress_safe_partial(const char *src, char *dst, int srcSize, int targetOutputSize, int dstCapacity)
LZ4LIB_API int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
LZ4LIB_API int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int originalSize)
LZ4LIB_API int LZ4_freeStream(LZ4_stream_t *streamPtr)
LZ4LIB_API const char * LZ4_versionString(void)
LZ4LIB_API int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
LZ4LIB_API int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
LZ4_u32 dictSize
Definition: bslz4.h:605
LZ4_streamDecode_t_internal internal_donotuse
Definition: bslz4.h:662
unsigned short LZ4_u16
Definition: bslz4.h:594
const LZ4_byte * prefixEnd
Definition: bslz4.h:611
LZ4LIB_API LZ4_streamDecode_t * LZ4_createStreamDecode(void)
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize)
LZ4LIB_API int LZ4_compressBound(int inputSize)
#define LZ4_STREAMDECODESIZE_U64
Definition: bslz4.h:658
LZ4LIB_API int LZ4_sizeofState(void)
char int compressedSize
Definition: bslz4.h:727
LZ4LIB_API int LZ4_decompress_safe_usingDict(const char *src, char *dst, int srcSize, int dstCapcity, const char *dictStart, int dictSize)
LZ4LIB_API void LZ4_resetStream(LZ4_stream_t *streamPtr)
Definition: bslz4.h:628
unsigned int LZ4_u32
Definition: bslz4.h:595
#define LZ4_STREAMSIZE_VOIDP
Definition: bslz4.h:627
char int int maxOutputSize
Definition: bslz4.h:701
char int isize
Definition: bslz4.h:709
LZ4LIB_API void LZ4_resetStream_fast(LZ4_stream_t *streamPtr)