revToRmlFiles function
Converts the bytes of a .rev file into main.rml's markup plus the files
it references with file=: scripts and shaders with their source, binary
assets as byteless files that only name them. Returns null when the bytes
are not a readable .rev or markupAvailable is false.
No file lands on the path main.rml or in a top-level folder named
builtins or main.rml; one that would gets another name
(builtins_2/…).
Implementation
RmlExportedProject? revToRmlFiles(Uint8List revBytes) {
if (!markupAvailable || revBytes.isEmpty) {
return null;
}
final source = calloc<Uint8>(revBytes.length);
final response = calloc<_RmlExportFilesResponseStruct>();
try {
source.asTypedList(revBytes.length).setAll(0, revBytes);
final ok = _revToRmlFiles(source, revBytes.length, response);
if (!ok || response.ref.data == nullptr || response.ref.size <= 0) {
return null;
}
// Views over native memory; copy them out before freeing.
final rml = utf8.decode(
response.ref.data.asTypedList(response.ref.size),
allowMalformed: true,
);
// Native always sends a bundle, at least its count; none means the copy
// out failed.
if (response.ref.files == nullptr || response.ref.filesSize <= 0) {
return null;
}
final bundle = Uint8List.fromList(
response.ref.files.asTypedList(response.ref.filesSize),
);
try {
return RmlExportedProject(
rml: rml,
files: decodeRmlExportedFiles(bundle),
);
} on FormatException {
return null;
}
} finally {
_freeRmlExportFiles(response);
calloc.free(response);
calloc.free(source);
}
}