toString method

  1. @override
String toString()
override

Returns this configuration as a JSON string.

This overrides Object.toString, which by Dart convention must not throw (it is called implicitly during interpolation/print). It returns the serialized JSON for a live config, and a placeholder for the disposed or consumed edge (the plan is silent on that edge; placeholder is a Dart-convention decision).

Implementation

@override
String toString() {
  if (_disposed || _consumed) return 'Config(unavailable)';
  final ownedStr = calloc.allocate<Void>(bindings.zd_string_sizeof());
  try {
    final rc = bindings.zd_config_to_string(_ptr.cast(), ownedStr.cast());
    if (rc != 0) return 'Config(error: $rc)'; // toString must not throw
    final loanedStr = bindings.zd_string_loan(ownedStr.cast());
    final data = bindings.zd_string_data(loanedStr);
    final len = bindings.zd_string_len(loanedStr);
    return data.cast<Utf8>().toDartString(length: len);
  } finally {
    bindings.zd_string_drop(ownedStr.cast());
    calloc.free(ownedStr);
  }
}