More efforts to make it compile; phew

This commit is contained in:
Mikhail Yakshin 2016-07-15 18:26:04 +03:00
parent b398797b05
commit d4268d1de6
1 changed files with 10 additions and 7 deletions

View File

@ -138,7 +138,9 @@ namespace Kaitai
public byte[] readBytesFull()
{
int count = mStream.Length - mStream.Position;
long countLong = mStream.Length - mStream.Position;
// TODO: check if the conversion is safe, throw exception otherwise?
int count = (int) countLong;
byte[] buffer = new byte[count];
mStream.Read(buffer, 0, count);
return buffer;
@ -146,14 +148,15 @@ namespace Kaitai
public byte[] ensureFixedContents(int len, byte[] expected)
{
IOException e = new IOException();
e.Message = "Expected bytes: "+Convert.ToBase64String(expected)+Environment.NewLine;
byte[] buff = readBytes(len);
e.message += "Got bytes: "+Convert.ToBase64String(buff);
for(int idx =0; idx < len; idx++)
if(buff[idx] != expected[idx]) throw e;
for (int idx = 0; idx < len; idx++)
if (buff[idx] != expected[idx])
{
String msg = "Expected bytes: "+Convert.ToBase64String(expected)+Environment.NewLine;
msg += "Got bytes: "+Convert.ToBase64String(buff);
throw new IOException(msg);
}
return buff;
}