rmlCommitDiffFiles function

RmlCommitDiff rmlCommitDiffFiles({
  1. required String base,
  2. required List<RmlFileInput> baseFiles,
  3. required String sandbox,
  4. required List<RmlFileInput> sandboxFiles,
  5. required int client,
  6. required int firstObject,
})

rmlCommitDiff over projects: base compiles against baseFiles and sandbox against sandboxFiles. A file with null bytes is withheld, so an asset naming it diffs as unchanged without either side holding its bytes. When markupAvailable is false, or base or sandbox is empty, it returns a failure without calling native, and ids are checked, as in rmlCommitDiff.

Implementation

RmlCommitDiff rmlCommitDiffFiles({
  required String base,
  required List<RmlFileInput> baseFiles,
  required String sandbox,
  required List<RmlFileInput> sandboxFiles,
  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 baseBundle = encodeRmlFileInputs(baseFiles);
  final sandboxBundle = encodeRmlFileInputs(sandboxFiles);
  final basePtr = calloc<Uint8>(baseBytes.length);
  final baseFilesPtr = calloc<Uint8>(baseBundle.length);
  final sandboxPtr = calloc<Uint8>(sandboxBytes.length);
  final sandboxFilesPtr = calloc<Uint8>(sandboxBundle.length);
  final response = calloc<_RmlCommitDiffResponseStruct>();
  try {
    basePtr.asTypedList(baseBytes.length).setAll(0, baseBytes);
    baseFilesPtr.asTypedList(baseBundle.length).setAll(0, baseBundle);
    sandboxPtr.asTypedList(sandboxBytes.length).setAll(0, sandboxBytes);
    sandboxFilesPtr.asTypedList(sandboxBundle.length).setAll(0, sandboxBundle);
    _rmlCommitDiffFiles(
      basePtr,
      baseBytes.length,
      baseFilesPtr,
      baseBundle.length,
      sandboxPtr,
      sandboxBytes.length,
      sandboxFilesPtr,
      sandboxBundle.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(baseFilesPtr);
    calloc.free(sandboxPtr);
    calloc.free(sandboxFilesPtr);
  }
}