private bool TryLookupKey(int key, out XmlDictionaryString result)
 {
     if (BinaryFormatParser.IsSessionKey(key))
     {
         return(this.readerSession.TryLookup(BinaryFormatParser.GetSessionKey(key), out result));
     }
     return(this.dictionary.TryLookup(BinaryFormatParser.GetStaticKey(key), out result));
 }
        public Message TryCreateMessage(byte[] buffer, int offset, int size, BufferManager bufferManager, BufferedMessageData messageData)
        {
            RelatesToHeader     header;
            MessageIDHeader     header2;
            XmlDictionaryString anonymous;
            int num6;
            XmlDictionaryString str2;
            int num  = offset;
            int num2 = size;
            int num3 = BinaryFormatParser.MatchBytes(buffer, num, num2, commonFragment);

            if (num3 == 0)
            {
                return(null);
            }
            num  += num3;
            num2 -= num3;
            num3  = BinaryFormatParser.MatchKey(buffer, num, num2);
            if (num3 == 0)
            {
                return(null);
            }
            int num4 = num;
            int num5 = num3;

            num  += num3;
            num2 -= num3;
            num3  = BinaryFormatParser.MatchBytes(buffer, num, num2, requestFragment1);
            if (num3 != 0)
            {
                num  += num3;
                num2 -= num3;
                num3  = BinaryFormatParser.MatchUniqueID(buffer, num, num2);
                if (num3 == 0)
                {
                    return(null);
                }
                int num7 = num;
                int num8 = num3;
                num  += num3;
                num2 -= num3;
                num3  = BinaryFormatParser.MatchBytes(buffer, num, num2, requestFragment2);
                if (num3 == 0)
                {
                    return(null);
                }
                num  += num3;
                num2 -= num3;
                if (BinaryFormatParser.MatchAttributeNode(buffer, num, num2))
                {
                    return(null);
                }
                header2 = MessageIDHeader.Create(BinaryFormatParser.ParseUniqueID(buffer, num7, num8), this.messageVersion.Addressing);
                header  = null;
                if (!this.readerSession.TryLookup(1, out anonymous))
                {
                    return(null);
                }
                num6 = (requestFragment1.Length + num8) + requestFragment2.Length;
            }
            else
            {
                num3 = BinaryFormatParser.MatchBytes(buffer, num, num2, responseFragment1);
                if (num3 == 0)
                {
                    return(null);
                }
                num  += num3;
                num2 -= num3;
                num3  = BinaryFormatParser.MatchUniqueID(buffer, num, num2);
                if (num3 == 0)
                {
                    return(null);
                }
                int num9  = num;
                int num10 = num3;
                num  += num3;
                num2 -= num3;
                num3  = BinaryFormatParser.MatchBytes(buffer, num, num2, responseFragment2);
                if (num3 == 0)
                {
                    return(null);
                }
                num  += num3;
                num2 -= num3;
                if (BinaryFormatParser.MatchAttributeNode(buffer, num, num2))
                {
                    return(null);
                }
                header    = RelatesToHeader.Create(BinaryFormatParser.ParseUniqueID(buffer, num9, num10), this.messageVersion.Addressing);
                header2   = null;
                anonymous = XD.Addressing10Dictionary.Anonymous;
                num6      = (responseFragment1.Length + num10) + responseFragment2.Length;
            }
            num6 += commonFragment.Length + num5;
            int key = BinaryFormatParser.ParseKey(buffer, num4, num5);

            if (!this.TryLookupKey(key, out str2))
            {
                return(null);
            }
            ActionHeader actionHeader = ActionHeader.Create(str2, this.messageVersion.Addressing);

            if (this.toHeader == null)
            {
                this.toHeader = ToHeader.Create(new Uri(anonymous.Value), this.messageVersion.Addressing);
            }
            int num12 = num6 - bodyFragment.Length;

            offset += num12;
            size   -= num12;
            Buffer.BlockCopy(bodyFragment, 0, buffer, offset, bodyFragment.Length);
            messageData.Open(new ArraySegment <byte>(buffer, offset, size), bufferManager);
            PatternMessage message = new PatternMessage(messageData, this.messageVersion);
            MessageHeaders headers = message.Headers;

            headers.AddActionHeader(actionHeader);
            if (header2 != null)
            {
                headers.AddMessageIDHeader(header2);
                headers.AddReplyToHeader(ReplyToHeader.AnonymousReplyTo10);
            }
            else
            {
                headers.AddRelatesToHeader(header);
            }
            headers.AddToHeader(this.toHeader);
            return(message);
        }