@Override
    public SearchResult decode(BerBuffer buffer) {
        byte tag = buffer.readTag();
        buffer.skipLength();
        List<Attribute> attributes;
        String objectName;
        SearchResultEntry entry;
        switch (tag) {
            case SEARCH_RESULT_ENTRY -> {
                List<SearchResultEntry> resultEntries = new ArrayList<>(8);
                attributes = new ArrayList<>(16);
                objectName = buffer.readOctetString();

                buffer.skipTag();
                int length = buffer.readLength();
                int end = buffer.readerIndex() + length;
                while (buffer.isReadableWithEnd(end)) {
                    attributes.add(Attribute.decode(buffer));
                }

                List<Control> controls = Control.decode(buffer);
                entry = new SearchResultEntry(objectName, attributes, controls);
                resultEntries.add(entry);
                return new SearchResult(0, null, null, null, resultEntries) {
                    @Override
                    public boolean isComplete() {
                        return false;
                    }
                };
            }
            case SEARCH_RESULT_DONE -> {
                if (entries == null) {
                    throw new LdapException(
                            ResultCode.PROTOCOL_ERROR,
                            "The search result is not complete yet");
                }
                LdapResult result = LdapResult.decodeResult(buffer);
                return new SearchResult(
                        result.getResultCode(),
                        result.getMatchedDn(),
                        result.getDiagnosticMessage(),
                        result.getReferrals(),
                        entries);
            }
            default -> throw new LdapException(
                    ResultCode.PROTOCOL_ERROR,
                    "Unexpected tag for the search result: "
                            + tag);
        }
    }
@author James Chen
@implSpec <a href="https://datatracker.ietf.org/doc/html/rfc4511#section-4.5.2">4.5.2. Search
          Result</a>
turms-gateway/src/main/java/im/turms/gateway/infra/ldap/element/operation/search/SearchResult.java