1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Handling of Index
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
19 /// Minimum Unpadded Size
20 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
22 /// Maximum Unpadded Size
23 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
26 /// Get the size of the Index Padding field. This is needed by Index encoder
27 /// and decoder, but applications should have no use for this.
28 extern uint32_t lzma_index_padding_size(const lzma_index *i);
31 /// Round the variable-length integer to the next multiple of four.
32 static inline lzma_vli
33 vli_ceil4(lzma_vli vli)
35 assert(vli <= LZMA_VLI_MAX);
36 return (vli + 3) & ~LZMA_VLI_C(3);
40 /// Calculate the size of the Index field excluding Index Padding
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 /// Calculate the size of the Index field including Index Padding
50 static inline lzma_vli
51 index_size(lzma_vli count, lzma_vli index_list_size)
53 return vli_ceil4(index_size_unpadded(count, index_list_size));
57 /// Calculate the total size of the Stream
58 static inline lzma_vli
59 index_stream_size(lzma_vli blocks_size,
60 lzma_vli count, lzma_vli index_list_size)
62 return LZMA_STREAM_HEADER_SIZE + blocks_size
63 + index_size(count, index_list_size)
64 + LZMA_STREAM_HEADER_SIZE;