public static int getSerializedSize1_2_4Bytes(int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Cannot encode negative number");
        } else if (number > 0x3FFFFFFF) {
            throw new IllegalArgumentException("Cannot encode number larger than 2^30.");
        }

        if (number < 0x80) {
            //length 1 byte
            return 1;
        } else if (number < 0x4000) {
            //length 2 bytes
            return 2;
        } else {
            //length 4 bytes
            return 4;
        }
    }
Computes the size used for storing the given integer using 1, 2 or 4 bytes.

@param number the integer to check length of
@return the number of bytes used to store it; 1, 2 or 4
vespajlib/src/main/java/com/yahoo/io/GrowableByteBuffer.java