simple_private.h revision 312518
1112102Ssam///////////////////////////////////////////////////////////////////////////////
2112102Ssam//
3112102Ssam/// \file       simple_private.h
4112102Ssam/// \brief      Private definitions for so called simple filters
5112102Ssam//
6112102Ssam//  Author:     Lasse Collin
7112102Ssam//
8112102Ssam//  This file has been put into the public domain.
9112102Ssam//  You can do whatever you want with this file.
10112102Ssam//
11112102Ssam///////////////////////////////////////////////////////////////////////////////
12112102Ssam
13112102Ssam#ifndef LZMA_SIMPLE_PRIVATE_H
14112102Ssam#define LZMA_SIMPLE_PRIVATE_H
15112102Ssam
16112102Ssam#include "simple_coder.h"
17112102Ssam
18112102Ssam
19112102Ssamtypedef struct {
20112102Ssam	/// Next filter in the chain
21112102Ssam	lzma_next_coder next;
22112102Ssam
23112102Ssam	/// True if the next coder in the chain has returned LZMA_STREAM_END.
24112102Ssam	bool end_was_reached;
25112102Ssam
26112102Ssam	/// True if filter() should encode the data; false to decode.
27112102Ssam	/// Currently all simple filters use the same function for encoding
28112102Ssam	/// and decoding, because the difference between encoders and decoders
29112102Ssam	/// is very small.
30112102Ssam	bool is_encoder;
31112102Ssam
32112102Ssam	/// Pointer to filter-specific function, which does
33112102Ssam	/// the actual filtering.
34112102Ssam	size_t (*filter)(void *simple, uint32_t now_pos,
35115392Sru			bool is_encoder, uint8_t *buffer, size_t size);
36112102Ssam
37112102Ssam	/// Pointer to filter-specific data, or NULL if filter doesn't need
38112102Ssam	/// any extra data.
39115392Sru	void *simple;
40115392Sru
41115392Sru	/// The lowest 32 bits of the current position in the data. Most
42112102Ssam	/// filters need this to do conversions between absolute and relative
43112102Ssam	/// addresses.
44112102Ssam	uint32_t now_pos;
45112102Ssam
46112102Ssam	/// Size of the memory allocated for the buffer.
47112102Ssam	size_t allocated;
48115392Sru
49115392Sru	/// Flushing position in the temporary buffer. buffer[pos] is the
50112102Ssam	/// next byte to be copied to out[].
51112102Ssam	size_t pos;
52112102Ssam
53112102Ssam	/// buffer[filtered] is the first unfiltered byte. When pos is smaller
54112102Ssam	/// than filtered, there is unflushed filtered data in the buffer.
55112102Ssam	size_t filtered;
56123901Sbrueffer
57112102Ssam	/// Total number of bytes (both filtered and unfiltered) currently
58112102Ssam	/// in the temporary buffer.
59112102Ssam	size_t size;
60115392Sru
61115392Sru	/// Temporary buffer
62112102Ssam	uint8_t buffer[];
63112102Ssam} lzma_simple_coder;
64112102Ssam
65112102Ssam
66112102Ssamextern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
67112102Ssam		const lzma_allocator *allocator,
68112102Ssam		const lzma_filter_info *filters,
69112102Ssam		size_t (*filter)(void *simple, uint32_t now_pos,
70112102Ssam			bool is_encoder, uint8_t *buffer, size_t size),
71123901Sbrueffer		size_t simple_size, size_t unfiltered_max,
72115392Sru		uint32_t alignment, bool is_encoder);
73
74#endif
75