1207753Smm///////////////////////////////////////////////////////////////////////////////
2207753Smm//
3207753Smm/// \file       vli_size.c
4207753Smm/// \brief      Calculates the encoded size of a variable-length integer
5207753Smm//
6207753Smm//  Author:     Lasse Collin
7207753Smm//
8207753Smm//  This file has been put into the public domain.
9207753Smm//  You can do whatever you want with this file.
10207753Smm//
11207753Smm///////////////////////////////////////////////////////////////////////////////
12207753Smm
13207753Smm#include "common.h"
14207753Smm
15207753Smm
16207753Smmextern LZMA_API(uint32_t)
17207753Smmlzma_vli_size(lzma_vli vli)
18207753Smm{
19207753Smm	if (vli > LZMA_VLI_MAX)
20207753Smm		return 0;
21207753Smm
22207753Smm	uint32_t i = 0;
23207753Smm	do {
24207753Smm		vli >>= 7;
25207753Smm		++i;
26207753Smm	} while (vli != 0);
27207753Smm
28207753Smm	assert(i <= LZMA_VLI_BYTES_MAX);
29207753Smm	return i;
30207753Smm}
31