protected byte[] BuildMask(Dictionary <string, EndpointAddressProcessor.HeaderBit[]> headerLookup)
 {
     byte[] mask = null;
     foreach (KeyValuePair <string, EndpointAddressProcessor.HeaderBit[]> pair in headerLookup)
     {
         EndpointAddressProcessor.HeaderBit[] bitArray;
         if (this.headerLookup.TryGetValue(pair.Key, out bitArray))
         {
             if (bitArray.Length < pair.Value.Length)
             {
                 int length = bitArray.Length;
                 Array.Resize <EndpointAddressProcessor.HeaderBit>(ref bitArray, pair.Value.Length);
                 for (int j = length; j < pair.Value.Length; j++)
                 {
                     bitArray[j] = new EndpointAddressProcessor.HeaderBit(this.nextBit++);
                 }
                 this.headerLookup[pair.Key] = bitArray;
             }
         }
         else
         {
             bitArray = new EndpointAddressProcessor.HeaderBit[pair.Value.Length];
             for (int k = 0; k < pair.Value.Length; k++)
             {
                 bitArray[k] = new EndpointAddressProcessor.HeaderBit(this.nextBit++);
             }
             this.headerLookup.Add(pair.Key, bitArray);
         }
         for (int i = 0; i < pair.Value.Length; i++)
         {
             bitArray[i].AddToMask(ref mask);
         }
     }
     if (this.nextBit == 0)
     {
         this.size = 0;
         return(mask);
     }
     this.size = ((this.nextBit - 1) / 8) + 1;
     return(mask);
 }
Exemple #2
0
        private void CreateMask()
        {
            int num = 0;

            this.qnameLookup  = new Dictionary <EndpointAddressProcessor.QName, int>(EndpointAddressProcessor.QNameComparer);
            this.headerLookup = new Dictionary <string, EndpointAddressProcessor.HeaderBit[]>();
            StringBuilder builder = null;

            for (int i = 0; i < this.address.Headers.Count; i++)
            {
                EndpointAddressProcessor.HeaderBit[] bitArray;
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                else
                {
                    builder.Remove(0, builder.Length);
                }
                string comparableForm = this.address.Headers[i].GetComparableForm(builder);
                if (this.headerLookup.TryGetValue(comparableForm, out bitArray))
                {
                    Array.Resize <EndpointAddressProcessor.HeaderBit>(ref bitArray, bitArray.Length + 1);
                    bitArray[bitArray.Length - 1]     = new EndpointAddressProcessor.HeaderBit(num++);
                    this.headerLookup[comparableForm] = bitArray;
                }
                else
                {
                    EndpointAddressProcessor.QName       name;
                    EndpointAddressProcessor.HeaderBit[] bitArray2 = new EndpointAddressProcessor.HeaderBit[] { new EndpointAddressProcessor.HeaderBit(num++) };
                    this.headerLookup.Add(comparableForm, bitArray2);
                    AddressHeader header = this.address.Headers[i];
                    name.name = header.Name;
                    name.ns   = header.Namespace;
                    this.qnameLookup[name] = 1;
                }
            }
            if (num == 0)
            {
                this.size = 0;
            }
            else
            {
                this.size = ((num - 1) / 8) + 1;
            }
            if (this.size > 0)
            {
                this.mask = new byte[this.size];
                for (int j = 0; j < (this.size - 1); j++)
                {
                    this.mask[j] = 0xff;
                }
                if ((num % 8) == 0)
                {
                    this.mask[this.size - 1] = 0xff;
                }
                else
                {
                    this.mask[this.size - 1] = (byte)((((int)1) << (num % 8)) - 1);
                }
            }
        }