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