1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: expandtab:ts=8:sw=4:softtabstop=4:
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       index.h
6 /// \brief      Handling of Index
7 //
8 //  Author:     Lasse Collin
9 //
10 //  This file has been put into the public domain.
11 //  You can do whatever you want with this file.
12 //
13 ///////////////////////////////////////////////////////////////////////////////
14 
15 #ifndef LZMA_INDEX_H
16 #define LZMA_INDEX_H
17 
18 #include "common.h"
19 
20 
21 /// Minimum Unpadded Size
22 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
23 
24 /// Maximum Unpadded Size
25 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
26 
27 
28 /// Get the size of the Index Padding field. This is needed by Index encoder
29 /// and decoder, but applications should have no use for this.
30 extern uint32_t lzma_index_padding_size(const lzma_index *i);
31 
32 
33 /// Round the variable-length integer to the next multiple of four.
34 static inline lzma_vli
vli_ceil4(lzma_vli vli)35 vli_ceil4(lzma_vli vli)
36 {
37 	assert(vli <= LZMA_VLI_MAX);
38 	return (vli + 3) & ~LZMA_VLI_C(3);
39 }
40 
41 
42 /// Calculate the size of the Index field excluding Index Padding
43 static inline lzma_vli
index_size_unpadded(lzma_vli count,lzma_vli index_list_size)44 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
45 {
46 	// Index Indicator + Number of Records + List of Records + CRC32
47 	return 1 + lzma_vli_size(count) + index_list_size + 4;
48 }
49 
50 
51 /// Calculate the size of the Index field including Index Padding
52 static inline lzma_vli
index_size(lzma_vli count,lzma_vli index_list_size)53 index_size(lzma_vli count, lzma_vli index_list_size)
54 {
55 	return vli_ceil4(index_size_unpadded(count, index_list_size));
56 }
57 
58 
59 /// Calculate the total size of the Stream
60 static inline lzma_vli
index_stream_size(lzma_vli blocks_size,lzma_vli count,lzma_vli index_list_size)61 index_stream_size(lzma_vli blocks_size,
62 		lzma_vli count, lzma_vli index_list_size)
63 {
64 	return LZMA_STREAM_HEADER_SIZE + blocks_size
65 			+ index_size(count, index_list_size)
66 			+ LZMA_STREAM_HEADER_SIZE;
67 }
68 
69 #endif
70