append method
Appends owned bytes into the writer, consuming them.
After this call, the bytes object is consumed and must not be used.
Throws StateError if already finished or disposed. Throws ZenohException if the native append fails.
Implementation
void append(ZBytes bytes) {
_checkState();
final rc = bindings.zd_bytes_writer_append(
_loanMut().cast(),
bytes.nativePtr.cast(),
);
// markConsumed is unconditional and runs BEFORE the rc-throw: the shim
// zd_bytes_writer_append z_bytes_move's the owned bytes, gravestoning the
// native handle regardless of the return code. Marking before the throw
// prevents a later use-after-move on any rc != 0 outcome, mirroring every
// other send site (session.dart:250/302/844, query.dart:171).
//
// This ordering cannot be tested dynamically, and the rationale lives here
// because that is the only place it can do any work. Every precondition
// that could make the call return rc != 0 is intercepted earlier --
// _checkState() (finished/disposed -> StateError) and bytes.nativePtr's
// _ensureNotConsumed (consumed -> StateError) -- so no reachable public-API
// path drives the error branch. Two tests once guarded this line; both
// exercised only the success path and passed with or without the reorder,
// so they were removed as dead weight (the success-path consume contract
// remains pinned by bytes_writer_test's 'append consumes the ZBytes').
// If you reorder these two statements, no test will tell you.
bytes.markConsumed();
if (rc != 0) throw ZenohException('Failed to append bytes', rc);
}