rmlCommitDiff function
Diffs a sandbox markup document against its base, both compiled here: the
result classifies every change into a ChangeSet the live file can apply,
remapping new objects from (client, firstObject). When
markupAvailable is false, or base or sandbox is empty, it returns a
failure without calling native; an empty base is the base's failure.
A negative client or firstObject throws an ArgumentError.
Implementation
RmlCommitDiff rmlCommitDiff(
String base,
String sandbox, {
required int client,
required int firstObject,
}) {
RangeError.checkNotNegative(client, 'client');
RangeError.checkNotNegative(firstObject, 'firstObject');
if (!markupAvailable) {
return const RmlCommitDiff.failure([
RmlCompileError(line: 0, message: 'markup is not available'),
]);
}
if (base.isEmpty || sandbox.isEmpty) {
return RmlCommitDiff.failure(const [
RmlCompileError(line: 0, message: 'no markup to diff'),
], baseFailed: base.isEmpty);
}
final baseBytes = utf8.encode(base);
final sandboxBytes = utf8.encode(sandbox);
final basePtr = calloc<Uint8>(baseBytes.length);
final sandboxPtr = calloc<Uint8>(sandboxBytes.length);
final response = calloc<_RmlCommitDiffResponseStruct>();
try {
basePtr.asTypedList(baseBytes.length).setAll(0, baseBytes);
sandboxPtr.asTypedList(sandboxBytes.length).setAll(0, sandboxBytes);
_rmlCommitDiff(
basePtr,
baseBytes.length,
sandboxPtr,
sandboxBytes.length,
client,
firstObject,
response,
);
final report =
response.ref.report == nullptr || response.ref.reportSize <= 0
? '{}'
: utf8.decode(
response.ref.report.asTypedList(response.ref.reportSize),
allowMalformed: true,
);
final changes = response.ref.data == nullptr || response.ref.size <= 0
? null
: Uint8List.fromList(response.ref.data.asTypedList(response.ref.size));
return RmlCommitDiff.fromJson(report, changes);
} finally {
_freeRmlCommitDiff(response);
calloc.free(response);
calloc.free(basePtr);
calloc.free(sandboxPtr);
}
}