]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/index.h
Oh well, big messy commit again. Some highlights:
[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 /// Minimum Unpadded Size
27 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
28
29 /// Maximum Unpadded Size
30 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
31
32
33 /// Get the size of the Index Padding field. This is needed by Index encoder
34 /// and decoder, but applications should have no use for this.
35 extern uint32_t lzma_index_padding_size(const lzma_index *i);
36
37
38 /// Round the variable-length integer to the next multiple of four.
39 static inline lzma_vli
40 vli_ceil4(lzma_vli vli)
41 {
42         assert(vli <= LZMA_VLI_MAX);
43         return (vli + 3) & ~LZMA_VLI_C(3);
44 }
45
46
47 /// Calculate the size of the Index field excluding Index Padding
48 static inline lzma_vli
49 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
50 {
51         // Index Indicator + Number of Records + List of Records + CRC32
52         return 1 + lzma_vli_size(count) + index_list_size + 4;
53 }
54
55
56 /// Calculate the size of the Index field including Index Padding
57 static inline lzma_vli
58 index_size(lzma_vli count, lzma_vli index_list_size)
59 {
60         return vli_ceil4(index_size_unpadded(count, index_list_size));
61 }
62
63
64 /// Calculate the total size of the Stream
65 static inline lzma_vli
66 index_stream_size(lzma_vli blocks_size,
67                 lzma_vli count, lzma_vli index_list_size)
68 {
69         return LZMA_STREAM_HEADER_SIZE + blocks_size
70                         + index_size(count, index_list_size)
71                         + LZMA_STREAM_HEADER_SIZE;
72 }
73
74 #endif