vli_size.c 630 B

123456789101112131415161718192021222324252627282930
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file vli_size.c
  4. /// \brief Calculates the encoded size of a variable-length integer
  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. #include "common.h"
  13. extern LZMA_API(uint32_t)
  14. lzma_vli_size(lzma_vli vli)
  15. {
  16. if (vli > LZMA_VLI_MAX)
  17. return 0;
  18. uint32_t i = 0;
  19. do {
  20. vli >>= 7;
  21. ++i;
  22. } while (vli != 0);
  23. assert(i <= LZMA_VLI_BYTES_MAX);
  24. return i;
  25. }