public static Pair<Integer, Integer> readRawVarint32(byte[] input, int offset)
    throws IOException {
    int newOffset = offset;
    byte tmp = input[newOffset++];
    if (tmp >= 0) {
      return new Pair<>((int) tmp, newOffset - offset);
    }
    int result = tmp & 0x7f;
    tmp = input[newOffset++];
    if (tmp >= 0) {
      result |= tmp << 7;
    } else {
      result |= (tmp & 0x7f) << 7;
      tmp = input[newOffset++];
      if (tmp >= 0) {
        result |= tmp << 14;
      } else {
        result |= (tmp & 0x7f) << 14;
        tmp = input[newOffset++];
        if (tmp >= 0) {
          result |= tmp << 21;
        } else {
          result |= (tmp & 0x7f) << 21;
          tmp = input[newOffset++];
          result |= tmp << 28;
          if (tmp < 0) {
            // Discard upper 32 bits.
            for (int i = 0; i < 5; i++) {
              tmp = input[newOffset++];
              if (tmp >= 0) {
                return new Pair<>(result, newOffset - offset);
              }
            }
            throw new IOException("Malformed varint");
          }
        }
      }
    }
    return new Pair<>(result, newOffset - offset);
  }
Reads a varInt value stored in an array. Input array where the varInt is available Offset in
the input array where varInt is available
@return A pair of integers in which first value is the actual decoded varInt value and second
        value as number of bytes taken by this varInt for it's storage in the input array.
@throws IOException When varint is malformed and not able to be read correctly
hbase-common/src/main/java/org/apache/hadoop/hbase/io/util/StreamUtils.java