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

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

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

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

            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, ref bytesConsumed));
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Decode the next token as a int.
        /// Assumes the next token is a int.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="bytesConsumed"></param>
        /// <returns>Decoded int</returns>
        public static BInt Decode(BinaryReader inputStream, ref int bytesConsumed)
        {
            // Get past 'i'
            inputStream.Read();
            bytesConsumed++;

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

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

                bytesConsumed++;
            }

            bytesConsumed++;

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

            return(res);
        }
コード例 #3
0
        public bool Equals(BInt other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Equals(other.Value));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public override bool Equals(object obj)
        {
            BInt other = obj as BInt;

            return(Equals(other));
        }