Exemplo n.º 1
0
        // TODO check comment, if only vs. only if
        /// <summary>
        /// Restore the content references if only the content types array is
        /// present. The content references are removed when decoding a message. That
        /// means if a message was received it cannot be used a second time as the
        /// content references are not there anymore. This method restores the
        /// content references based on the content types of the message.
        /// </summary>
        public void RestoreContentReferences()
        {
            IDictionary <Content, int> references = new Dictionary <Content, int>(ContentTypes.Count() * 2);

            foreach (var contentType in ContentTypes)
            {
                // TODO what about Content.Undefined
                if (contentType == Content.Empty)
                {
                    return;
                }

                int index = 0;
                if (contentType == Content.PublicKeySignature || contentType == Content.PublicKey)
                {
                    int j = references[Content.PublicKeySignature];
                    if (j != default(int))
                    {
                        index = j;
                    }
                    else
                    {
                        j = references[Content.PublicKey];
                        if (j != default(int))
                        {
                            index = j;
                        }
                    }
                }

                if (!references.ContainsKey(contentType))
                {
                    references.Add(contentType, index);
                }
                else
                {
                    index = references[contentType];
                }

                ContentReferences.Enqueue(new MessageContentIndex(index, contentType));
                references.Add(contentType, index + 1);
            }
        }