47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class CECRTDebug
|
|
{
|
|
}
|
|
public class CECDataReader
|
|
{
|
|
private byte[] data;
|
|
private int offset;
|
|
private int length;
|
|
|
|
public CECDataReader(byte[] data, int offset, int length)
|
|
{
|
|
this.data = data;
|
|
this.offset = offset;
|
|
this.length = length;
|
|
}
|
|
|
|
public int ReadInt()
|
|
{
|
|
if (offset + sizeof(int) > offset + length)
|
|
throw new System.InvalidOperationException("Not enough data to read int");
|
|
|
|
int value = System.BitConverter.ToInt32(data, offset);
|
|
offset += sizeof(int);
|
|
return value;
|
|
}
|
|
|
|
public byte[] ReadData(int size)
|
|
{
|
|
if (offset + size > offset + length)
|
|
throw new System.InvalidOperationException($"Not enough data to read {size} bytes");
|
|
|
|
byte[] result = new byte[size];
|
|
System.Array.Copy(data, offset, result, 0, size);
|
|
offset += size;
|
|
return result;
|
|
}
|
|
}
|
|
}
|