parseData function
Parses a byte list and create a Cartridge
If the byte list is a valid GWC file, the result will be Cartridge or null, if the parser failed.
Implementation
Cartridge? parseData(Uint8List bytes) {
try {
const header = {0x02, 0x0a, 0x43, 0x41, 0x52, 0x54, 0x00}; // magic header
final reader = BinaryReader(
byteData: ByteData.view(bytes.buffer),
endian: Endian.little,
);
for (var index = 0; index < header.length; index++) {
if (reader.getByte() != header.elementAt(index)) {
return null;
}
}
return Cartridge.create(reader);
} on Exception catch (_) {
return null;
}
}