1 /*
2  * Copyright (c) Facebook, Inc.
3  * 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 
19 #include "data.h"
20 
21 typedef struct {
22     ZSTD_cParameter param;
23     int value;
24 } param_value_t;
25 
26 typedef 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  */
34 typedef 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;
46     /**
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;
56     /**
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;
61 } config_t;
62 
63 /**
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  */
68 int config_skip_data(config_t const* config, data_t const* data);
69 
70 #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  */
76 int config_get_level(config_t const* config);
77 
78 /**
79  * Returns the compression parameters specified by the config.
80  */
81 ZSTD_parameters config_get_zstd_params(
82     config_t const* config,
83     uint64_t srcSize,
84     size_t dictSize);
85 
86 /**
87  * The NULL-terminated list of configs.
88  */
89 extern config_t const* const* configs;
90 
91 #endif
92