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