public static int readVarInt(ByteBuffer buffer) {
        long result = 0L;
        int shift = 0;
        for (int i = 0; i < 9; i++) {
            // gets 7 bits from next byte
            byte b = buffer.get();
            result |= (b & 0x7F) << shift;
            if ((b & 0x80) == 0) {
                break;
            }
            shift += 7;
        }

        return (int) result;
    }
Read varint from given byte buffer.

@param buffer non-null byte buffer
@return varint
clickhouse-data/src/main/java/com/clickhouse/data/format/BinaryStreamUtils.java