code: public static int putVarInt(int v, byte[] sink, int offset) {
      do {
        // Encode next 7 bits + terminator bit
        int bits = v & 0x7F;
        v >>>= 7;
        byte b = (byte) (bits + ((v != 0) ? 0x80 : 0));
        sink[offset++] = b;
      } while (v != 0);
      return offset;
    }
docs: Encodes an integer in a variable-length encoding, 7 bits per byte, into a destination byte[],
  following the protocol buffer convention.
  
  @param v the int value to write to sink
  @param sink the sink buffer to write to
  @param offset the offset within sink to begin writing
  @return the updated offset after writing the varint