code: public static void marshallSize(ObjectOutput out, int value) throws IOException {
        if (value < 0) {
           out.writeByte(0x80); //meaning it is a negative value!
           return;
        }
        if ((value & ~0x3F) == 0) { // fits in 1 byte
           out.writeByte(value & 0x3F); //first bit is 0 (== positive) and second bit is zero (== not more bytes)
           return;
        }
        out.writeByte((value & 0x3F) | 0x40); //set second bit to 1 (== more bytes)
        value >>>= 6; //6 bits written so far
        //normal code for unsigned int. only the first byte is special
        while ((value & ~0x7F) != 0) {
           out.writeByte((byte) ((value & 0x7f) | 0x80));
           value >>>= 7;
        }
        out.writeByte((byte) value);
     }
docs: A special marshall implementation for integer.
  <p>
  This method supports negative values but they are handles as {@link #NULL_VALUE}. It means that the real value is
  lost and {@link #NULL_VALUE} is returned by {@link #unmarshallSize(ObjectInput)}.
  <p>
  The integer is marshalled in a variable length from 1 to 5 bytes. Negatives values are always marshalled in 1
  byte.
  
  @param out   {@link ObjectOutput} to write.
  @param value Integer value to marshall.
  @throws IOException If any of the usual Input/Output related exceptions occur.