public static int getSerializedSize2_4_8Bytes(long number) {
        if (number < 0L) {
            throw new IllegalArgumentException("Cannot encode negative number.");
        } else if (number > 0x3FFFFFFFFFFFFFFFL) {
            throw new IllegalArgumentException("Cannot encode number larger than 2^62.");
        }

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

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