put method

void put(
  1. String value, {
  2. Encoding? encoding,
  3. ZBytes? attachment,
})

Publishes a string value through this advanced publisher.

Optionally set the encoding (MIME type) of the message. An optional attachment can be included; it is consumed by this call and must not be reused.

Throws ZenohException if the encoding is malformed or the put fails.

Implementation

void put(String value, {Encoding? encoding, ZBytes? attachment}) {
  _ensureOpen();
  final loaned = bindings.zd_advanced_publisher_loan(_ptr.cast());
  // The payload is passed as a factory, not a value: _put validates the
  // attachment handle first and only then builds it. Building it here meant
  // a disposed attachment's StateError stranded a payload nothing else held
  // a reference to.
  _put(loaned.cast(), () => ZBytes.fromString(value), encoding, attachment);
}