1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Handling of Index
6 // Copyright (C) 2008 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 ///////////////////////////////////////////////////////////////////////////////
26 /// Minimum Unpadded Size
27 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
29 /// Maximum Unpadded Size
30 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
33 /// Get the size of the Index Padding field. This is needed by Index encoder
34 /// and decoder, but applications should have no use for this.
35 extern uint32_t lzma_index_padding_size(const lzma_index *i);
38 /// Round the variable-length integer to the next multiple of four.
39 static inline lzma_vli
40 vli_ceil4(lzma_vli vli)
42 assert(vli <= LZMA_VLI_MAX);
43 return (vli + 3) & ~LZMA_VLI_C(3);
47 /// Calculate the size of the Index field excluding Index Padding
48 static inline lzma_vli
49 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
51 // Index Indicator + Number of Records + List of Records + CRC32
52 return 1 + lzma_vli_size(count) + index_list_size + 4;
56 /// Calculate the size of the Index field including Index Padding
57 static inline lzma_vli
58 index_size(lzma_vli count, lzma_vli index_list_size)
60 return vli_ceil4(index_size_unpadded(count, index_list_size));
64 /// Calculate the total size of the Stream
65 static inline lzma_vli
66 index_stream_size(lzma_vli blocks_size,
67 lzma_vli count, lzma_vli index_list_size)
69 return LZMA_STREAM_HEADER_SIZE + blocks_size
70 + index_size(count, index_list_size)
71 + LZMA_STREAM_HEADER_SIZE;