Java Type Size sizeOfInVarInt32(int length)

Here you can find the source of sizeOfInVarInt32(int length)

Description

Compute the space needed to encode the length in BER code.

License

Open Source License

Parameter

Parameter Description
length Length to encode

Return

the count of bytes needed to encode the value length

Declaration

public static int sizeOfInVarInt32(int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w ww.  j a v  a2 s.c o m*/
     * Compute the space needed to encode the length in BER code.
     *
     * @param length Length to encode
     * @return the count of bytes needed to encode the value <code>length</code>
     */
    public static int sizeOfInVarInt32(int length) {
        if (length < (1 << 7)) {
            return 1;
        }
        if (length < (1 << 14)) {
            return 2;
        }
        if (length < (1 << 21)) {
            return 3;
        }
        if (length < (1 << 28)) {
            return 4;
        }
        return 5;
    }
}

Related

  1. sizeOfCompactInt(int i)
  2. sizeOfEnumValue(T enumValue)
  3. sizeOfFloat(float f)
  4. sizeOfInt()
  5. sizeOfInt(int x)
  6. sizeOfPrimitive(Object object)
  7. sizeOfPrimitiveArray(Object object)
  8. sizeOfTreeMap(int size)
  9. sizeOfVarint(int value)