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 /// Set for how many Records to allocate memory the next time
32 /// lzma_index_append() needs to allocate space for a new Record.
33 /// This is used only by the Index decoder.
34 extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
37 /// Round the variable-length integer to the next multiple of four.
38 static inline lzma_vli
39 vli_ceil4(lzma_vli vli)
41 assert(vli <= LZMA_VLI_MAX);
42 return (vli + 3) & ~LZMA_VLI_C(3);
46 /// Calculate the size of the Index field excluding Index Padding
47 static inline lzma_vli
48 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
50 // Index Indicator + Number of Records + List of Records + CRC32
51 return 1 + lzma_vli_size(count) + index_list_size + 4;
55 /// Calculate the size of the Index field including Index Padding
56 static inline lzma_vli
57 index_size(lzma_vli count, lzma_vli index_list_size)
59 return vli_ceil4(index_size_unpadded(count, index_list_size));
63 /// Calculate the total size of the Stream
64 static inline lzma_vli
65 index_stream_size(lzma_vli blocks_size,
66 lzma_vli count, lzma_vli index_list_size)
68 return LZMA_STREAM_HEADER_SIZE + blocks_size
69 + index_size(count, index_list_size)
70 + LZMA_STREAM_HEADER_SIZE;