public static bool ReadBoolean(Stream stream)
{
if (stream == null) {
throw new ArgumentNullException("stream");
}
int b = stream.ReadByte();
if (b == 0xf4) {
return false;
}
if (b == 0xf5) {
return true;
}
while ((b >> 5) == 6) {
// Skip tags until a tag character is no longer read
if (b == 0xd8) {
stream.ReadByte();
} else if (b == 0xd9) {
stream.Position += 2;
} else if (b == 0xda) {
stream.Position += 4;
} else if (b == 0xdb) {
stream.Position += 8;
} else if (b > 0xdb) {
throw new IOException("Not a boolean");
}
b = stream.ReadByte();
}
if (b == 0xf4) {
return false;
}
if (b == 0xf5) {
return true;
}
throw new IOException("Not a boolean");
}