Here you can find the source of sizeOfInVarInt32(int length)
Parameter | Description |
---|---|
length | Length to encode |
length
public static int sizeOfInVarInt32(int length)
//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; } }