xref: /aosp_15_r20/external/zstd/lib/decompress/zstd_decompress_block.h (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  * You may select, at your option, one of the above-listed licenses.
9*01826a49SYabin Cui  */
10*01826a49SYabin Cui 
11*01826a49SYabin Cui 
12*01826a49SYabin Cui #ifndef ZSTD_DEC_BLOCK_H
13*01826a49SYabin Cui #define ZSTD_DEC_BLOCK_H
14*01826a49SYabin Cui 
15*01826a49SYabin Cui /*-*******************************************************
16*01826a49SYabin Cui  *  Dependencies
17*01826a49SYabin Cui  *********************************************************/
18*01826a49SYabin Cui #include "../common/zstd_deps.h"   /* size_t */
19*01826a49SYabin Cui #include "../zstd.h"    /* DCtx, and some public functions */
20*01826a49SYabin Cui #include "../common/zstd_internal.h"  /* blockProperties_t, and some public functions */
21*01826a49SYabin Cui #include "zstd_decompress_internal.h"  /* ZSTD_seqSymbol */
22*01826a49SYabin Cui 
23*01826a49SYabin Cui 
24*01826a49SYabin Cui /* ===   Prototypes   === */
25*01826a49SYabin Cui 
26*01826a49SYabin Cui /* note: prototypes already published within `zstd.h` :
27*01826a49SYabin Cui  * ZSTD_decompressBlock()
28*01826a49SYabin Cui  */
29*01826a49SYabin Cui 
30*01826a49SYabin Cui /* note: prototypes already published within `zstd_internal.h` :
31*01826a49SYabin Cui  * ZSTD_getcBlockSize()
32*01826a49SYabin Cui  * ZSTD_decodeSeqHeaders()
33*01826a49SYabin Cui  */
34*01826a49SYabin Cui 
35*01826a49SYabin Cui 
36*01826a49SYabin Cui  /* Streaming state is used to inform allocation of the literal buffer */
37*01826a49SYabin Cui typedef enum {
38*01826a49SYabin Cui     not_streaming = 0,
39*01826a49SYabin Cui     is_streaming = 1
40*01826a49SYabin Cui } streaming_operation;
41*01826a49SYabin Cui 
42*01826a49SYabin Cui /* ZSTD_decompressBlock_internal() :
43*01826a49SYabin Cui  * decompress block, starting at `src`,
44*01826a49SYabin Cui  * into destination buffer `dst`.
45*01826a49SYabin Cui  * @return : decompressed block size,
46*01826a49SYabin Cui  *           or an error code (which can be tested using ZSTD_isError())
47*01826a49SYabin Cui  */
48*01826a49SYabin Cui size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
49*01826a49SYabin Cui                                void* dst, size_t dstCapacity,
50*01826a49SYabin Cui                          const void* src, size_t srcSize, const streaming_operation streaming);
51*01826a49SYabin Cui 
52*01826a49SYabin Cui /* ZSTD_buildFSETable() :
53*01826a49SYabin Cui  * generate FSE decoding table for one symbol (ll, ml or off)
54*01826a49SYabin Cui  * this function must be called with valid parameters only
55*01826a49SYabin Cui  * (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
56*01826a49SYabin Cui  * in which case it cannot fail.
57*01826a49SYabin Cui  * The workspace must be 4-byte aligned and at least ZSTD_BUILD_FSE_TABLE_WKSP_SIZE bytes, which is
58*01826a49SYabin Cui  * defined in zstd_decompress_internal.h.
59*01826a49SYabin Cui  * Internal use only.
60*01826a49SYabin Cui  */
61*01826a49SYabin Cui void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
62*01826a49SYabin Cui              const short* normalizedCounter, unsigned maxSymbolValue,
63*01826a49SYabin Cui              const U32* baseValue, const U8* nbAdditionalBits,
64*01826a49SYabin Cui                    unsigned tableLog, void* wksp, size_t wkspSize,
65*01826a49SYabin Cui                    int bmi2);
66*01826a49SYabin Cui 
67*01826a49SYabin Cui /* Internal definition of ZSTD_decompressBlock() to avoid deprecation warnings. */
68*01826a49SYabin Cui size_t ZSTD_decompressBlock_deprecated(ZSTD_DCtx* dctx,
69*01826a49SYabin Cui                             void* dst, size_t dstCapacity,
70*01826a49SYabin Cui                       const void* src, size_t srcSize);
71*01826a49SYabin Cui 
72*01826a49SYabin Cui 
73*01826a49SYabin Cui #endif /* ZSTD_DEC_BLOCK_H */
74