simple_private.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: 0BSD
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. /// \file simple_private.h
  5. /// \brief Private definitions for so called simple filters
  6. //
  7. // Author: Lasse Collin
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef LZMA_SIMPLE_PRIVATE_H
  11. #define LZMA_SIMPLE_PRIVATE_H
  12. #include "simple_coder.h"
  13. typedef struct {
  14. /// Next filter in the chain
  15. lzma_next_coder next;
  16. /// True if the next coder in the chain has returned LZMA_STREAM_END.
  17. bool end_was_reached;
  18. /// True if filter() should encode the data; false to decode.
  19. /// Currently all simple filters use the same function for encoding
  20. /// and decoding, because the difference between encoders and decoders
  21. /// is very small.
  22. bool is_encoder;
  23. /// Pointer to filter-specific function, which does
  24. /// the actual filtering.
  25. size_t (*filter)(void *simple, uint32_t now_pos,
  26. bool is_encoder, uint8_t *buffer, size_t size);
  27. /// Pointer to filter-specific data, or NULL if filter doesn't need
  28. /// any extra data.
  29. void *simple;
  30. /// The lowest 32 bits of the current position in the data. Most
  31. /// filters need this to do conversions between absolute and relative
  32. /// addresses.
  33. uint32_t now_pos;
  34. /// Size of the memory allocated for the buffer.
  35. size_t allocated;
  36. /// Flushing position in the temporary buffer. buffer[pos] is the
  37. /// next byte to be copied to out[].
  38. size_t pos;
  39. /// buffer[filtered] is the first unfiltered byte. When pos is smaller
  40. /// than filtered, there is unflushed filtered data in the buffer.
  41. size_t filtered;
  42. /// Total number of bytes (both filtered and unfiltered) currently
  43. /// in the temporary buffer.
  44. size_t size;
  45. /// Temporary buffer
  46. uint8_t buffer[];
  47. } lzma_simple_coder;
  48. extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
  49. const lzma_allocator *allocator,
  50. const lzma_filter_info *filters,
  51. size_t (*filter)(void *simple, uint32_t now_pos,
  52. bool is_encoder, uint8_t *buffer, size_t size),
  53. size_t simple_size, size_t unfiltered_max,
  54. uint32_t alignment, bool is_encoder);
  55. #endif