method.h 1.7 KB

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