code: public static int writeVint(byte[] dest, int offset, int i) {
      if (i >= -112 && i <= 127) {
        dest[offset++] = (byte) i;
      } else {
        int len = -112;
        if (i < 0) {
          i ^= -1L; // take one's complement'
          len = -120;
        }
  
        long tmp = i;
        while (tmp != 0) {
          tmp = tmp >> 8;
          len--;
        }
  
        dest[offset++] = (byte) len;
  
        len = (len < -120) ? -(len + 120) : -(len + 112);
  
        for (int idx = len; idx != 0; idx--) {
          int shiftbits = (idx - 1) * 8;
          long mask = 0xFFL << shiftbits;
          dest[offset++] = (byte) ((i & mask) >> shiftbits);
        }
      }
  
      return offset;
    }
docs: Writes a vInt directly to a byte array
  
  @param dest The destination array for the vInt to be written to
  @param offset The location where to write the vInt to
  @param i The Value being written into byte array
  @return Returns the new offset location