コード例 #1
0
        internal static IBencodingType Decode(BinaryReader inputStream)
        {
            char next = (char)inputStream.PeekChar();

            switch (next)
            {
            case 'i':
                // Integer
                return(BInt.Decode(inputStream));

            case 'l':
                // List
                return(BList.Decode(inputStream));

            case 'd':
                // List
                return(BDict.Decode(inputStream));

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                // String
                return(BString.Decode(inputStream));
            }

            return(null);
        }
コード例 #2
0
ファイル: BInt.cs プロジェクト: cl456852/torrentFilter
        public bool Equals(BInt other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Equals(other.Value));
        }
コード例 #3
0
ファイル: BInt.cs プロジェクト: cl456852/torrentFilter
        public int CompareTo(BInt other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (Value < other.Value)
            {
                return(-1);
            }

            if (Value > other.Value)
            {
                return(1);
            }

            return(0);
        }
コード例 #4
0
ファイル: BInt.cs プロジェクト: cl456852/torrentFilter
        /// <summary>
        /// Decode the next token as a int.
        /// Assumes the next token is a int.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <returns>Decoded int</returns>
        public static BInt Decode(BinaryReader inputStream)
        {
            // Get past 'i'
            inputStream.Read();

            // Read numbers till an 'e'
            string number = "";
            char   ch;

            while ((ch = inputStream.ReadChar()) != 'e')
            {
                number += ch;
            }

            BInt res = new BInt {
                Value = long.Parse(number)
            };

            return(res);
        }
コード例 #5
0
ファイル: BInt.cs プロジェクト: cl456852/torrentFilter
        public override bool Equals(object obj)
        {
            BInt other = obj as BInt;

            return(Equals(other));
        }