1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file subblock_decoder_helper.c
4 /// \brief Helper filter for the Subblock decoder
6 /// This filter is used to indicate End of Input for subfilters needing it.
8 // Author: Lasse Collin
10 // This file has been put into the public domain.
11 // You can do whatever you want with this file.
13 ///////////////////////////////////////////////////////////////////////////////
15 #include "subblock_decoder_helper.h"
19 const lzma_options_subblock_helper *options;
24 helper_decode(lzma_coder *coder,
25 lzma_allocator *allocator lzma_attribute((unused)),
26 const uint8_t *restrict in, size_t *restrict in_pos,
27 size_t in_size, uint8_t *restrict out,
28 size_t *restrict out_pos, size_t out_size,
29 lzma_action action lzma_attribute((unused)))
31 // If end_was_reached is true, we cannot have any input.
32 assert(!coder->options->end_was_reached || *in_pos == in_size);
34 // We can safely copy as much as possible, because we are never
35 // given more data than a single Subblock Data field.
36 lzma_bufcpy(in, in_pos, in_size, out, out_pos, out_size);
38 // Return LZMA_STREAM_END when instructed so by the Subblock decoder.
39 return coder->options->end_was_reached ? LZMA_STREAM_END : LZMA_OK;
44 helper_end(lzma_coder *coder, lzma_allocator *allocator)
46 lzma_free(coder, allocator);
52 lzma_subblock_decoder_helper_init(lzma_next_coder *next,
53 lzma_allocator *allocator, const lzma_filter_info *filters)
55 // This is always the last filter in the chain.
56 assert(filters[1].init == NULL);
58 if (next->coder == NULL) {
59 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
60 if (next->coder == NULL)
61 return LZMA_MEM_ERROR;
63 next->code = &helper_decode;
64 next->end = &helper_end;
67 next->coder->options = filters[0].options;