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