public void putInt1_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
            put((byte) number);
        } else if (number < 0x4000) {
            //length 2 bytes
            putShort((short) (((short)number) | ((short) 0x8000)));
        } else {
            //length 4 bytes
            putInt(number | 0xC0000000);
        }
    }
Writes a 30-bit positive integer to the buffer, using 1, 2, or 4 bytes.

@param number the integer to write
vespajlib/src/main/java/com/yahoo/io/GrowableByteBuffer.java