Ejemplo n.º 1
0
        /// <summary>
        /// Decode the next token as a dictionary.
        /// Assumes the next token is a dictionary.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="bytesConsumed"></param>
        /// <returns>Decoded dictionary</returns>
        public static BDict Decode(BinaryReader inputStream, ref int bytesConsumed)
        {
            // Get past 'd'
            inputStream.ReadByte();

            bytesConsumed++;
            BDict res = new BDict();

            // Read elements till an 'e'
            while (inputStream.PeekChar() != 'e')
            {
                // Key
                BString key = BString.Decode(inputStream, ref bytesConsumed);

                // Value
                IBencodingType value = BencodingUtils.Decode(inputStream, ref bytesConsumed);

                res[key.Value] = value;
            }

            // Get past 'e'
            inputStream.Read();
            bytesConsumed++;

            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decode the next token as a list.
        /// Assumes the next token is a list.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="bytesConsumed"></param>
        /// <returns>Decoded list</returns>
        public static BList Decode(BinaryReader inputStream, ref int bytesConsumed)
        {
            // Get past 'l'
            inputStream.Read();
            bytesConsumed++;

            BList res = new BList();

            // Read elements till an 'e'
            while (inputStream.PeekChar() != 'e')
            {
                res.Add(BencodingUtils.Decode(inputStream, ref bytesConsumed));
            }

            // Get past 'e'
            inputStream.Read();
            bytesConsumed++;

            return(res);
        }