/// <summary> /// Decode the next token as a list. /// Assumes the next token is a list. /// </summary> /// <param name="inputStream"></param> /// <returns>Decoded list</returns> public static BList Decode(BinaryReader inputStream) { // Get past 'l' inputStream.Read(); BList res = new BList(); // Read elements till an 'e' while (inputStream.PeekChar() != 'e') { res.Add(BencodingUtils.Decode(inputStream)); } // Get past 'e' inputStream.Read(); return(res); }
/// <summary> /// Decode the next token as a dictionary. /// Assumes the next token is a dictionary. /// </summary> /// <param name="inputStream"></param> /// <returns>Decoded dictionary</returns> public static BDict Decode(BinaryReader inputStream) { // Get past 'd' inputStream.Read(); BDict res = new BDict(); // Read elements till an 'e' while (inputStream.PeekChar() != 'e') { // Key BString key = BString.Decode(inputStream); // Value IBencodingType value = BencodingUtils.Decode(inputStream); res[key.Value] = value; } // Get past 'e' inputStream.Read(); return(res); }