• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016-2020, 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 } config_t;
57 
58 /**
59  * Returns true if the config should skip this data.
60  * For instance, if the config requires a dictionary but the data doesn't have
61  * one.
62  */
63 int config_skip_data(config_t const* config, data_t const* data);
64 
65 #define CONFIG_NO_LEVEL (-ZSTD_TARGETLENGTH_MAX - 1)
66 /**
67  * Returns the compression level specified by the config, or CONFIG_NO_LEVEL if
68  * no level is specified. Note that 0 is a valid compression level, meaning
69  * default.
70  */
71 int config_get_level(config_t const* config);
72 
73 /**
74  * Returns the compression parameters specified by the config.
75  */
76 ZSTD_parameters config_get_zstd_params(
77     config_t const* config,
78     uint64_t srcSize,
79     size_t dictSize);
80 
81 /**
82  * The NULL-terminated list of configs.
83  */
84 extern config_t const* const* configs;
85 
86 #endif
87