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 METHOD_H 12*01826a49SYabin Cui #define METHOD_H 13*01826a49SYabin Cui 14*01826a49SYabin Cui #include <stddef.h> 15*01826a49SYabin Cui 16*01826a49SYabin Cui #include "data.h" 17*01826a49SYabin Cui #include "config.h" 18*01826a49SYabin Cui #include "result.h" 19*01826a49SYabin Cui 20*01826a49SYabin Cui /** 21*01826a49SYabin Cui * The base class for state that methods keep. 22*01826a49SYabin Cui * All derived method state classes must have a member of this type. 23*01826a49SYabin Cui */ 24*01826a49SYabin Cui typedef struct { 25*01826a49SYabin Cui data_t const* data; 26*01826a49SYabin Cui } method_state_t; 27*01826a49SYabin Cui 28*01826a49SYabin Cui /** 29*01826a49SYabin Cui * A method that compresses the data using config. 30*01826a49SYabin Cui */ 31*01826a49SYabin Cui typedef struct { 32*01826a49SYabin Cui char const* name; /**< The identifier for this method in the results. */ 33*01826a49SYabin Cui /** 34*01826a49SYabin Cui * Creates a state that must contain a member variable of method_state_t, 35*01826a49SYabin Cui * and returns a pointer to that member variable. 36*01826a49SYabin Cui * 37*01826a49SYabin Cui * This method can be used to do expensive work that only depends on the 38*01826a49SYabin Cui * data, like loading the data file into a buffer. 39*01826a49SYabin Cui */ 40*01826a49SYabin Cui method_state_t* (*create)(data_t const* data); 41*01826a49SYabin Cui /** 42*01826a49SYabin Cui * Compresses the data in the state using the given config. 43*01826a49SYabin Cui * 44*01826a49SYabin Cui * @param state A pointer to the state returned by create(). 45*01826a49SYabin Cui * 46*01826a49SYabin Cui * @returns The total compressed size on success, or an error code. 47*01826a49SYabin Cui */ 48*01826a49SYabin Cui result_t (*compress)(method_state_t* state, config_t const* config); 49*01826a49SYabin Cui /** 50*01826a49SYabin Cui * Frees the state. 51*01826a49SYabin Cui */ 52*01826a49SYabin Cui void (*destroy)(method_state_t* state); 53*01826a49SYabin Cui } method_t; 54*01826a49SYabin Cui 55*01826a49SYabin Cui /** 56*01826a49SYabin Cui * Set the zstd cli path. Must be called before any methods are used. 57*01826a49SYabin Cui */ 58*01826a49SYabin Cui void method_set_zstdcli(char const* zstdcli); 59*01826a49SYabin Cui 60*01826a49SYabin Cui /** 61*01826a49SYabin Cui * A NULL-terminated list of methods. 62*01826a49SYabin Cui */ 63*01826a49SYabin Cui extern method_t const* const* methods; 64*01826a49SYabin Cui 65*01826a49SYabin Cui #endif 66