index.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef LZMA_INDEX_H
  13. #define LZMA_INDEX_H
  14. #include "common.h"
  15. /// Minimum Unpadded Size
  16. #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
  17. /// Maximum Unpadded Size
  18. #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
  19. /// Get the size of the Index Padding field. This is needed by Index encoder
  20. /// and decoder, but applications should have no use for this.
  21. extern uint32_t lzma_index_padding_size(const lzma_index *i);
  22. /// Set for how many Records to allocate memory the next time
  23. /// lzma_index_append() needs to allocate space for a new Record.
  24. /// This is used only by the Index decoder.
  25. extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
  26. /// Round the variable-length integer to the next multiple of four.
  27. static inline lzma_vli
  28. vli_ceil4(lzma_vli vli)
  29. {
  30. assert(vli <= LZMA_VLI_MAX);
  31. return (vli + 3) & ~LZMA_VLI_C(3);
  32. }
  33. /// Calculate the size of the Index field excluding Index Padding
  34. static inline lzma_vli
  35. index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
  36. {
  37. // Index Indicator + Number of Records + List of Records + CRC32
  38. return 1 + lzma_vli_size(count) + index_list_size + 4;
  39. }
  40. /// Calculate the size of the Index field including Index Padding
  41. static inline lzma_vli
  42. index_size(lzma_vli count, lzma_vli index_list_size)
  43. {
  44. return vli_ceil4(index_size_unpadded(count, index_list_size));
  45. }
  46. /// Calculate the total size of the Stream
  47. static inline lzma_vli
  48. index_stream_size(lzma_vli blocks_size,
  49. lzma_vli count, lzma_vli index_list_size)
  50. {
  51. return LZMA_STREAM_HEADER_SIZE + blocks_size
  52. + index_size(count, index_list_size)
  53. + LZMA_STREAM_HEADER_SIZE;
  54. }
  55. #endif