1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file filter_flags_encoder.c
4 /// \brief Decodes a Filter Flags field
6 // Copyright (C) 2007 Lasse Collin
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
20 #include "filter_encoder.h"
23 extern LZMA_API lzma_ret
24 lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter)
26 if (filter->id >= LZMA_FILTER_RESERVED_START)
27 return LZMA_PROG_ERROR;
29 return_if_error(lzma_properties_size(size, filter));
31 *size += lzma_vli_size(filter->id) + lzma_vli_size(*size);
37 extern LZMA_API lzma_ret
38 lzma_filter_flags_encode(const lzma_filter *filter,
39 uint8_t *out, size_t *out_pos, size_t out_size)
42 if (filter->id >= LZMA_FILTER_RESERVED_START)
43 return LZMA_PROG_ERROR;
45 return_if_error(lzma_vli_encode(filter->id, NULL,
46 out, out_pos, out_size));
50 return_if_error(lzma_properties_size(&props_size, filter));
51 return_if_error(lzma_vli_encode(props_size, NULL,
52 out, out_pos, out_size));
55 if (out_size - *out_pos < props_size)
56 return LZMA_PROG_ERROR;
58 return_if_error(lzma_properties_encode(filter, out + *out_pos));
60 *out_pos += props_size;