blob: a4b542a90afe12b283ff8c7bd6578add0ffc4388 [file] [log] [blame]
Nick Terrell4aaa36f2018-11-20 12:37:43 -08001/*
Elliott Hughes44aba642023-09-12 20:18:59 +00002 * Copyright (c) Meta Platforms, Inc. and affiliates.
Nick Terrell4aaa36f2018-11-20 12:37:43 -08003 * All rights reserved.
4 *
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
9 */
10
11#ifndef CONFIG_H
12#define CONFIG_H
13
14#include <stddef.h>
15
16#define ZSTD_STATIC_LINKING_ONLY
17#include <zstd.h>
18
Nick Terrelle8598622018-11-30 17:16:19 -080019#include "data.h"
20
Nick Terrell4aaa36f2018-11-20 12:37:43 -080021typedef struct {
22 ZSTD_cParameter param;
Nick Terrellfcfea052018-12-03 20:06:26 -080023 int value;
Nick Terrell4aaa36f2018-11-20 12:37:43 -080024} param_value_t;
25
26typedef struct {
27 size_t size;
28 param_value_t const* data;
29} param_values_t;
30
31/**
32 * The config tells the compression method what options to use.
33 */
34typedef struct {
35 const char* name; /**< Identifies the config in the results table */
36 /**
37 * Optional arguments to pass to the CLI. If not set, CLI-based methods
38 * will skip this config.
39 */
40 char const* cli_args;
41 /**
42 * Parameters to pass to the advanced API. If the advanced API isn't used,
43 * the parameters will be derived from these.
44 */
45 param_values_t param_values;
Nick Terrelle8598622018-11-30 17:16:19 -080046 /**
47 * Boolean parameter that says if we should use a dictionary. If the data
48 * doesn't have a dictionary, this config is skipped. Defaults to no.
49 */
50 int use_dictionary;
51 /**
52 * Boolean parameter that says if we should pass the pledged source size
53 * when the method allows it. Defaults to yes.
54 */
55 int no_pledged_src_size;
Sen Huangf27e3262021-03-25 10:38:56 -070056 /**
57 * Boolean parameter that says that this config should only be used
58 * for methods that use the advanced compression API
59 */
60 int advanced_api_only;
Nick Terrell4aaa36f2018-11-20 12:37:43 -080061} config_t;
62
Nick Terrelle8598622018-11-30 17:16:19 -080063/**
64 * Returns true if the config should skip this data.
65 * For instance, if the config requires a dictionary but the data doesn't have
66 * one.
67 */
68int config_skip_data(config_t const* config, data_t const* data);
69
Nick Terrell4aaa36f2018-11-20 12:37:43 -080070#define CONFIG_NO_LEVEL (-ZSTD_TARGETLENGTH_MAX - 1)
71/**
72 * Returns the compression level specified by the config, or CONFIG_NO_LEVEL if
73 * no level is specified. Note that 0 is a valid compression level, meaning
74 * default.
75 */
76int config_get_level(config_t const* config);
77
78/**
Nick Terrellfcfea052018-12-03 20:06:26 -080079 * Returns the compression parameters specified by the config.
80 */
81ZSTD_parameters config_get_zstd_params(
82 config_t const* config,
83 uint64_t srcSize,
84 size_t dictSize);
85
86/**
Nick Terrell4aaa36f2018-11-20 12:37:43 -080087 * The NULL-terminated list of configs.
88 */
89extern config_t const* const* configs;
90
91#endif