snapshot method

  1. @override
Uint8List snapshot(
  1. int handle
)
override

Serializes the handle state to a byte buffer (snapshot).

Implementation

@override
Uint8List snapshot(int handle) {
  final ptr = Pointer<ffi_native.MontyHandle>.fromAddress(handle);
  final outLen = calloc<Size>();

  try {
    final buf = ffi_native.monty_snapshot(ptr, outLen);
    if (buf == nullptr) {
      throw StateError('monty_snapshot returned null');
    }
    final len = outLen.value;
    final bytes = Uint8List.fromList(buf.cast<Uint8>().asTypedList(len));
    ffi_native.monty_bytes_free(buf, len);

    return bytes;
  } finally {
    calloc.free(outLen);
  }
}