/// <summary>
        /// Decodes the internal.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="strictDecoding">if set to <c>true</c> [strict decoding].</param>
        /// <exception cref="TorrentClient.BEncoding.BEncodingException">
        /// Invalid data found. Aborting
        /// or
        /// or
        /// Invalid data found. Aborting
        /// </exception>
        private void DecodeInternal(RawReader reader, bool strictDecoding)
        {
            reader.CannotBeNull();

            BEncodedString key    = null;
            BEncodedValue  value  = null;
            BEncodedString oldkey = null;

            if (reader.ReadByte() != 'd')
            {
                throw new BEncodingException("Invalid data found. Aborting"); // Remove the leading 'd'
            }

            while (reader.PeekByte() != -1 &&
                   reader.PeekByte() != 'e')
            {
                key = (BEncodedString)BEncodedValue.Decode(reader);         // keys have to be BEncoded strings

                if (oldkey != null &&
                    oldkey.CompareTo(key) > 0)
                {
                    if (strictDecoding)
                    {
                        throw new BEncodingException($"Illegal BEncodedDictionary. The attributes are not ordered correctly. Old key: {oldkey}, New key: {key}");
                    }
                }

                oldkey = key;
                value  = BEncodedValue.Decode(reader);                    // the value is a BEncoded value
                this.dictionary.Add(key, value);
            }

            if (reader.ReadByte() != 'e')
            {
                throw new BEncodingException("Invalid data found. Aborting");
            }
        }
示例#2
0
 /// <summary>
 /// Decodes the stream into respected value.
 /// </summary>
 /// <param name="reader">The reader.</param>
 internal abstract void DecodeInternal(RawReader reader);
示例#3
0
        /// <summary>
        /// Decodes the specified reader.
        /// </summary>
        /// <typeparam name="T">The BEncoded value type.</typeparam>
        /// <param name="reader">The reader.</param>
        /// <returns>
        /// The BEncoded value.
        /// </returns>
        public static T Decode <T>(RawReader reader) where T : BEncodedValue
        {
            reader.CannotBeNull();

            return((T)BEncodedValue.Decode(reader));
        }
        /// <summary>
        /// Decodes the internal.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void DecodeInternal(RawReader reader)
        {
            reader.CannotBeNull();

            this.DecodeInternal(reader, reader.StrictDecoding);
        }