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 #ifndef CONFIG_H 12*3117ece4Schristos #define CONFIG_H 13*3117ece4Schristos 14*3117ece4Schristos #include <stddef.h> 15*3117ece4Schristos 16*3117ece4Schristos #define ZSTD_STATIC_LINKING_ONLY 17*3117ece4Schristos #include <zstd.h> 18*3117ece4Schristos 19*3117ece4Schristos #include "data.h" 20*3117ece4Schristos 21*3117ece4Schristos typedef struct { 22*3117ece4Schristos ZSTD_cParameter param; 23*3117ece4Schristos int value; 24*3117ece4Schristos } param_value_t; 25*3117ece4Schristos 26*3117ece4Schristos typedef struct { 27*3117ece4Schristos size_t size; 28*3117ece4Schristos param_value_t const* data; 29*3117ece4Schristos } param_values_t; 30*3117ece4Schristos 31*3117ece4Schristos /** 32*3117ece4Schristos * The config tells the compression method what options to use. 33*3117ece4Schristos */ 34*3117ece4Schristos typedef struct { 35*3117ece4Schristos const char* name; /**< Identifies the config in the results table */ 36*3117ece4Schristos /** 37*3117ece4Schristos * Optional arguments to pass to the CLI. If not set, CLI-based methods 38*3117ece4Schristos * will skip this config. 39*3117ece4Schristos */ 40*3117ece4Schristos char const* cli_args; 41*3117ece4Schristos /** 42*3117ece4Schristos * Parameters to pass to the advanced API. If the advanced API isn't used, 43*3117ece4Schristos * the parameters will be derived from these. 44*3117ece4Schristos */ 45*3117ece4Schristos param_values_t param_values; 46*3117ece4Schristos /** 47*3117ece4Schristos * Boolean parameter that says if we should use a dictionary. If the data 48*3117ece4Schristos * doesn't have a dictionary, this config is skipped. Defaults to no. 49*3117ece4Schristos */ 50*3117ece4Schristos int use_dictionary; 51*3117ece4Schristos /** 52*3117ece4Schristos * Boolean parameter that says if we should pass the pledged source size 53*3117ece4Schristos * when the method allows it. Defaults to yes. 54*3117ece4Schristos */ 55*3117ece4Schristos int no_pledged_src_size; 56*3117ece4Schristos /** 57*3117ece4Schristos * Boolean parameter that says that this config should only be used 58*3117ece4Schristos * for methods that use the advanced compression API 59*3117ece4Schristos */ 60*3117ece4Schristos int advanced_api_only; 61*3117ece4Schristos } config_t; 62*3117ece4Schristos 63*3117ece4Schristos /** 64*3117ece4Schristos * Returns true if the config should skip this data. 65*3117ece4Schristos * For instance, if the config requires a dictionary but the data doesn't have 66*3117ece4Schristos * one. 67*3117ece4Schristos */ 68*3117ece4Schristos int config_skip_data(config_t const* config, data_t const* data); 69*3117ece4Schristos 70*3117ece4Schristos #define CONFIG_NO_LEVEL (-ZSTD_TARGETLENGTH_MAX - 1) 71*3117ece4Schristos /** 72*3117ece4Schristos * Returns the compression level specified by the config, or CONFIG_NO_LEVEL if 73*3117ece4Schristos * no level is specified. Note that 0 is a valid compression level, meaning 74*3117ece4Schristos * default. 75*3117ece4Schristos */ 76*3117ece4Schristos int config_get_level(config_t const* config); 77*3117ece4Schristos 78*3117ece4Schristos /** 79*3117ece4Schristos * Returns the compression parameters specified by the config. 80*3117ece4Schristos */ 81*3117ece4Schristos ZSTD_parameters config_get_zstd_params( 82*3117ece4Schristos config_t const* config, 83*3117ece4Schristos uint64_t srcSize, 84*3117ece4Schristos size_t dictSize); 85*3117ece4Schristos 86*3117ece4Schristos /** 87*3117ece4Schristos * The NULL-terminated list of configs. 88*3117ece4Schristos */ 89*3117ece4Schristos extern config_t const* const* configs; 90*3117ece4Schristos 91*3117ece4Schristos #endif 92