index.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file index.h
  4. /// \brief Handling of Index
  5. /// \note This header file does not include common.h or lzma.h because
  6. /// this file is needed by both liblzma internally and by the
  7. /// tests. Including common.h will include and define many things
  8. /// the tests do not need and prevents issues with header file
  9. /// include order. This way, if lzma.h or common.h are not
  10. /// included before this file it will break on every OS instead
  11. /// of causing more subtle errors.
  12. //
  13. // Author: Lasse Collin
  14. //
  15. // This file has been put into the public domain.
  16. // You can do whatever you want with this file.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef LZMA_INDEX_H
  20. #define LZMA_INDEX_H
  21. /// Minimum Unpadded Size
  22. #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
  23. /// Maximum Unpadded Size
  24. #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
  25. /// Index Indicator based on xz specification
  26. #define INDEX_INDICATOR 0
  27. /// Get the size of the Index Padding field. This is needed by Index encoder
  28. /// and decoder, but applications should have no use for this.
  29. extern uint32_t lzma_index_padding_size(const lzma_index *i);
  30. /// Set for how many Records to allocate memory the next time
  31. /// lzma_index_append() needs to allocate space for a new Record.
  32. /// This is used only by the Index decoder.
  33. extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
  34. /// Round the variable-length integer to the next multiple of four.
  35. static inline lzma_vli
  36. vli_ceil4(lzma_vli vli)
  37. {
  38. assert(vli <= UNPADDED_SIZE_MAX);
  39. return (vli + 3) & ~LZMA_VLI_C(3);
  40. }
  41. /// Calculate the size of the Index field excluding Index Padding
  42. static inline lzma_vli
  43. index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
  44. {
  45. // Index Indicator + Number of Records + List of Records + CRC32
  46. return 1 + lzma_vli_size(count) + index_list_size + 4;
  47. }
  48. /// Calculate the size of the Index field including Index Padding
  49. static inline lzma_vli
  50. index_size(lzma_vli count, lzma_vli index_list_size)
  51. {
  52. return vli_ceil4(index_size_unpadded(count, index_list_size));
  53. }
  54. /// Calculate the total size of the Stream
  55. static inline lzma_vli
  56. index_stream_size(lzma_vli blocks_size,
  57. lzma_vli count, lzma_vli index_list_size)
  58. {
  59. return LZMA_STREAM_HEADER_SIZE + blocks_size
  60. + index_size(count, index_list_size)
  61. + LZMA_STREAM_HEADER_SIZE;
  62. }
  63. #endif