]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/index.h
Put the interesting parts of XZ Utils into the public domain.
[icculus/xz.git] / src / liblzma / common / index.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       index.h
4 /// \brief      Handling of Index
5 //
6 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef LZMA_INDEX_H
14 #define LZMA_INDEX_H
15
16 #include "common.h"
17
18
19 /// Minimum Unpadded Size
20 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
21
22 /// Maximum Unpadded Size
23 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
24
25
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);
29
30
31 /// Round the variable-length integer to the next multiple of four.
32 static inline lzma_vli
33 vli_ceil4(lzma_vli vli)
34 {
35         assert(vli <= LZMA_VLI_MAX);
36         return (vli + 3) & ~LZMA_VLI_C(3);
37 }
38
39
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)
43 {
44         // Index Indicator + Number of Records + List of Records + CRC32
45         return 1 + lzma_vli_size(count) + index_list_size + 4;
46 }
47
48
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)
52 {
53         return vli_ceil4(index_size_unpadded(count, index_list_size));
54 }
55
56
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)
61 {
62         return LZMA_STREAM_HEADER_SIZE + blocks_size
63                         + index_size(count, index_list_size)
64                         + LZMA_STREAM_HEADER_SIZE;
65 }
66
67 #endif