private static void writeExtensibleMatchFilter(
            BerBuffer buffer,
            byte[] filter,
            int matchStart,
            int matchEnd,
            int valueStart,
            int valueEnd) {
        boolean matchDN = false;
        int firstColon = ByteUtil.indexOf(filter, ':', matchStart, matchEnd);
        int secondColon;
        int i;

        buffer.beginSequence(TYPE_EXTENSIBLE_MATCH);

        if (firstColon >= 0) {
            if ((i = ByteUtil.indexOf(filter, ":dn", firstColon, matchEnd)) >= 0) {
                matchDN = true;
            }
            // test for matching rule
            if (((secondColon = ByteUtil.indexOf(filter, ':', firstColon + 1, matchEnd)) >= 0)
                    || (i == -1)) {
                if (i == firstColon) {
                    buffer.writeOctetString(EXTENSIBLE_MATCHING_RULE,
                            filter,
                            secondColon + 1,
                            matchEnd - (secondColon + 1));
                } else if ((i == secondColon) && (i >= 0)) {
                    buffer.writeOctetString(EXTENSIBLE_MATCHING_RULE,
                            filter,
                            firstColon + 1,
                            secondColon - (firstColon + 1));
                } else {
                    buffer.writeOctetString(EXTENSIBLE_MATCHING_RULE,
                            filter,
                            firstColon + 1,
                            matchEnd - (firstColon + 1));
                }
            }
            // test for the attribute type.
            if (firstColon > matchStart) {
                buffer.writeOctetString(EXTENSIBLE_MATCHING_TYPE,
                        filter,
                        matchStart,
                        firstColon - matchStart);
            }
        } else {
            buffer.writeOctetString(EXTENSIBLE_MATCHING_TYPE,
                    filter,
                    matchStart,
                    matchEnd - matchStart);
        }
        byte[] filterValue = unescapeFilterValue(filter, valueStart, valueEnd);
        if (filterValue == null) {
            buffer.writeOctetString(EXTENSIBLE_MATCHING_VALUE,
                    filter,
                    valueStart,
                    valueEnd - valueStart);
        } else {
            buffer.writeOctetString(EXTENSIBLE_MATCHING_VALUE, filterValue);
        }
        buffer.writeBoolean(EXTENSIBLE_MATCHING_DN, matchDN)
                .endSequence();
    }
@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