private static BDictionary ReadDictionary(BinaryReader binaryReader)
{
Contract.Requires(binaryReader != null);
int i = binaryReader.ReadByte();
if (i != 'd')
{
throw Error();
}
BDictionary dict = new BDictionary();
try
{
for (int c = binaryReader.PeekChar(); ; c = binaryReader.PeekChar())
{
if (c == -1) throw Error();
if (c == 'e')
{
binaryReader.ReadByte();
break;
}
BString k = ReadString(binaryReader);
IBElement v = ReadElement(binaryReader);
dict.Add(k, v);
}
}
catch (BencodingException) { throw; }
catch (Exception e) { throw Error(e); }
return dict;
}