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