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 /// Maximum encoded value of Total Size.
27 #define TOTAL_SIZE_ENCODED_MAX (LZMA_VLI_MAX / 4 - 1)
29 /// Convert the real Total Size value to a value that is stored to the Index.
30 #define total_size_encode(size) ((size) / 4 - 1)
32 /// Convert the encoded Total Size value from Index to the real Total Size.
33 #define total_size_decode(size) (((size) + 1) * 4)
36 /// Get the size of the Index Padding field. This is needed by Index encoder
37 /// and decoder, but applications should have no use for this.
38 extern uint32_t lzma_index_padding_size(const lzma_index *i);
41 static inline lzma_vli
42 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
44 // Index Indicator + Number of Records + List of Records + CRC32
45 return 1 + lzma_vli_size(count) + index_list_size + 4;
49 static inline lzma_vli
50 index_size(lzma_vli count, lzma_vli index_list_size)
52 // Round up to a mulitiple of four.
53 return (index_size_unpadded(count, index_list_size) + 3)
58 static inline lzma_vli
60 lzma_vli total_size, lzma_vli count, lzma_vli index_list_size)
62 return LZMA_STREAM_HEADER_SIZE + total_size
63 + index_size(count, index_list_size)
64 + LZMA_STREAM_HEADER_SIZE;