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