UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
lz4.h
Go to the documentation of this file.
1/*
2 * LZ4 - Fast LZ compression algorithm
3 * Header File
4 * Copyright (C) 2011-2020, 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
37// HEADER_UNIT_SKIP - Not compatible
38
39#include "HAL/PlatformMemory.h"
40#if defined (__cplusplus)
41extern "C" {
42#endif
43
44#ifndef LZ4_H_2983827168210
45#define LZ4_H_2983827168210
46
47/* --- Dependency --- */
48
49
80/*^***************************************************************
81* Export parameters
82*****************************************************************/
83
84#define LZ4LIB_API CORE_API
85
98#if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
99# define LZ4_HEAPMODE 0
100# define LZ4HC_HEAPMODE 0
101# define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
102# if !defined(LZ4_memcpy)
103# error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
104# endif
105# if !defined(LZ4_memset)
106# error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
107# endif
108# if !defined(LZ4_memmove)
109# error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
110# endif
111#elif ! defined(LZ4_FREESTANDING)
112# define LZ4_FREESTANDING 0
113#endif
114
115
116/*------ Version ------*/
117#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
118#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
119#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
120
121#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
122
123#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
124#define LZ4_QUOTE(str) #str
125#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
126#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
127
128LZ4LIB_API int LZ4_versionNumber (void);
129LZ4LIB_API const char* LZ4_versionString (void);
132/*-************************************
133* Tuning parameter
134**************************************/
135#define LZ4_MEMORY_USAGE_MIN 10
136#define LZ4_MEMORY_USAGE_DEFAULT 14
137#define LZ4_MEMORY_USAGE_MAX 20
138
146#ifndef LZ4_MEMORY_USAGE
147# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
148#endif
149
150#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
151# error "LZ4_MEMORY_USAGE is too small !"
152#endif
153
154#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
155# error "LZ4_MEMORY_USAGE is too large !"
156#endif
157
158/*-************************************
159* Simple Functions
160**************************************/
175LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
176
191LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
192
193
194/*-************************************
195* Advanced Functions
196**************************************/
197#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
198#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
199
210
219LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
220
221
229LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
230
231
255LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
256
257
292LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
293
294
295/*-*********************************************
296* Streaming Compression Functions
297***********************************************/
298typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
299
313#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
314#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
317#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
318#endif
319
343
355LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
356
381
390
391
392/*-**********************************************
393* Streaming Decompression Functions
394* Bufferless synchronous API
395************************************************/
396typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
397
402#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
403#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
406#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
407#endif
408
416LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
417
430#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
431
457LZ4LIB_API int
459 const char* src, char* dst,
460 int srcSize, int dstCapacity);
461
462
471LZ4LIB_API int
472LZ4_decompress_safe_usingDict(const char* src, char* dst,
473 int srcSize, int dstCapacity,
474 const char* dictStart, int dictSize);
475
476LZ4LIB_API int
477LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
478 int compressedSize,
480 const char* dictStart, int dictSize);
481
482#endif /* LZ4_H_2983827168210 */
483
484
485/*^*************************************
486 * !!!!!! STATIC LINKING ONLY !!!!!!
487 ***************************************/
488
489/*-****************************************************************************
490 * Experimental section
491 *
492 * Symbols declared in this section must be considered unstable. Their
493 * signatures or semantics may change, or they may be removed altogether in the
494 * future. They are therefore only safe to depend on when the caller is
495 * statically linked against the library.
496 *
497 * To protect against unsafe usage, not only are the declarations guarded,
498 * the definitions are hidden by default
499 * when building LZ4 as a shared/dynamic library.
500 *
501 * In order to access these declarations,
502 * define LZ4_STATIC_LINKING_ONLY in your application
503 * before including LZ4's headers.
504 *
505 * In order to make their implementations accessible dynamically, you must
506 * define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
507 ******************************************************************************/
508
509#ifdef LZ4_STATIC_LINKING_ONLY
510
511#ifndef LZ4_STATIC_3504398509
512#define LZ4_STATIC_3504398509
513
514#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
515#define LZ4LIB_STATIC_API LZ4LIB_API
516#else
517#define LZ4LIB_STATIC_API
518#endif
519
520
531LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
532
562
563
615#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
616#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize))
618#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
619# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
620#endif
621
622#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
623#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN)
625#endif /* LZ4_STATIC_3504398509 */
626#endif /* LZ4_STATIC_LINKING_ONLY */
627
628
629
630#ifndef LZ4_H_98237428734687
631#define LZ4_H_98237428734687
632
633/*-************************************************************
634 * Private Definitions
635 **************************************************************
636 * Do not use these definitions directly.
637 * They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
638 * Accessing members will expose user code to API and/or ABI break in future versions of the library.
639 **************************************************************/
640#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
641#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
642#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
643
644#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
645 typedef int8 LZ4_i8;
646 typedef uint8 LZ4_byte;
647 typedef uint16 LZ4_u16;
648 typedef uint32 LZ4_u32;
649#else
650 typedef signed char LZ4_i8;
651 typedef unsigned char LZ4_byte;
652 typedef unsigned short LZ4_u16;
653 typedef unsigned int LZ4_u32;
654#endif
655
672
673#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
677}; /* previously typedef'd to LZ4_stream_t */
678
679
694LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
695
696
708
709#define LZ4_STREAMDECODE_MINSIZE 32
713} ; /* previously typedef'd to LZ4_streamDecode_t */
714
722
723
724#endif /* LZ4_H_98237428734687 */
725
726
727#if defined (__cplusplus)
728}
729#endif
#define LZ4LIB_API
Definition lz4.h:84
LZ4LIB_API LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
Definition lz4.cpp:1505
#define LZ4_STREAMDECODE_MINSIZE
Definition lz4.h:709
LZ4LIB_API int LZ4_compress_fast(const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition lz4.cpp:1414
LZ4LIB_API int LZ4_decompress_safe_partial_usingDict(const char *src, char *dst, int compressedSize, int targetOutputSize, int maxOutputSize, const char *dictStart, int dictSize)
Definition lz4.cpp:2625
LZ4LIB_API const char * LZ4_versionString(void)
Definition lz4.cpp:726
LZ4LIB_API int LZ4_versionNumber(void)
Definition lz4.cpp:725
LZ4LIB_API int LZ4_sizeofState(void)
Definition lz4.cpp:728
#define LZ4_STREAM_MINSIZE
Definition lz4.h:673
LZ4LIB_API int LZ4_compressBound(int inputSize)
Definition lz4.cpp:727
LZ4LIB_API int LZ4_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity)
Definition lz4.cpp:2343
unsigned short LZ4_u16
Definition lz4.h:652
LZ4LIB_API int LZ4_compress_fast_extState(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition lz4.cpp:1344
LZ4LIB_API int LZ4_decompress_safe_partial(const char *src, char *dst, int srcSize, int targetOutputSize, int dstCapacity)
Definition lz4.cpp:2351
signed char LZ4_i8
Definition lz4.h:650
LZ4LIB_API void LZ4_resetStream(LZ4_stream_t *streamPtr)
Definition lz4.cpp:1517
unsigned char LZ4_byte
Definition lz4.h:651
LZ4LIB_API int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition lz4.cpp:1459
LZ4LIB_API int LZ4_compress_default(const char *src, char *dst, int srcSize, int dstCapacity)
Definition lz4.cpp:1433
unsigned int LZ4_u32
Definition lz4.h:653
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
LZ4LIB_API int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition lz4.cpp:1630
LZ4LIB_API int LZ4_decompress_safe_usingDict(const char *src, char *dst, int srcSize, int dstCapcity, const char *dictStart, int dictSize)
Definition lz4.cpp:2610
char int srcSize
Definition lz4.h:709
char int compressedSize
Definition lz4.h:735
LZ4LIB_API void LZ4_resetStream_fast(LZ4_stream_t *streamPtr)
Definition lz4.cpp:1523
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize)
Definition lz4.cpp:2506
LZ4LIB_API int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
Definition lz4.cpp:2466
LZ4LIB_API int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int maxDictSize)
Definition lz4.cpp:1737
LZ4LIB_API LZ4_stream_t * LZ4_createStream(void)
Definition lz4.cpp:1484
#define LZ4_HASH_SIZE_U32
Definition lz4.h:579
LZ4LIB_API int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
Definition lz4.cpp:2480
LZ4LIB_API int LZ4_freeStream(LZ4_stream_t *streamPtr)
Definition lz4.cpp:1528
const char char int inputSize
Definition lz4.h:711
char * dst
Definition lz4.h:735
LZ4LIB_API LZ4_streamDecode_t * LZ4_createStreamDecode(void)
Definition lz4.cpp:2460
char int int maxOutputSize
Definition lz4.h:710
LZ4LIB_API int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, int dictSize)
Definition lz4.cpp:1539
LZ4LIB_API int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int srcSize, int dstCapacity)
Definition lz4.cpp:2522
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
int LZ4_compress_fast_extState_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition lz4.cpp:1376
void LZ4_attach_dictionary(LZ4_stream_t *workingStream, const LZ4_stream_t *dictionaryStream)
Definition lz4.cpp:1581
Definition lz4.h:702
SIZE_T prefixSize
Definition lz4.h:706
const LZ4_byte * prefixEnd
Definition lz4.h:704
const LZ4_byte * externalDict
Definition lz4.h:703
SIZE_T extDictSize
Definition lz4.h:705
Definition lz4.h:663
LZ4_u32 tableType
Definition lz4.h:668
LZ4_u32 currentOffset
Definition lz4.h:667
const LZ4_byte * dictionary
Definition lz4.h:665
const LZ4_stream_t_internal * dictCtx
Definition lz4.h:666
LZ4_u32 dictSize
Definition lz4.h:669
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32]
Definition lz4.h:664
Definition lz4.h:710
LZ4_streamDecode_t_internal internal_donotuse
Definition lz4.h:712
char minStateSize[LZ4_STREAMDECODE_MINSIZE]
Definition lz4.h:711
Definition lz4.h:674
char minStateSize[LZ4_STREAM_MINSIZE]
Definition lz4.h:675
LZ4_stream_t_internal internal_donotuse
Definition lz4.h:676