rmlToRev function

RmlCompileResult rmlToRev(
  1. Uint8List rmlBytes
)

Compiles a .rml markup document into the equivalent .rev bytes -- the inverse of revToRml. Every payload the document needs must be embedded in it: a file= reference has no directory to resolve against here and compiles as an error.

Implementation

RmlCompileResult rmlToRev(Uint8List rmlBytes) {
  if (rmlBytes.isEmpty) {
    return const RmlCompileResult.failure('0: no markup to compile\n');
  }
  final source = calloc<Uint8>(rmlBytes.length);
  final response = calloc<_RmlCompileResponseStruct>();
  try {
    source.asTypedList(rmlBytes.length).setAll(0, rmlBytes);
    _rmlToRev(source, rmlBytes.length, response);
    if (response.ref.data != nullptr && response.ref.size > 0) {
      // A view over native memory; copy it out before freeing.
      return RmlCompileResult.success(
        Uint8List.fromList(response.ref.data.asTypedList(response.ref.size)),
      );
    }
    if (response.ref.error != nullptr && response.ref.errorSize > 0) {
      return RmlCompileResult.failure(
        utf8.decode(
          response.ref.error.asTypedList(response.ref.errorSize),
          allowMalformed: true,
        ),
      );
    }
    return const RmlCompileResult.failure('0: markup compile failed\n');
  } finally {
    _freeRmlCompile(response);
    calloc.free(response);
    calloc.free(source);
  }
}