]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/index.h
Update the code to mostly match the new simpler file format
[icculus/xz.git] / src / liblzma / common / index.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       index.h
4 /// \brief      Handling of Index
5 //
6 //  Copyright (C) 2008 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #ifndef LZMA_INDEX_H
21 #define LZMA_INDEX_H
22
23 #include "common.h"
24
25
26 /// Maximum encoded value of Total Size.
27 #define TOTAL_SIZE_ENCODED_MAX (LZMA_VLI_VALUE_MAX / 4 - 1)
28
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)
31
32 /// Convert the encoded Total Size value from Index to the real Total Size.
33 #define total_size_decode(size) (((size) + 1) * 4)
34
35
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);
39
40
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 static inline lzma_vli
50 index_size(lzma_vli count, lzma_vli index_list_size)
51 {
52         // Round up to a mulitiple of four.
53         return (index_size_unpadded(count, index_list_size) + 3)
54                         & ~LZMA_VLI_C(3);
55 }
56
57
58 static inline lzma_vli
59 index_stream_size(
60                 lzma_vli total_size, lzma_vli count, lzma_vli index_list_size)
61 {
62         return LZMA_STREAM_HEADER_SIZE + total_size
63                         + index_size(count, index_list_size)
64                         + LZMA_STREAM_HEADER_SIZE;
65 }
66
67 #endif