/// <summary>
        /// Decodes a BEncoded number from the supplied RawReader
        /// </summary>
        /// <param name="reader">RawReader containing a BEncoded Number</param>
        internal override void DecodeInternal(RawReader reader)
        {
            var sign = 1;

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

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

            if (reader.PeekByte() == '-')
            {
                sign = -1;
                reader.ReadByte();
            }

            int letter;

            while (((letter = reader.PeekByte()) != -1) && letter != 'e')
            {
                if (letter < '0' || letter > '9')
                {
                    throw new BEncodingException("Invalid number found.");
                }
                InternalNumber = InternalNumber * 10 + (letter - '0');
                reader.ReadByte();
            }
            if (reader.ReadByte() != 'e')        //remove the trailing 'e'
            {
                throw new BEncodingException("Invalid data found. Aborting.");
            }

            InternalNumber *= sign;
        }
Exemple #2
0
 internal abstract void DecodeInternal(RawReader reader);
Exemple #3
0
 public static TValue Decode <TValue>(RawReader reader)
     where TValue : BEncodedValue
 {
     return((TValue)Decode(reader));
 }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 internal override void DecodeInternal(RawReader reader)
 {
     DecodeInternal(reader, reader.StrictDecoding);
 }