]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/filter_flags_encoder.c
Oh well, big messy commit again. Some highlights:
[icculus/xz.git] / src / liblzma / common / filter_flags_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       filter_flags_encoder.c
4 /// \brief      Decodes a Filter Flags field
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "filter_encoder.h"
21
22
23 extern LZMA_API lzma_ret
24 lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter)
25 {
26         if (filter->id >= LZMA_FILTER_RESERVED_START)
27                 return LZMA_PROG_ERROR;
28
29         return_if_error(lzma_properties_size(size, filter));
30
31         *size += lzma_vli_size(filter->id) + lzma_vli_size(*size);
32
33         return LZMA_OK;
34 }
35
36
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)
40 {
41         // Filter ID
42         if (filter->id >= LZMA_FILTER_RESERVED_START)
43                 return LZMA_PROG_ERROR;
44
45         return_if_error(lzma_vli_encode(filter->id, NULL,
46                         out, out_pos, out_size));
47
48         // Size of Properties
49         uint32_t props_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));
53
54         // Filter Properties
55         if (out_size - *out_pos < props_size)
56                 return LZMA_PROG_ERROR;
57
58         return_if_error(lzma_properties_encode(filter, out + *out_pos));
59
60         *out_pos += props_size;
61
62         return LZMA_OK;
63 }