private static void writeFilterInSet(
            BerBuffer buffer,
            byte[] filter,
            int filterType,
            int start,
            int end) {
        Context context = new Context();
        int currentFilterIndex = 0;
        for (context.readIndex = start; context.readIndex < end; context.readIndex++) {
            char c = (char) filter[context.readIndex];
            if (Character.isSpaceChar(c) || c == '(') {
                continue;
            }
            if ((filterType == TYPE_NOT) && (currentFilterIndex > 0)) {
                throw new LdapException(
                        ResultCode.FILTER_ERROR,
                        "The filter \"!\" cannot be followed by more than one filter");
            }

            int closingParenIndex = findClosingParenIndex(filter, context.readIndex, end);

            int length = closingParenIndex - context.readIndex;
            byte[] newFilter = new byte[length + 2];
            System.arraycopy(filter, context.readIndex, newFilter, 1, length);
            newFilter[0] = (byte) '(';
            newFilter[length + 1] = (byte) ')';
            writeFilter(buffer, newFilter, newFilter.length);
            currentFilterIndex++;
            context.readIndex = closingParenIndex + 1;
        }
    }
@author James Chen
@implSpec <a href="https://tools.ietf.org/html/rfc4515"> RFC 4515: String Representation of
          Search Filters</a>
turms-gateway/src/main/java/im/turms/gateway/infra/ldap/element/operation/search/Filter.java