private bool ReadMagic(BinaryReader reader)
{
try
{
ini:
byte b0 = reader.ReadByte();
if (b0 != 0xF9) goto ini;
b0 = reader.ReadByte();
if (b0 != 0xbe) goto ini;
b0 = reader.ReadByte();
if (b0 != 0xb4) goto ini;
b0 = reader.ReadByte();
if (b0 != 0xd9) goto ini;
return true;
}
catch (EndOfStreamException)
{
return false;
}
}
I found this piece of code on github and was wondering why someone would use the ReadMagic function instead of the usual reader.Read() function? Also could someone explain how the ReadMagic function works?
using(var reader = command.ExecuteReader())
{
while(ReadMagic(reader));
}
goto? Amazing...var seq = new byte[] {0xF9, 0xbe, 0xb4, 0xd9}; int currentIndex = 0; while(!reader.EndOfStream) { if(reader.ReadByte() == seq[currentIndex]) currentIndex++; else currentIndex = 0; if(currentIndex == seq.Length) return true;} return false;