putBytes method
Publishes ZBytes payload through this publisher.
The payload is consumed by this call and must not be reused.
An optional attachment can be included (consumed by this call).
Implementation
void putBytes(ZBytes payload, {Encoding? encoding, ZBytes? attachment}) {
_ensureOpen();
final loaned = bindings.zd_publisher_loan(_ptr.cast());
final payloadPtr = payload.nativePtr;
final encodingStr = encoding != null
? encoding.mimeType.toNativeUtf8()
: nullptr;
final attachmentPtr = attachment != null ? attachment.nativePtr : nullptr;
try {
final rc = bindings.zd_publisher_put(
loaned,
payloadPtr.cast(),
encodingStr.cast(),
attachmentPtr.cast(),
);
payload.markConsumed();
if (attachment != null) attachment.markConsumed();
if (rc != 0) {
throw ZenohException('Publisher put failed', rc);
}
} finally {
if (encodingStr != nullptr) malloc.free(encodingStr);
}
}