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 return_if_error(lzma_properties_size(size, filter));
28 // lzma_properties_size() validates the Filter ID as a side-effect,
29 // so we know that it is a valid VLI.
30 *size += lzma_vli_size(filter->id) + lzma_vli_size(*size);
36 extern LZMA_API lzma_ret
37 lzma_filter_flags_encode(const lzma_filter *filter,
38 uint8_t *out, size_t *out_pos, size_t out_size)
41 if (filter->id >= LZMA_FILTER_RESERVED_START)
42 return LZMA_HEADER_ERROR;
44 return_if_error(lzma_vli_encode(filter->id, NULL,
45 out, out_pos, out_size));
49 return_if_error(lzma_properties_size(&props_size, filter));
50 return_if_error(lzma_vli_encode(props_size, NULL,
51 out, out_pos, out_size));
54 if (out_size - *out_pos < props_size)
55 return LZMA_PROG_ERROR;
57 return_if_error(lzma_properties_encode(filter, out + *out_pos));
59 *out_pos += props_size;