Represents an LdapResult.
 LdapResult ::= SEQUENCE { resultCode      ENUMERATED { success                      (0), operationsError              (1), protocolError                (2), timeLimitExceeded            (3), sizeLimitExceeded            (4), compareFalse                 (5), compareTrue                  (6), authMethodNotSupported       (7), strongAuthRequired           (8), -- 9 reserved -- referral                     (10),  -- new adminLimitExceeded           (11),  -- new unavailableCriticalExtension (12),  -- new confidentialityRequired      (13),  -- new saslBindInProgress           (14),  -- new noSuchAttribute              (16), undefinedAttributeType       (17), inappropriateMatching        (18), constraintViolation          (19), attributeOrValueExists       (20), invalidAttributeSyntax       (21), -- 22-31 unused -- noSuchObject                 (32), aliasProblem                 (33), invalidDNSyntax              (34), -- 35 reserved for undefined isLeaf -- aliasDereferencingProblem    (36), -- 37-47 unused -- inappropriateAuthentication  (48), invalidCredentials           (49), insufficientAccessRights     (50), busy                         (51), unavailable                  (52), unwillingToPerform           (53), loopDetect                   (54), -- 55-63 unused -- namingViolation              (64), objectClassViolation         (65), notAllowedOnNonLeaf          (66), notAllowedOnRDN              (67), entryAlreadyExists           (68), objectClassModsProhibited    (69), -- 70 reserved for CLdap -- affectsMultipleDSAs          (71), -- new -- 72-79 unused -- other                        (80) }, -- 81-90 reserved for APIs -- matchedDN       LdapDN, errorMessage    LdapString, referral        [3] Referral OPTIONAL } 
Inheritance: Novell.Directory.Ldap.Asn1.Asn1Sequence, RfcResponse
        public static async ValueTask <RfcLdapMessage> Decode(IAsn1Decoder dec, Stream inRenamed, int len, CancellationToken cancellationToken)
        {
            var message = new RfcLdapMessage(await DecodeStructured(dec, inRenamed, len, cancellationToken).ConfigureAwait(false));

            // Decode implicitly tagged protocol operation from an Asn1Tagged type
            // to its appropriate application type.
            var protocolOp   = (Asn1Tagged)message.get_Renamed(1);
            var protocolOpId = protocolOp.GetIdentifier();
            var content      = ((Asn1OctetString)protocolOp.TaggedValue).ByteValue();
            var bais         = new MemoryStream(content);

            switch (protocolOpId.Tag)
            {
            case LdapMessage.SearchResponse:
                message.set_Renamed(1, new RfcSearchResultEntry(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)));
                break;

            case LdapMessage.SearchResult:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcSearchResultDone(newContent)).ConfigureAwait(false));
                break;

            case LdapMessage.SearchResultReference:
                message.set_Renamed(1, new RfcSearchResultReference(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)));
                break;

            case LdapMessage.AddResponse:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcAddResponse(newContent)).ConfigureAwait(false));
                break;

            case LdapMessage.BindResponse:
                message.set_Renamed(1, await RfcBindResponse.Decode(dec, bais, content.Length, cancellationToken).ConfigureAwait(false));
                break;

            case LdapMessage.CompareResponse:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcCompareResponse(newContent)).ConfigureAwait(false));
                break;

            case LdapMessage.DelResponse:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcDelResponse(newContent)).ConfigureAwait(false));
                break;

            case LdapMessage.ExtendedResponse:
                message.set_Renamed(1, new RfcExtendedResponse(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)));
                break;

            case LdapMessage.IntermediateResponse:
                message.set_Renamed(1, new RfcIntermediateResponse(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)));
                break;

            case LdapMessage.ModifyResponse:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcModifyResponse(newContent)).ConfigureAwait(false));
                break;

            case LdapMessage.ModifyRdnResponse:
                message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcModifyDnResponse(newContent)).ConfigureAwait(false));
                break;

            default:
                throw new Exception("RfcLdapMessage: Invalid tag: " + protocolOpId.Tag);
            }

            // decode optional implicitly tagged controls from Asn1Tagged type to
            // to RFC 2251 types.
            if (message.Size() > 2)
            {
                var controls = (Asn1Tagged)message.get_Renamed(2);

                // Asn1Identifier controlsId = protocolOp.getIdentifier();
                // we could check to make sure we have controls here....
                content = ((Asn1OctetString)controls.TaggedValue).ByteValue();
                bais    = new MemoryStream(content);
                message.set_Renamed(2, await RfcControls.Decode(dec, bais, content.Length, cancellationToken).ConfigureAwait(false));
            }

            return(message);
        }